-
Notifications
You must be signed in to change notification settings - Fork 10
/
emojireactioncaptor.go
38 lines (32 loc) · 1.12 KB
/
emojireactioncaptor.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
package capture
import (
"fmt"
"github.com/slack-go/slack"
)
// EmojiReactionCaptor captures emoji reactions recorded by
// invocations of AddReaction. It only supports recording
// emojis for one given channel and timestamp
type EmojiReactionCaptor struct {
Channel string
Timestamp string
Emojis []string
}
// AddReaction captures the addition of an emoji reaction with the given named emoji to the given item
func (e *EmojiReactionCaptor) AddReaction(name string, item slack.ItemRef) error {
if e.Channel == "" {
e.Channel = item.Channel
e.Timestamp = item.Timestamp
e.Emojis = append(e.Emojis, name)
} else if e.Channel == item.Channel && e.Timestamp == item.Timestamp {
e.Emojis = append(e.Emojis, name)
} else {
return fmt.Errorf("EmojiReactionCaptor doesn't support capturing emojis for more than one message")
}
return nil
}
// NewEmojiReactor returns a new EmojiReactionCaptor with an initialized emojis array
func NewEmojiReactor() (emojiReactionCaptor *EmojiReactionCaptor) {
emojiReactionCaptor = new(EmojiReactionCaptor)
emojiReactionCaptor.Emojis = make([]string, 0)
return emojiReactionCaptor
}