This repository was archived by the owner on Sep 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathreactionevents.go
More file actions
98 lines (73 loc) · 1.54 KB
/
Copy pathreactionevents.go
File metadata and controls
98 lines (73 loc) · 1.54 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import "github.com/diamondburned/discordgo"
func reactionAdd(s *discordgo.Session, ra *discordgo.MessageReactionAdd) {
if Channel == nil || ra.ChannelID != Channel.ID {
return
}
m, err := d.State.Message(Channel.ID, ra.MessageID)
if err != nil {
return
}
d.State.Lock()
for _, r := range m.Reactions {
if !isSameEmoji(r, ra.MessageReaction) {
continue
}
r.Count++
if ra.UserID == d.State.User.ID {
r.Me = true
}
goto Found
}
m.Reactions = append(
m.Reactions,
&discordgo.MessageReactions{
Count: 1,
Me: ra.UserID == d.State.User.ID,
Emoji: &ra.Emoji,
},
)
Found:
d.State.Unlock()
handleReactionEvent(m)
}
func reactionRemove(s *discordgo.Session, rm *discordgo.MessageReactionRemove) {
if Channel == nil || rm.ChannelID != Channel.ID {
return
}
m, err := d.State.Message(Channel.ID, rm.MessageID)
if err != nil {
return
}
d.State.Lock()
for i, r := range m.Reactions {
if !isSameEmoji(r, rm.MessageReaction) {
continue
}
r.Count--
if r.Count == 0 {
m.Reactions = removeAllReactions(
m.Reactions, i,
)
break
}
if rm.UserID == d.State.User.ID {
r.Me = false
}
}
d.State.Unlock()
handleReactionEvent(m)
}
func reactionRemoveAll(s *discordgo.Session, rm *discordgo.MessageReactionRemoveAll) {
if Channel == nil || rm.ChannelID != Channel.ID {
return
}
m, err := d.State.Message(Channel.ID, rm.MessageID)
if err != nil {
return
}
d.State.Lock()
m.Reactions = []*discordgo.MessageReactions{}
d.State.Unlock()
handleReactionEvent(m)
}