-
Notifications
You must be signed in to change notification settings - Fork 42
/
reaction.go
42 lines (33 loc) · 903 Bytes
/
reaction.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
package util
import (
"strings"
"github.com/hackebrot/turtle"
)
// Reaction representation for a reaction/emoji. It can be the "id" of the reaction (like "smile", or the actual Unicode char, like "😄")
type Reaction string
// ToSlackReaction uses the "id" of the reaction/Emoji, like "smile". It trims potential ":"
func (r Reaction) ToSlackReaction() string {
emoji := r.getEmoji()
if emoji == nil {
return strings.Trim(string(r), ":")
}
return emoji.Name
}
// GetChar get the real string/unicode representation of the current reaction/emoji
func (r Reaction) GetChar() string {
emoji := r.getEmoji()
if emoji == nil {
return "?"
}
return emoji.Char
}
func (r Reaction) getEmoji() *turtle.Emoji {
name := strings.Trim(string(r), ":")
if emoji, ok := turtle.Emojis[name]; ok {
return emoji
}
if emoji, ok := turtle.EmojisByChar[name]; ok {
return emoji
}
return nil
}