-
Notifications
You must be signed in to change notification settings - Fork 42
/
add_link.go
48 lines (40 loc) · 1.21 KB
/
add_link.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 command
import (
"github.com/innogames/slack-bot/bot"
"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"
)
// NewAddLinkCommand is more or less internal command to add a link button to the posted message
func NewAddLinkCommand(base bot.BaseCommand) bot.Command {
return &addLinkCommand{base}
}
type addLinkCommand struct {
bot.BaseCommand
}
func (c *addLinkCommand) GetMatcher() matcher.Matcher {
return matcher.NewRegexpMatcher("add link (?P<name>.*) <(?P<link>https:.*)>", c.AddLink)
}
func (c *addLinkCommand) AddLink(match matcher.Result, message msg.Message) {
name := match.GetString("name")
link := match.GetString("link")
attachment := slack.Attachment{
Actions: []slack.AttachmentAction{
client.GetSlackLink(name, link),
},
}
c.SendMessage(message, "", slack.MsgOptionAttachments(attachment))
}
func (c *addLinkCommand) GetHelp() []bot.Help {
return []bot.Help{
{
Command: "add link",
Description: "adds a link button to the message",
Examples: []string{
"add link Google https://google.com",
"add link Review https://stash.example.com/pr/12/review",
},
},
}
}