diff --git a/command.go b/command.go index a3da25c..f52d490 100644 --- a/command.go +++ b/command.go @@ -2,7 +2,10 @@ package nechotron import ( "fmt" + "log" "strings" + + "github.com/NicoNex/echotron/v3" ) type Command struct { @@ -26,12 +29,29 @@ func (c *Command) Param(text string) string { return strings.TrimPrefix(text, "/"+c.Body+" ") } -func MakeCommandList(commands []*Command, format string) string { +func MakeCommandList(format string, commands ...*Command) string { result := "" for _, command := range commands { - result += fmt.Sprintf(format, command.String(), command.Description) + result += fmt.Sprintf(format, command.String(), EscapeMd2(command.Description)) } return result } +func botCommands(commands ...*Command) []echotron.BotCommand { + cmds := []echotron.BotCommand{} + for _, c := range commands { + cmds = append(cmds, echotron.BotCommand{Command: c.Body, Description: c.Description}) + } + return cmds +} + +func SetMyCommands(api echotron.API, langCode string, scope echotron.BotCommandScope, commands ...*Command) error { + _, err := api.SetMyCommands(&echotron.CommandOptions{LanguageCode: "", Scope: scope}, botCommands(commands...)...) + if err != nil { + log.Println(err) + return err + } + return nil +} + // func HandleCommand(command *Command, handler cmdFunc) (bool, error) diff --git a/update.go b/update.go index a9f0c45..9a070df 100644 --- a/update.go +++ b/update.go @@ -196,7 +196,10 @@ func (u *Update) Text() string { if u.IsText() { return u.Message.Text } - return u.Message.Caption + if u.IsMessage() { + return u.Message.Caption + } + return "" } func (u *Update) Entities() []*echotron.MessageEntity {