nechotron/bot.go

36 lines
551 B
Go

package nechotron
import (
"context"
"time"
echo "github.com/NicoNex/echotron/v3"
"github.com/google/uuid"
)
type bot struct {
chatID int64
me *echo.User
echo.API
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,
}
newState, err := b.state.Fn(upd)
if err != nil {
upd.LogError("", err, true)
}
if newState != nil {
b.state = newState
}
}