2020-04-18 19:32:33 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"git.dragon-labs.de/alphyron/group_helper/cli"
|
2020-05-09 18:54:42 +00:00
|
|
|
"git.dragon-labs.de/alphyron/group_helper/models"
|
2020-04-18 19:32:33 +00:00
|
|
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
|
2021-03-13 23:22:49 +00:00
|
|
|
"log"
|
2020-04-18 19:32:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type helpCommand struct {
|
|
|
|
commandManager *cli.CommandManager
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHelpCommand(commandManager *cli.CommandManager) cli.Command {
|
|
|
|
return &helpCommand{commandManager: commandManager}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h helpCommand) GetUsage() string {
|
|
|
|
return "/help"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h helpCommand) GetCommand() string {
|
|
|
|
return "/help"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h helpCommand) GetDescription() string {
|
|
|
|
return "Information about all commands"
|
|
|
|
}
|
|
|
|
|
2020-05-09 18:54:42 +00:00
|
|
|
func (h helpCommand) ExecuteCommand(bot *tgbotapi.BotAPI, update *tgbotapi.Update, group *models.Group) (bool, error) {
|
2020-04-18 19:32:33 +00:00
|
|
|
|
2021-03-13 23:22:49 +00:00
|
|
|
log.Println("test1")
|
|
|
|
|
|
|
|
messages := "All supported Commands:"
|
2020-04-18 19:32:33 +00:00
|
|
|
for _, cmd := range h.commandManager.Commands {
|
2021-03-13 23:22:49 +00:00
|
|
|
messages += fmt.Sprintf("\n%s - %s", cmd.GetUsage(), cmd.GetDescription())
|
2020-04-18 19:32:33 +00:00
|
|
|
}
|
2021-03-13 23:22:49 +00:00
|
|
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, messages)
|
2020-04-18 19:32:33 +00:00
|
|
|
msg.ParseMode = "Markdown"
|
|
|
|
|
|
|
|
_, err := bot.Send(msg)
|
|
|
|
|
2021-03-13 23:22:49 +00:00
|
|
|
return err == nil, err
|
2020-04-18 19:32:33 +00:00
|
|
|
}
|
|
|
|
|
2021-03-13 23:22:49 +00:00
|
|
|
func (h helpCommand) AllowChatType(_ *tgbotapi.Chat) bool {
|
2020-04-18 19:32:33 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-03-13 23:22:49 +00:00
|
|
|
func (h helpCommand) AllowMember(_ *tgbotapi.ChatMember) bool {
|
2020-04-18 19:32:33 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h helpCommand) AllowEveryMember() bool {
|
|
|
|
return true
|
|
|
|
}
|