forked from raylu/rbot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcmd-help.go
50 lines (40 loc) · 1.15 KB
/
cmd-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
package main
import (
irc "github.com/fluffle/goirc/client"
config "goconfig"
"strings"
)
const helpFile = "help.conf"
func helpGetTopics() (helpTopics string) {
c, _ := config.ReadDefault(helpFile)
helpTopics, _ = c.String("DEFAULT", "topics")
return helpTopics
}
func helpGetHelp(conn *irc.Conn, topic string, channel string) {
c, _ := config.ReadDefault(helpFile)
var text []string
content, _ := c.String(topic, "content")
content = strings.Replace(content, "{trigger}", trigger, -1)
text = strings.Split(content, "\n")
for _, out := range text {
say(conn, channel, out)
}
}
func helpProcessRequest(conn *irc.Conn, nick *irc.Nick, topic string, channel string) {
channel = nick.Nick
topic = strings.TrimSpace(topic)
validTopics := strings.ToLower(helpGetTopics())
if topic == "" {
say(conn, channel, "Syntax is !help <topic>. Valid topics are:")
say(conn, channel, validTopics)
}
topic = strings.ToLower(topic)
if strings.Contains(validTopics, topic) {
helpGetHelp(conn, topic, channel)
return
} else {
say(conn, channel, "%s is not a valid help topic. Valid topics are:", topic)
say(conn, channel, validTopics)
return
}
}