41 lines
634 B
Go
41 lines
634 B
Go
package nechotron
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
"time"
|
|
|
|
echo "github.com/NicoNex/echotron/v3"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type bot struct {
|
|
chatID int64
|
|
me *echo.User
|
|
echo.API
|
|
data StateData
|
|
lock sync.Mutex
|
|
state *State
|
|
}
|
|
|
|
func (b *bot) Update(u *echo.Update) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
upd := &Update{
|
|
U: U(*u),
|
|
Bot: b,
|
|
UpdateID: uuid.New(),
|
|
Ctx: ctx,
|
|
}
|
|
|
|
b.lock.Lock()
|
|
defer b.lock.Unlock()
|
|
newState, err := b.state.Call(upd)
|
|
if err != nil {
|
|
upd.LogError("", err, true)
|
|
}
|
|
if newState != nil {
|
|
b.state = newState
|
|
}
|
|
}
|