tg/cmd/test/main.go

57 lines
983 B
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 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)
}
}