88 lines
1.3 KiB
Go
88 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"vultras.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{})
|
|
})).SetRootNode(tg.NewRootNode(
|
|
// The "/" widget.
|
|
StartWidget,
|
|
|
|
tg.NewNode(
|
|
PanelPath,
|
|
PanelWidget,
|
|
),
|
|
|
|
tg.NewNode(
|
|
MutateMessagesPath,
|
|
MutateMessagesWidget,
|
|
|
|
tg.NewNode(
|
|
UpperCasePath,
|
|
MutateMessagesToUpperCaseWidget,
|
|
),
|
|
tg.NewNode(
|
|
LowerCasePath,
|
|
MutateMessagesToLowerCaseWidget,
|
|
),
|
|
tg.NewNode(
|
|
EscapePath,
|
|
MutateMessagesEscapeWidget,
|
|
),
|
|
),
|
|
|
|
tg.NewNode(
|
|
IncDecPath,
|
|
IncDecWidget,
|
|
),
|
|
|
|
tg.NewNode(
|
|
LocationPath,
|
|
LocationWidget,
|
|
),
|
|
)).SetRootWidget(tg.NewCommandCompo().SetUsage(
|
|
UsageAction,
|
|
).SetPreStart(
|
|
PreStartAction,
|
|
).SetCommands(
|
|
BotCommands...,
|
|
))
|
|
|
|
func main() {
|
|
token := os.Getenv("BOT_TOKEN")
|
|
|
|
bot, err := tg.NewBot(token)
|
|
if err != nil {
|
|
log.Panic(err)
|
|
}
|
|
bot = bot.SetBehaviour(beh)
|
|
//SetDebug(true)
|
|
|
|
bot.SetData(&BotData{
|
|
Name: "Jay",
|
|
})
|
|
|
|
log.Printf("Authorized on account %s", bot.Api().Self.UserName)
|
|
err = bot.Run()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|