-
Notifications
You must be signed in to change notification settings - Fork 42
/
add_button.go
52 lines (43 loc) · 1.41 KB
/
add_button.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
package command
import (
"github.com/innogames/slack-bot/bot"
"github.com/innogames/slack-bot/bot/config"
"github.com/innogames/slack-bot/bot/matcher"
"github.com/innogames/slack-bot/bot/msg"
"github.com/innogames/slack-bot/client"
"github.com/slack-go/slack"
)
// NewAddButtonCommand is more or less internal command to add a link button to the posted message
func NewAddButtonCommand(base bot.BaseCommand, cfg config.Server) bot.Command {
return &addButtonCommand{base, cfg}
}
type addButtonCommand struct {
bot.BaseCommand
cfg config.Server
}
func (c *addButtonCommand) GetMatcher() matcher.Matcher {
return matcher.NewRegexpMatcher("add button \"(?P<name>.*)\" \"(?P<command>.*)\"", c.AddLink)
}
func (c *addButtonCommand) AddLink(match matcher.Result, message msg.Message) {
name := match.GetString("name")
command := match.GetString("command")
blocks := []slack.Block{
client.GetInteraction(message, name, command),
}
c.SendMessage(message, "", slack.MsgOptionBlocks(blocks...))
}
// IsEnabled checks if the http server is enabled to receive slack interactions
func (c *addButtonCommand) IsEnabled() bool {
return c.cfg.IsEnabled()
}
func (c *addButtonCommand) GetHelp() []bot.Help {
return []bot.Help{
{
Command: "add button",
Description: "adds a button to the message which then performs any command",
Examples: []string{
"add button \"Start job\" \"trigger job XYZ\"",
},
},
}
}