From 601174f764673580a982a02727612af852f27ae5 Mon Sep 17 00:00:00 2001 From: nefrace Date: Tue, 24 Jan 2023 03:11:15 +0300 Subject: [PATCH] Setting commands to users --- commands.go | 11 +++++++++-- main.go | 13 ++++++++++--- states.go | 4 +--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/commands.go b/commands.go index e5212b7..c4208e2 100644 --- a/commands.go +++ b/commands.go @@ -16,15 +16,22 @@ func handleMe(u *neco.Update) error { var commandHelp = neco.NewCommand("help", "Показываю данный текст", false) +var helpText = ` +Вот мои команды: +%s + +Время сборки бота: %s` + func handleHelp(u *neco.Update) error { - _, err := u.AnswerPlain("Тут текст помощи") + commands := neco.MakeCommandList("`%s` \\- _%s_\n", commandHelp, commandMe) + _, err := u.AnswerMarkdown(fmt.Sprintf(helpText, commands, BuildTime)) return err } var commandSay = neco.NewCommand("say", "Пишу ваш текст от своего имени.", true) func handleSay(u *neco.Update) error { - param := commandMe.Param(u.Text()) + param := commandSay.Param(u.Text()) _, err := u.AnswerMarkdown(fmt.Sprintf("*_%s_*", neco.EscapeMd2(param))) return err } diff --git a/main.go b/main.go index 72db483..da97f9a 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "git.nefrace.ru/nefrace/nechotron" "git.nefrace.ru/nefrace/tongo" + "github.com/NicoNex/echotron/v3" "github.com/joho/godotenv" ) @@ -17,10 +18,16 @@ func main() { if err != nil { log.Fatalf("Can't connect to database: %v", err) } - neco := nechotron.NewTron(os.Getenv("TELEGRAM_TOKEN"), &MainState) + token := os.Getenv("TELEGRAM_TOKEN") + neco := nechotron.NewTron(token, &MainState) neco. Use(UserDBUpdater(db)). - Use(UserLogger) - // neko.ApiServer = "http://192.168.100.15:7373" + Use(ErrorLogger) + api := echotron.NewAPI(token) + defaultCommands := []*nechotron.Command{commandHelp, commandMe} + adminCommands := []*nechotron.Command{commandSay, commandWarn} + allCommands := append(defaultCommands, adminCommands...) + nechotron.SetMyCommands(api, "", echotron.BotCommandScope{Type: echotron.Any}, defaultCommands...) + nechotron.SetMyCommands(api, "", echotron.BotCommandScope{Type: echotron.BCSTAllChatAdministrators}, allCommands...) log.Fatal(neco.DispatchPoll()) } diff --git a/states.go b/states.go index eff83bd..ebb19a9 100644 --- a/states.go +++ b/states.go @@ -6,12 +6,10 @@ import ( var MainState = neco.State{ Fn: func(u *neco.Update) error { - privateDisp := neco.NewDispatcher(). + disp := neco.NewDispatcher(). HandleCommand(commandMe, handleMe). HandleCommand(commandHelp, handleHelp). HandleCommand(commandSay, handleSay) - disp := neco.NewDispatcher(). - HandleFilter(neco.IsPrivate, privateDisp.Run) return disp.Run(u) },