grim/wasdead

Fix the help message for the help command
draft
2019-04-08, Gary Kramlich
c06bc2e462ed
Fix the help message for the help command
package discord
import (
"fmt"
"strings"
"github.com/bwmarrin/discordgo"
)
type commandHelp struct{}
func (cmd *commandHelp) Help() string {
return "Displays this help message"
}
func createField(name string, cmd Command) *discordgo.MessageEmbedField {
return &discordgo.MessageEmbedField{
Name: name,
Value: fmt.Sprintf("\nUsage: **%s**\n%s", name, cmd.Help()),
}
}
func (cmd *commandHelp) Run(args []string, c *DiscordClient, m *discordgo.MessageCreate) (interface{}, error) {
embed := &discordgo.MessageEmbed{
Author: &discordgo.MessageEmbedAuthor{
Name: "WasDead",
},
Description: "Command Help",
}
if len(args) == 0 {
for _, name := range commands.Keys() {
icmd, _ := commands.Get(name)
cmd := icmd.(Command)
embed.Fields = append(embed.Fields, createField(name, cmd))
}
} else if len(args) == 1 {
name := args[0]
icmd, found := commands.Get(strings.ToLower(name))
if !found {
return nil, fmt.Errorf("command %s not found", name)
}
cmd := icmd.(Command)
embed.Fields = append(embed.Fields, createField(name, cmd))
} else {
return nil, fmt.Errorf("unsupported number of arguments")
}
return embed, nil
}