-
Notifications
You must be signed in to change notification settings - Fork 0
/
help.go
executable file
·48 lines (40 loc) · 827 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
38
39
40
41
42
43
44
45
46
47
48
package actions
import (
"fmt"
"strings"
"github.com/zaibon/ircbot"
)
type Help struct{}
func (h *Help) Command() []string {
return []string{
".help",
".h",
}
}
func (h *Help) Usage() string {
return ".h <command>"
}
func (h *Help) Do(b *ircbot.IrcBot, m *ircbot.IrcMsg) {
if len(m.Trailing) < 2 {
var output string
fmt.Printf("%+v", b.GetActionnersCmds())
for _, cmd := range b.GetActionnersCmds() {
output += fmt.Sprintf("%s, ", cmd)
}
b.Say(m.Channel(), output[:len(output)-2])
return
}
cmd := m.Trailing[1]
if !strings.HasPrefix(cmd, ".") {
cmd = fmt.Sprintf(".%s", cmd)
}
actioner, err := b.GetActioner(cmd)
if err != nil {
b.Say(m.Channel(), err.Error())
return
}
lines := strings.Split(actioner.Usage(), "\n")
for _, line := range lines {
b.Say(m.Channel(), line)
}
}