2023-07-03 17:22:45 +03:00
|
|
|
package main
|
|
|
|
|
2023-07-08 22:26:21 +03:00
|
|
|
import (
|
2023-08-10 15:49:25 +03:00
|
|
|
"log"
|
|
|
|
"os"
|
2023-07-08 22:26:21 +03:00
|
|
|
|
2024-05-15 20:41:53 +03:00
|
|
|
"surdeus.su/core/tg"
|
2023-07-09 01:28:59 +03:00
|
|
|
)
|
|
|
|
|
2023-08-19 13:34:21 +03:00
|
|
|
type BotData struct {
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
2023-09-11 10:23:04 +03:00
|
|
|
type SessionData struct {
|
2023-08-12 14:35:33 +03:00
|
|
|
Counter int
|
|
|
|
}
|
|
|
|
|
2024-03-29 14:30:48 +03:00
|
|
|
func ExtractSessionData(c tg.Context) *SessionData {
|
|
|
|
return c.SessionData().(*SessionData)
|
2023-09-09 07:28:06 +03:00
|
|
|
}
|
|
|
|
|
2024-07-23 16:08:39 +03:00
|
|
|
var BackWidget = tg.RenderFunc(func(c tg.Context) tg.UI{
|
|
|
|
return c.GoRet(tg.Back)
|
|
|
|
})
|
|
|
|
|
2024-03-29 14:30:48 +03:00
|
|
|
var beh = tg.NewBehaviour().SetInit(tg.Func(func(c tg.Context) {
|
|
|
|
// The session initialization.
|
|
|
|
c.SetSessionData(&SessionData{})
|
2024-07-21 16:02:47 +03:00
|
|
|
})).SetRootWidget(
|
|
|
|
// Setting as the most top
|
|
|
|
// widget command handling
|
|
|
|
// so we can call them at any screen.
|
|
|
|
tg.NewCommandCompo().SetUsage(
|
|
|
|
UsageAction,
|
|
|
|
).SetPreStart(
|
|
|
|
PreStartAction,
|
|
|
|
).SetCommands(
|
|
|
|
BotCommands...,
|
2023-12-19 22:35:57 +03:00
|
|
|
),
|
2024-07-21 16:02:47 +03:00
|
|
|
)
|
2023-10-22 20:41:01 +03:00
|
|
|
|
2023-07-03 17:22:45 +03:00
|
|
|
func main() {
|
2023-07-08 22:26:21 +03:00
|
|
|
token := os.Getenv("BOT_TOKEN")
|
|
|
|
|
2023-08-19 09:12:26 +03:00
|
|
|
bot, err := tg.NewBot(token)
|
2023-08-10 15:49:25 +03:00
|
|
|
if err != nil {
|
2024-07-21 16:02:47 +03:00
|
|
|
log.Fatalf("tg.NewBot(...): %s", err)
|
2023-08-10 15:49:25 +03:00
|
|
|
}
|
2024-03-29 14:30:48 +03:00
|
|
|
bot = bot.SetBehaviour(beh)
|
2024-07-21 16:02:47 +03:00
|
|
|
//bot.API().Debug = true
|
2023-07-08 22:26:21 +03:00
|
|
|
|
2024-03-29 14:30:48 +03:00
|
|
|
bot.SetData(&BotData{
|
2023-09-11 13:00:38 +03:00
|
|
|
Name: "Jay",
|
2024-03-29 14:30:48 +03:00
|
|
|
})
|
2023-09-11 13:00:38 +03:00
|
|
|
|
2024-07-21 16:02:47 +03:00
|
|
|
log.Printf("Authorized on account %s", bot.API().Self.UserName)
|
2023-09-11 13:00:38 +03:00
|
|
|
err = bot.Run()
|
|
|
|
if err != nil {
|
2024-07-21 16:02:47 +03:00
|
|
|
log.Fatalf("bot.Run(...): %s", err)
|
2023-09-11 13:00:38 +03:00
|
|
|
}
|
2023-08-10 15:49:25 +03:00
|
|
|
}
|