Lists of commands

This commit is contained in:
nefrace 2023-01-24 03:08:34 +03:00
parent e396d6a885
commit d035524ebc
2 changed files with 26 additions and 3 deletions

View File

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

View File

@ -196,7 +196,10 @@ func (u *Update) Text() string {
if u.IsText() {
return u.Message.Text
}
if u.IsMessage() {
return u.Message.Caption
}
return ""
}
func (u *Update) Entities() []*echotron.MessageEntity {