-
Notifications
You must be signed in to change notification settings - Fork 0
/
reactions.go
292 lines (274 loc) · 7.33 KB
/
reactions.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
package discord
import (
"fmt"
"reflect"
"strings"
"time"
"github.com/andersfylling/disgord"
disgordiface "github.com/aplombomb/boombot/discord/ifaces"
)
var (
seenEmojis = []*disgord.Emoji{
{
Name: "👀",
},
{
Name: "eyes",
},
{
Name: "monkaEyesZoom",
},
{
Name: "eyesFlipped",
},
{
Name: "freakouteyes",
},
{
Name: "monkaUltraEyes",
},
{
Name: "PepeHmm",
},
}
acceptedEmojis = []*disgord.Emoji{
{
Name: "✅",
},
{
Name: "check",
},
{
Name: "👍",
},
{
Name: "ablobyes",
},
{
Name: "Check",
},
{
Name: "seemsgood",
},
}
rejectedEmojis = []*disgord.Emoji{
{
Name: "🚫",
},
{
Name: "no",
},
{
Name: "steve_nope",
},
{
Name: "❌",
},
{
Name: "xmark",
},
}
)
// AdminReaction defines the structure of needed reaction data
type AdminReaction struct {
userID disgord.Snowflake
channelID disgord.Snowflake
emoji *disgord.Emoji
}
// ReactionEventClient defines contextual data regarding a message react event
type ReactionEventClient struct {
emoji *disgord.Emoji
uID disgord.Snowflake
chID disgord.Snowflake
msgID disgord.Snowflake
disgordClient disgordiface.DisgordClientAPI
}
// NewReactionEventClient returns a pointer to a new ReactionEventClient
func NewReactionEventClient(emoji *disgord.Emoji, uID disgord.Snowflake, chID disgord.Snowflake, msgID disgord.Snowflake, disgordClient disgordiface.DisgordClientAPI) *ReactionEventClient {
return &ReactionEventClient{
emoji,
uID,
chID,
msgID,
disgordClient,
}
}
func deleteReaction(s disgord.Session, data *disgord.MessageReactionAdd) {
err := s.Channel(data.ChannelID).Message(data.MessageID).Reaction(data.PartialEmoji.Name).DeleteUser(data.UserID)
if err != nil {
fmt.Println(err)
}
}
// HandleJukeboxReact triggers the playback channels of the queue in response to user reaction
func (rec *ReactionEventClient) HandleJukeboxReact(s disgord.Session, queue *Queue, data *disgord.MessageReactionAdd) {
if rec.uID != 860286976296878080 && rec.uID == queue.NowPlayingUID {
switch rec.emoji.Name {
case "\u26D4":
go func() {
queue.Stop <- true
return
}()
case "\u267B":
go func() {
deleteReaction(s, data)
queue.Shuffle <- true
return
}()
case "\u23F8":
go func() {
deleteReaction(s, data)
queue.Pause <- true
return
}()
case "\u25B6":
go func() {
deleteReaction(s, data)
queue.Play <- true
return
}()
case "\u23E9":
go func() {
queue.Next <- true
return
}()
}
}
}
// GenerateModResponse returns the applicable message response if reaction criteria are met
func (rec *ReactionEventClient) GenerateModResponse() (*disgord.Message, error) {
// fmt.Printf("Name: %+v\nChannelID: %+v\nUserID: %+v\n", rec.emoji.Name, rec.chID, rec.uID)
dm := disgord.Message{}
reactionEvent := &AdminReaction{
userID: rec.uID,
channelID: rec.chID,
emoji: rec.emoji,
}
seenReactions := createReactions(seenEmojis)
acceptedReactions := createReactions(acceptedEmojis)
rejectedReactions := createReactions(rejectedEmojis)
//Loop through valid seen reactions and check for a match
// TODO: These loops need to be consolidated into a single function
for _, currentSeenReaction := range seenReactions {
if reflect.DeepEqual(currentSeenReaction, reactionEvent) {
url := ""
modName := ""
chQueryBuilder := rec.disgordClient.Channel(rec.chID)
message, _ := chQueryBuilder.GetMessages(&disgord.GetMessagesParams{
Around: rec.msgID,
})
msgFields := strings.Fields(message[0].Content)
//snag the url and the mod name from the request
for _, field := range msgFields {
if strings.Contains(field, "https://www.curseforge.com/minecraft/mc-mods/") {
url = field
urlFields := strings.Split(url, "/")
i := len(urlFields) - 1
modName = urlFields[i]
}
}
dm = disgord.Message{
Embeds: []*disgord.Embed{
{
Title: fmt.Sprintf("**Your request to add %s is being reviewed**", modName),
URL: url,
Description: fmt.Sprintf("*Bomb is reviewing your request to add %s*", modName),
Color: 0xcc0000,
Footer: &disgord.EmbedFooter{
Text: "Sit tight partner!",
IconURL: "https://cdn.discordapp.com/emojis/745396324215685201.gif?v=1",
},
},
},
}
break
}
}
//Loop through valid accepted reactions and check for a match
for _, currentAcceptedReaction := range acceptedReactions {
if reflect.DeepEqual(currentAcceptedReaction, reactionEvent) {
url := ""
modName := ""
chQueryBuilder := rec.disgordClient.Channel(rec.chID)
message, _ := chQueryBuilder.GetMessages(&disgord.GetMessagesParams{
Around: rec.msgID,
})
msgFields := strings.Fields(message[0].Content)
//snag the url and the mod name from the request
for _, field := range msgFields {
if strings.Contains(field, "https://www.curseforge.com/minecraft/mc-mods/") {
url = field
urlFields := strings.Split(url, "/")
i := len(urlFields) - 1
modName = urlFields[i]
}
}
dm = disgord.Message{
Embeds: []*disgord.Embed{
{
Title: fmt.Sprintf("**%s ACCEPTED!!**", modName),
URL: url,
Description: fmt.Sprintf("*Bomb has added %s to the modpack! If the server breaks now, it's all your fault!*", modName),
Color: 0xcc0000,
Footer: &disgord.EmbedFooter{
Text: "Pervert Steve is always watching...",
IconURL: "https://cdn.discordapp.com/emojis/681217726412488767.png?v=1",
},
},
},
}
go deleteMessage(message[0], 3*time.Second, rec.disgordClient)
break
}
}
//Loop through valid rejected reactions and check for a match
//Extract the mod name to include in the embedded dm to the user for context
for _, currentRejectedReaction := range rejectedReactions {
if reflect.DeepEqual(currentRejectedReaction, reactionEvent) {
url := ""
modName := ""
chQueryBuilder := rec.disgordClient.Channel(rec.chID)
message, _ := chQueryBuilder.GetMessages(&disgord.GetMessagesParams{
Around: rec.msgID,
})
msgFields := strings.Fields(message[0].Content)
//snag the url and the mod name from the request
for _, field := range msgFields {
if strings.Contains(field, "https://www.curseforge.com/minecraft/mc-mods/") {
url = field
urlFields := strings.Split(url, "/")
i := len(urlFields) - 1
modName = urlFields[i]
}
}
dm = disgord.Message{
Embeds: []*disgord.Embed{
{
Title: fmt.Sprintf("**%s Rejected**", modName),
URL: url,
Description: fmt.Sprintf("*Bomb has rejected your request to add %s*", modName),
Color: 0xcc0000,
Footer: &disgord.EmbedFooter{
Text: "You have brought much shame upon your famiry",
IconURL: "https://cdn.discordapp.com/emojis/662170922580574258.gif?v=1",
},
},
},
}
go deleteMessage(message[0], 3*time.Second, rec.disgordClient)
break
}
}
return &dm, nil
}
// ParseReaction bundles up reaction data for easier comparison
func createReactions(emojis []*disgord.Emoji) []*AdminReaction {
reactions := []*AdminReaction{}
for _, emoji := range emojis {
reactions = append(reactions, &AdminReaction{
userID: 801961246429544469,
channelID: 734986357583380510,
emoji: emoji,
})
}
return reactions
}