-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventdelegation.go
124 lines (112 loc) · 4.91 KB
/
eventdelegation.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
package discord
import (
"fmt"
"time"
"github.com/andersfylling/disgord"
)
// Goal is to have this file as small as possible, the purpose of this file isn't about delegation so to say
// It's acting as an intermediary; separating global vars from the business logic
// This means the more code/logic I can get out of this file, the more code/logic that can be tested
// RespondToCommand delegates actions when commands are issued
func RespondToCommand(s disgord.Session, data *disgord.MessageCreate) {
plis := ytService.PlaylistItems.List([]string{"snippet", "status", "contentDetails"})
ytv := ytService.Search.List([]string{"snippet"}).MaxResults(3).Order("relevance").SafeSearch("none").Type("video")
cec := NewCommandEventClient(data.Message, disgordGlobalClient, plis, ytv, globalQueue)
cec.Delegate()
}
// RespondToMessage delegates actions when messages are created
func RespondToMessage(s disgord.Session, data *disgord.MessageCreate) {
switch data.Message.ChannelID {
case 1031788884960493618:
data.Message.React(ctx, s, "\u26D4") // Purge emoji
time.Sleep(1 * time.Second)
data.Message.React(ctx, s, "\u267B") // Shuffle Emoji
time.Sleep(1 * time.Second)
data.Message.React(ctx, s, "\u23F8") // Pause Emoji
time.Sleep(1 * time.Second)
data.Message.React(ctx, s, "\u25B6") // Play Emoji
time.Sleep(1 * time.Second)
data.Message.React(ctx, s, "\u23E9") // Next emoji
time.Sleep(1 * time.Second)
}
user := data.Message.Author
fmt.Printf("\n%+v: %+v | %+v\n", user.Username, data.Message.Content, time.Now().Format("Mon Jan _2 15:04:05 2006"))
mec := NewMessageEventClient(data.Message, disgordGlobalClient)
err := mec.FilterNonModLinks()
if err != nil {
fmt.Printf("\nError filtering non-mod link: %+v\n", err)
}
}
// RespondToReaction delegates actions when reactions are added to messages
func RespondToReaction(s disgord.Session, data *disgord.MessageReactionAdd) {
userQueryBuilder := disgordGlobalClient.User(data.UserID)
user, err := userQueryBuilder.Get()
if err != nil {
fmt.Printf("\nError getting user: %+v\n", err)
}
// fmt.Printf("Message reaction %+v by user %+v | %+v\n", data.PartialEmoji.Name, user.Username, time.Now().Format("Mon Jan _2 15:04:05 2006"))
rec := NewReactionEventClient(data.PartialEmoji, data.UserID, data.ChannelID, data.MessageID, disgordGlobalClient)
rec.HandleJukeboxReact(s, globalQueue, data)
msg, err := rec.GenerateModResponse()
if err != nil {
fmt.Printf("\nError generating mod reaction response: %+v\n", err)
}
//TO-DO Sending the dm here as opposed having it sent via GenerateModResponse for testing purposes
// Using it here at least allows me to get full coverage of the reactions logic
// The SendMsg method of disgord.User requires session arg which has proven difficult to mock
if msg != nil {
user.SendMsg(ctx, s, msg)
}
}
// RespondToVoiceChannelUpdate updates the server's voice channel cache every time an update is emitted
func RespondToVoiceChannelUpdate(s disgord.Session, data *disgord.VoiceStateUpdate) {
globalQueue.UpdateVoiceCache(data.ChannelID, data.UserID)
if data.ChannelID != 0 && data.ChannelID != globalQueue.VoiceCache[860286976296878080] && data.UserID == globalQueue.NowPlayingUID && globalQueue.VoiceCache[data.UserID] != 0 {
go func() { //used to be this: 851268581094457357
globalQueue.ChannelHop <- data.ChannelID
return
}()
}
}
// RespondToPresenceUpdate fires when a server member's presence state changes
// func RespondToPresenceUpdate(s disgord.Session, data *disgord.PresenceUpdate) {
// This is temporary for testing\will be moved to a "roles" client
// after i decide how i want to handle these events
// Roles drg, twerkov, crafter respectively
// Will map game name as string key/snowflake of role as value
// Will make it really easy to remove/add role ids on events
// roleCache := map[string]disgord.Snowflake
// managedRoles := []disgord.Snowflake{787758251574820864, 737467990647373827, 735890320348282880}
// gameEvent, _ := data.Game()
// fmt.Println("GameEvent: ", gameEvent)
// fmt.Println("User: ", data.User.Username)
// if gameEvent == nil {
// fmt.Println("This must have been an online/offline event")
// return
// }
// fmt.Println("Game Name: ", gameEvent.Name)
// if len(data.Activities) == 0 {
// memberQueryBuilder := globalGuild.Member(data.User.ID)
// member, err := globalGuild.Member(data.User.ID).Get()
// if err != nil {
// fmt.Println("Error fetching member for role adjustment: ", err)
// }
// roles := member.Roles
// fmt.Printf("\n%+v's roles before: %+v", data.User.Username, roles)
// for _, rv := range roles {
// for _, mrv := range managedRoles {
// if mrv == rv {
// memberQueryBuilder.RemoveRole(mrv)
// }
// }
// }
// fmt.Printf("\n%+v's roles after: %+v", data.User.Username, roles)
// return
// }
// userID := data.User.ID
// activityName := data.Activities[0].Name
// drgRoleID := 864
// for k := range data.Activities {
// fmt.Println("activity: ", data.Activities[k])
// }
// }