2020-06-09 13:04:44 +00:00
|
|
|
package discord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
commands["help"] = command{
|
|
|
|
validate: func(cmd commandInit) bool {
|
|
|
|
return true
|
|
|
|
},
|
2020-06-12 05:17:58 +00:00
|
|
|
run: func(cmd commandInit) (string, error) {
|
2020-06-09 13:04:44 +00:00
|
|
|
args := strings.Fields(cmd.message.Content)[1:]
|
|
|
|
|
|
|
|
var resp string
|
|
|
|
if len(args) == 1 {
|
|
|
|
resp = singleHelp(args[0])
|
|
|
|
} else {
|
|
|
|
resp = allHelp()
|
|
|
|
}
|
2020-06-12 05:17:58 +00:00
|
|
|
return resp, nil
|
2020-06-09 13:04:44 +00:00
|
|
|
},
|
|
|
|
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")
|
|
|
|
}
|