/
helpparser.go
58 lines (48 loc) · 1.27 KB
/
helpparser.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
57
58
package help
import (
"errors"
"github.com/bwmarrin/discordgo"
"github.com/jakevoytko/crbot/feature"
"github.com/jakevoytko/crbot/log"
"github.com/jakevoytko/crbot/model"
"github.com/jakevoytko/crbot/util"
)
// Parser parses ?help commands.
type Parser struct {
featureRegistry *feature.Registry
}
// NewParser works as advertised.
func NewParser(featureRegistry *feature.Registry) *Parser {
return &Parser{
featureRegistry: featureRegistry,
}
}
// GetName returns the named type.
func (p *Parser) GetName() string {
return model.CommandNameHelp
}
const (
// MsgHelpHelp prints the results of ?help help
MsgHelpHelp = "Get help for help."
)
// HelpText returns the help text.
func (p *Parser) HelpText(command string) (string, error) {
return MsgHelpHelp, nil
}
// Parse parses the given help command.
func (p *Parser) Parse(splitContent []string, m *discordgo.MessageCreate) (*model.Command, error) {
if splitContent[0] != p.GetName() {
log.Fatal("parseHelp called with non-help command", errors.New("wat"))
}
splitContent = util.CollapseWhitespace(splitContent, 1)
userCommand := ""
if len(splitContent) > 1 {
userCommand = splitContent[1]
}
return &model.Command{
Type: model.CommandTypeHelp,
Help: &model.HelpData{
Command: userCommand,
},
}, nil
}