Lists of commands
This commit is contained in:
parent
e396d6a885
commit
d035524ebc
24
command.go
24
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)
|
||||
|
|
Loading…
Reference in New Issue