tg/cmd/test/main.go

62 lines
1 KiB
Go
Raw Normal View History

2023-07-03 17:22:45 +03:00
package main
2023-07-08 22:26:21 +03:00
import (
"log"
"os"
2023-07-08 22:26:21 +03:00
"surdeus.su/core/tg"
2023-07-09 01:28:59 +03:00
)
type BotData struct {
Name string
}
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)
}
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{})
})).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-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)
if err != nil {
log.Fatalf("tg.NewBot(...): %s", err)
}
2024-03-29 14:30:48 +03:00
bot = bot.SetBehaviour(beh)
//bot.API().Debug = true
2023-07-08 22:26:21 +03:00
2024-03-29 14:30:48 +03:00
bot.SetData(&BotData{
Name: "Jay",
2024-03-29 14:30:48 +03:00
})
log.Printf("Authorized on account %s", bot.API().Self.UserName)
err = bot.Run()
if err != nil {
log.Fatalf("bot.Run(...): %s", err)
}
}