-
Notifications
You must be signed in to change notification settings - Fork 1
/
help.go
37 lines (32 loc) · 873 Bytes
/
help.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package bot
import (
"fmt"
"strings"
)
func init() {
RegisterScript(Script{
Name: "Help",
Matcher: "help ?<filter>",
Description: "show description for all commands",
Function: helpScriptFunc,
})
}
func helpScriptFunc(context *ScriptContext) {
filter := context.Arguments["filter"]
helpMsg := ""
for _, script := range scripts {
if script.Matcher != "" && (strings.Contains(string(script.Matcher), filter) || filter == "") {
if helpMsg != "" {
helpMsg += "\n\n"
}
helpMsg = fmt.Sprintf("%s%s", helpMsg, string(script.Matcher))
if script.Description != "" {
helpMsg += fmt.Sprintf(" - %s", script.Description)
} else {
helpMsg += fmt.Sprintf("Missing help command description for %s", script.Name)
}
}
}
message := fmt.Sprintf("```\n%s\n```", helpMsg)
PostMessage(context.SlackEvent.Channel, message)
}