61 lines
1 KiB
Go
61 lines
1 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"surdeus.su/core/tg"
|
|
)
|
|
|
|
type BotData struct {
|
|
Name string
|
|
}
|
|
|
|
type SessionData struct {
|
|
Counter int
|
|
}
|
|
|
|
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)
|
|
})
|
|
|
|
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...,
|
|
),
|
|
)
|
|
|
|
func main() {
|
|
token := os.Getenv("BOT_TOKEN")
|
|
|
|
bot, err := tg.NewBot(token)
|
|
if err != nil {
|
|
log.Fatalf("tg.NewBot(...): %s", err)
|
|
}
|
|
bot = bot.SetBehaviour(beh)
|
|
//bot.API().Debug = true
|
|
|
|
bot.SetData(&BotData{
|
|
Name: "Jay",
|
|
})
|
|
|
|
log.Printf("Authorized on account %s", bot.API().Self.UserName)
|
|
err = bot.Run()
|
|
if err != nil {
|
|
log.Fatalf("bot.Run(...): %s", err)
|
|
}
|
|
}
|