Setting commands to users

This commit is contained in:
nefrace 2023-01-24 03:11:15 +03:00
parent 393f3813a8
commit 601174f764
3 changed files with 20 additions and 8 deletions

View File

@ -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
}

13
main.go
View File

@ -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())
}

View File

@ -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)
},