canopeas/discord/help.go

42 lines
749 B
Go
Raw Permalink Normal View History

package discord
import (
"fmt"
"strings"
)
func init() {
commands["help"] = command{
validate: func(cmd commandInit) bool {
return true
},
run: func(cmd commandInit) (string, error) {
args := strings.Fields(cmd.message.Content)[1:]
var resp string
if len(args) == 1 {
resp = singleHelp(args[0])
} else {
resp = allHelp()
}
return resp, nil
},
help: "HELP! HEEEEEEEEEELP!",
}
}
func singleHelp(cmd string) string {
if c, ok := commands[cmd]; ok {
return fmt.Sprintf("%s: %s", cmd, c.help)
}
return "Unknown command"
}
func allHelp() string {
helps := make([]string, 0)
for n, c := range commands {
helps = append(helps, fmt.Sprintf("%s: %s", n, c.help))
}
return strings.Join(helps, "\n")
}