2023-07-03 17:22:45 +03:00
|
|
|
package main
|
|
|
|
|
2023-07-08 22:26:21 +03:00
|
|
|
import (
|
2023-08-10 15:49:25 +03:00
|
|
|
"log"
|
|
|
|
"os"
|
2023-07-08 22:26:21 +03:00
|
|
|
|
2024-05-15 20:41:53 +03:00
|
|
|
"surdeus.su/core/tg"
|
2023-07-09 01:28:59 +03:00
|
|
|
)
|
|
|
|
|
2023-08-19 13:34:21 +03:00
|
|
|
type BotData struct {
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
2023-09-11 10:23:04 +03:00
|
|
|
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)
|
2023-09-09 07:28:06 +03:00
|
|
|
}
|
|
|
|
|
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(
|
2023-09-21 12:03:54 +03:00
|
|
|
// The "/" widget.
|
2024-03-29 14:30:48 +03:00
|
|
|
StartWidget,
|
2023-09-21 12:03:54 +03:00
|
|
|
|
2023-12-19 22:35:57 +03:00
|
|
|
tg.NewNode(
|
2024-03-29 14:30:48 +03:00
|
|
|
PanelPath,
|
|
|
|
PanelWidget,
|
2023-12-19 22:35:57 +03:00
|
|
|
),
|
|
|
|
|
2023-09-21 14:54:31 +03:00
|
|
|
tg.NewNode(
|
2024-03-29 14:30:48 +03:00
|
|
|
MutateMessagesPath,
|
|
|
|
MutateMessagesWidget,
|
|
|
|
|
2023-09-21 14:54:31 +03:00
|
|
|
tg.NewNode(
|
2024-03-29 14:30:48 +03:00
|
|
|
UpperCasePath,
|
|
|
|
MutateMessagesToUpperCaseWidget,
|
2023-09-21 14:54:31 +03:00
|
|
|
),
|
|
|
|
tg.NewNode(
|
2024-03-29 14:30:48 +03:00
|
|
|
LowerCasePath,
|
|
|
|
MutateMessagesToLowerCaseWidget,
|
2023-09-21 14:54:31 +03:00
|
|
|
),
|
2023-10-05 17:51:24 +03:00
|
|
|
tg.NewNode(
|
2024-03-29 14:30:48 +03:00
|
|
|
EscapePath,
|
|
|
|
MutateMessagesEscapeWidget,
|
2023-10-05 17:51:24 +03:00
|
|
|
),
|
2023-09-21 14:54:31 +03:00
|
|
|
),
|
|
|
|
|
2023-09-21 12:03:54 +03:00
|
|
|
tg.NewNode(
|
2024-03-29 14:30:48 +03:00
|
|
|
IncDecPath,
|
|
|
|
IncDecWidget,
|
2023-09-21 12:03:54 +03:00
|
|
|
),
|
2023-08-11 11:04:28 +03:00
|
|
|
|
2023-09-21 12:03:54 +03:00
|
|
|
tg.NewNode(
|
2024-03-29 14:30:48 +03:00
|
|
|
LocationPath,
|
|
|
|
LocationWidget,
|
2023-09-21 12:03:54 +03:00
|
|
|
),
|
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)
|
2023-08-10 15:49:25 +03:00
|
|
|
if err != nil {
|
|
|
|
log.Panic(err)
|
|
|
|
}
|
2024-03-29 14:30:48 +03:00
|
|
|
bot = bot.SetBehaviour(beh)
|
2024-05-15 20:41:53 +03:00
|
|
|
//SetDebug(true)
|
2023-07-08 22:26:21 +03:00
|
|
|
|
2024-03-29 14:30:48 +03:00
|
|
|
bot.SetData(&BotData{
|
2023-09-11 13:00:38 +03:00
|
|
|
Name: "Jay",
|
2024-03-29 14:30:48 +03:00
|
|
|
})
|
2023-09-11 13:00:38 +03:00
|
|
|
|
2024-03-29 14:30:48 +03:00
|
|
|
log.Printf("Authorized on account %s", bot.Api().Self.UserName)
|
2023-09-11 13:00:38 +03:00
|
|
|
err = bot.Run()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2023-08-10 15:49:25 +03:00
|
|
|
}
|