initial
This commit is contained in:
35
bot.go
Normal file
35
bot.go
Normal file
@ -0,0 +1,35 @@
|
||||
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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user