package nechotron import ( "context" "sync" "time" echo "github.com/NicoNex/echotron/v3" "github.com/google/uuid" ) type bot struct { echo.API chatID int64 Me *echo.User data StateData lock sync.Mutex State Runnable handler UpdateHandler } func DefaultHandler(u *Update) error { err := u.Bot.State.Call(u) return err } 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() // defer func() { // if r := recover(); r != nil { // log.Printf("[%s] Recovered. Error: %s\n", upd.UpdateID.String(), r) // } // }() b.handler(upd) }