✨ Implement help command
This commit is contained in:
parent
0f6ee5893c
commit
a44c3463d3
59
cli/commands/help.go
Normal file
59
cli/commands/help.go
Normal file
@ -0,0 +1,59 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.dragon-labs.de/alphyron/group_helper/cli"
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
"strings"
|
||||
)
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
func (h helpCommand) ExecuteCommand(bot *tgbotapi.BotAPI, update *tgbotapi.Update) (bool, error) {
|
||||
var builder strings.Builder
|
||||
|
||||
builder.WriteString("All supported Commands:\n")
|
||||
for _, cmd := range h.commandManager.Commands {
|
||||
builder.WriteString(fmt.Sprintf("%s - %s\n", cmd.GetUsage(), cmd.GetDescription()))
|
||||
}
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, builder.String())
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
_, err := bot.Send(msg)
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (h helpCommand) AllowChatType(chat *tgbotapi.Chat) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (h helpCommand) AllowMember(member *tgbotapi.ChatMember) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (h helpCommand) AllowEveryMember() bool {
|
||||
return true
|
||||
}
|
Loading…
Reference in New Issue
Block a user