2023-01-19 23:08:59 +03:00
|
|
|
package nechotron
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-01-20 00:27:29 +03:00
|
|
|
"sync"
|
2023-01-19 23:08:59 +03:00
|
|
|
"time"
|
|
|
|
|
|
|
|
echo "github.com/NicoNex/echotron/v3"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
type bot struct {
|
|
|
|
chatID int64
|
|
|
|
me *echo.User
|
|
|
|
echo.API
|
2023-01-20 00:27:29 +03:00
|
|
|
data StateData
|
|
|
|
lock sync.Mutex
|
2023-01-20 01:44:35 +03:00
|
|
|
state Runnable
|
2023-01-19 23:08:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
2023-01-20 00:27:29 +03:00
|
|
|
b.lock.Lock()
|
|
|
|
defer b.lock.Unlock()
|
2023-01-22 23:54:54 +03:00
|
|
|
err := b.state.Call(upd)
|
2023-01-19 23:08:59 +03:00
|
|
|
if err != nil {
|
|
|
|
upd.LogError("", err, true)
|
|
|
|
}
|
|
|
|
}
|