forked from fabioxgn/go-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
help.go
46 lines (39 loc) · 1.16 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
package bot
import (
"fmt"
"strings"
)
const (
helpDescripton = "Description: %s"
helpUsage = "Usage: %s%s %s"
availableCommands = "Available commands: %v"
helpAboutCommand = "Type: '%shelp <command>' to see details about a specific command."
helpCommand = "help"
)
func help(c *Cmd, channel, senderNick string, conn ircConnection) {
cmd := parse(CmdPrefix+c.FullArg, channel, senderNick)
if cmd == nil {
showAvailabeCommands(channel, conn)
return
}
command := commands[cmd.Command]
if command == nil {
showAvailabeCommands(c.Channel, conn)
return
}
showHelp(cmd, command, conn)
}
func showHelp(c *Cmd, help *customCommand, conn ircConnection) {
if help.Description != "" {
conn.Privmsg(c.Channel, fmt.Sprintf(helpDescripton, help.Description))
}
conn.Privmsg(c.Channel, fmt.Sprintf(helpUsage, CmdPrefix, c.Command, help.ExampleArgs))
}
func showAvailabeCommands(channel string, conn ircConnection) {
cmds := make([]string, 0)
for k := range commands {
cmds = append(cmds, k)
}
conn.Privmsg(channel, fmt.Sprintf(helpAboutCommand, CmdPrefix))
conn.Privmsg(channel, fmt.Sprintf(availableCommands, strings.Join(cmds, ", ")))
}