forked from Minecraft/canopeas
43 lines
790 B
Go
43 lines
790 B
Go
package discord
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
func init() {
|
|
commands["help"] = command{
|
|
validate: func(cmd commandInit) bool {
|
|
return true
|
|
},
|
|
run: func(cmd commandInit) error {
|
|
args := strings.Fields(cmd.message.Content)[1:]
|
|
|
|
var resp string
|
|
if len(args) == 1 {
|
|
resp = singleHelp(args[0])
|
|
} else {
|
|
resp = allHelp()
|
|
}
|
|
sendMessage(cmd.session, cmd.message.ChannelID, resp)
|
|
return 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")
|
|
}
|