forked from priscillachat/priscilla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.go
56 lines (45 loc) · 1.09 KB
/
misc.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
54
55
56
package main
import (
"fmt"
"strings"
)
func checkHelp(msg, source, room string, dp chan<- *dispatcherRequest) bool {
logger.Debug.Println("Checking help command:", msg)
matches := conf.helpRegex.FindAllStringSubmatch(msg, 1)
if len(matches) == 0 {
logger.Debug.Println("No help match found")
return false
}
section := ""
if len(matches[0]) > 1 {
section = matches[0][1]
}
dp <- &dispatcherRequest{
Query: &query{
Type: "message",
Source: "Internal: help",
To: source,
Message: &messageBlock{
Message: strings.Trim(showHelp(section), " \n"),
Room: room,
},
},
}
return true
}
func showHelp(cmdPrefix string) string {
helpMsg := "Here is what I can do:\n"
for helpE := help.Front(); helpE != nil; helpE = helpE.Next() {
h := helpE.Value.(*helpInfo)
if h.mention {
helpMsg += fmt.Sprintf("(when mentioned) %s - %s\n", h.helpCmd,
h.helpMsg)
} else if h.noPrefix {
helpMsg += fmt.Sprintf("%s - %s\n", h.helpCmd, h.helpMsg)
} else {
helpMsg += fmt.Sprintf("%s %s - %s\n", conf.Prefix, h.helpCmd,
h.helpMsg)
}
}
return helpMsg
}