tg/cmd/test/main.go

89 lines
1.3 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)
}
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{})
})).SetRootNode(tg.NewRootNode(
// The "/" widget.
2024-03-29 14:30:48 +03:00
StartWidget,
tg.NewNode(
2024-03-29 14:30:48 +03:00
PanelPath,
PanelWidget,
),
tg.NewNode(
2024-03-29 14:30:48 +03:00
MutateMessagesPath,
MutateMessagesWidget,
tg.NewNode(
2024-03-29 14:30:48 +03:00
UpperCasePath,
MutateMessagesToUpperCaseWidget,
),
tg.NewNode(
2024-03-29 14:30:48 +03:00
LowerCasePath,
MutateMessagesToLowerCaseWidget,
),
tg.NewNode(
2024-03-29 14:30:48 +03:00
EscapePath,
MutateMessagesEscapeWidget,
),
),
tg.NewNode(
2024-03-29 14:30:48 +03:00
IncDecPath,
IncDecWidget,
),
2023-08-11 11:04:28 +03:00
tg.NewNode(
2024-03-29 14:30:48 +03:00
LocationPath,
LocationWidget,
),
2024-03-29 14:30:48 +03:00
)).SetRootWidget(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.Panic(err)
}
2024-03-29 14:30:48 +03:00
bot = bot.SetBehaviour(beh)
//SetDebug(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
})
2024-03-29 14:30:48 +03:00
log.Printf("Authorized on account %s", bot.Api().Self.UserName)
err = bot.Run()
if err != nil {
panic(err)
}
}