plugin_help.go (view raw)
1package main
2
3import (
4 "bytes"
5 "log"
6)
7
8type HelpPlugin struct {
9}
10
11func (plugin *HelpPlugin) GetName() string {
12 return "Plugins help"
13}
14
15func (plugin *HelpPlugin) GetCommands() []string {
16 return []string{"/help"}
17}
18
19func (plugin *HelpPlugin) GetHelpText() []string {
20 return []string{"/help (/command) - returns help about a command"}
21}
22
23func (plugin *HelpPlugin) Setup() {
24}
25
26func (plugin *HelpPlugin) GotCommand(command string, message Message, args []string) {
27 msg := NewMessage(message.Chat.Id, "")
28 msg.ReplyToMessageId = message.MessageId
29 msg.DisableWebPagePreview = true
30
31 var buffer bytes.Buffer
32
33 if len(args) > 0 {
34 for _, plug := range plugins {
35 for _, cmd := range plug.GetCommands() {
36 log.Println(cmd)
37 log.Println(args[0])
38 log.Println(args[0][1:])
39 if cmd == args[0] || cmd[1:] == args[0] {
40 buffer.WriteString(plug.GetName())
41 buffer.WriteString("\n")
42
43 for _, help := range plug.GetHelpText() {
44 buffer.WriteString(" ")
45 buffer.WriteString(help)
46 buffer.WriteString("\n")
47 }
48 }
49 }
50 }
51 } else {
52 buffer.WriteString(config.Plugins["about_text"])
53 buffer.WriteString("\n\n")
54
55 for _, plug := range plugins {
56 val, _ := config.EnabledPlugins[plugin.GetName()]
57
58 buffer.WriteString(plug.GetName())
59 if !val {
60 buffer.WriteString(" (disabled)")
61 }
62 buffer.WriteString("\n")
63
64 for _, cmd := range plug.GetHelpText() {
65 buffer.WriteString(" ")
66 buffer.WriteString(cmd)
67 buffer.WriteString("\n")
68 }
69
70 buffer.WriteString("\n")
71 }
72 }
73
74 msg.Text = buffer.String()
75 bot.sendMessage(msg)
76}