-
Notifications
You must be signed in to change notification settings - Fork 42
/
command.go
64 lines (56 loc) · 1.62 KB
/
command.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
59
60
61
62
63
64
package custom_variables
import (
"github.com/innogames/slack-bot/v2/bot"
"github.com/innogames/slack-bot/v2/bot/config"
"github.com/innogames/slack-bot/v2/bot/matcher"
)
// GetCommand returns a set of all commands to manage user specific variables
func GetCommand(base bot.BaseCommand, cfg *config.Config) bot.Command {
return command{base, cfg}
}
type command struct {
bot.BaseCommand
cfg *config.Config
}
func (c command) GetMatcher() matcher.Matcher {
return matcher.NewGroupMatcher(
matcher.NewRegexpMatcher("(add|set) variable '?(?P<name>.*?)'? '?(?P<value>.*?)'?", c.add),
matcher.NewRegexpMatcher("(delete|remove) variable '?(?P<name>.*?)'?", c.delete),
matcher.NewTextMatcher("list variables", c.list),
)
}
func (c command) IsEnabled() bool {
cfg := loadConfig(c.cfg)
return cfg.Enabled
}
func (c command) GetHelp() []bot.Help {
return []bot.Help{
{
Command: "set variable <key> <value>",
Description: "Set a custom variable for just the current user",
Examples: []string{
"set variable 'server' 'foo.prod.local'",
},
Category: category,
},
{
Command: "delete variable <key>",
Description: "Remove a custom variable (for current user only)",
Examples: []string{
"remove variable 'server'",
},
Category: category,
},
{
Command: "list variables",
Description: "List you custom variables",
Examples: []string{"list variables"},
Category: category,
},
}
}
var category = bot.Category{
Name: "Custom Variables",
Description: "usable e.g. in 'commands' or 'crons'",
HelpURL: "https://github.com/innogames/slack-bot#custom-variables",
}