-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelp.go
53 lines (42 loc) · 1.1 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package module
import (
"fmt"
"github.com/davidscholberg/irkbot/lib/configure"
"github.com/davidscholberg/irkbot/lib/message"
"sort"
"strings"
)
var helpMsgs []string
// RegisterHelp allows modules to define help strings to be displayed on command.
func registerHelp(s []string) {
helpMsgs = append(helpMsgs, s...)
}
func sortHelp() {
sort.Strings(helpMsgs)
return
}
// Help displays help for all bot commands.
func help(cfg *configure.Config, in *message.InboundMsg, actions *actions) {
nick := in.Event.Nick
if strings.HasPrefix(in.Src, "#") {
actions.say(
fmt.Sprintf(
"%s: check your PMs, fam",
nick,
),
)
}
actions.sayTo(nick, "Hello! I am an Irkbot instance - "+
"https://github.com/davidscholberg/irkbot")
actions.sayTo(nick, "Here's my list of commands:")
for _, s := range helpMsgs {
actions.sayTo(nick, fmt.Sprintf("%s%s", cfg.Channel.CmdPrefix, s))
}
}
func parseHelp(cfg *configure.Config, in *message.InboundMsg, actions *actions) bool {
if strings.TrimSpace(in.Msg) != fmt.Sprintf("%s: help", cfg.User.Nick) {
return false
}
help(cfg, in, actions)
return false
}