-
Notifications
You must be signed in to change notification settings - Fork 4
/
events.go
669 lines (523 loc) · 22.7 KB
/
events.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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
package harmony
import (
"github.com/skwair/harmony/discord"
"github.com/skwair/harmony/voice"
)
type handler interface {
handle(interface{})
}
var intents = map[string]discord.GatewayIntent{
eventGuildCreate: discord.GatewayIntentGuild,
eventGuildUpdate: discord.GatewayIntentGuild,
eventGuildRoleCreate: discord.GatewayIntentGuild,
eventGuildRoleUpdate: discord.GatewayIntentGuild,
eventGuildRoleDelete: discord.GatewayIntentGuild,
eventChannelCreate: discord.GatewayIntentGuild,
eventChannelUpdate: discord.GatewayIntentGuild,
eventChannelDelete: discord.GatewayIntentGuild,
eventChannelPinsUpdate: discord.GatewayIntentGuild,
eventGuildMemberAdd: discord.GatewayIntentGuildMembers,
eventGuildMemberUpdate: discord.GatewayIntentGuildMembers,
eventGuildMemberRemove: discord.GatewayIntentGuildMembers,
eventGuildBanAdd: discord.GatewayIntentGuildBans,
eventGuildBanRemove: discord.GatewayIntentGuildBans,
eventGuildEmojisUpdate: discord.GatewayIntentGuildEmojis,
eventGuildIntegrationsUpdate: discord.GatewayIntentGuildIntegrations,
eventWebhooksUpdate: discord.GatewayIntentGuildWebhooks,
eventGuildInviteCreate: discord.GatewayIntentGuildInvites,
eventGuildInviteDelete: discord.GatewayIntentGuildInvites,
eventVoiceStateUpdate: discord.GatewayIntentGuildVoiceStates,
eventPresenceUpdate: discord.GatewayIntentGuildPresences,
eventMessageCreate: discord.GatewayIntentGuildMessages | discord.GatewayIntentDirectMessages,
eventMessageUpdate: discord.GatewayIntentGuildMessages | discord.GatewayIntentDirectMessages,
eventMessageDelete: discord.GatewayIntentGuildMessages | discord.GatewayIntentDirectMessages,
eventMessageDeleteBulk: discord.GatewayIntentGuildMessages | discord.GatewayIntentDirectMessages,
eventMessageReactionAdd: discord.GatewayIntentGuildMessageReactions | discord.GatewayIntentDirectMessageReactions,
eventMessageReactionRemove: discord.GatewayIntentGuildMessageReactions | discord.GatewayIntentDirectMessageReactions,
eventMessageReactionRemoveAll: discord.GatewayIntentGuildMessageReactions | discord.GatewayIntentDirectMessageReactions,
eventMessageReactionRemoveEmoji: discord.GatewayIntentGuildMessageReactions | discord.GatewayIntentDirectMessageReactions,
eventTypingStart: discord.GatewayIntentGuildMessageTyping | discord.GatewayIntentDirectMessageTyping,
}
func (c *Client) registerHandler(event string, h handler) {
c.mu.Lock()
defer c.mu.Unlock()
if missing := intents[event]; missing&c.intents == 0 {
c.logger.Warnf("registering handler for event %q without required intent %q", event, missing)
}
if h == nil {
panic("harmony: trying to register a nil event handler")
}
c.handlersMu.Lock()
c.handlers[event] = h
c.handlersMu.Unlock()
c.logger.Debugf("registered handler for %s events", event)
}
type readyHandler func(*Ready)
// handle implements the handler interface.
func (h readyHandler) handle(v interface{}) {
h(v.(*Ready))
}
// OnReady registers the handler function for the "READY" event.
func (c *Client) OnReady(f func(r *Ready)) {
c.registerHandler(eventReady, readyHandler(f))
}
type channelCreateHandler func(*discord.Channel)
// handle implements the handler interface.
func (h channelCreateHandler) handle(v interface{}) {
h(v.(*discord.Channel))
}
// OnChannelCreate registers the handler function for the "CHANNEL_CREATE" event.
// This event is fired when a new channel is created, relevant to the current user.
func (c *Client) OnChannelCreate(f func(c *discord.Channel)) {
c.registerHandler(eventChannelCreate, channelCreateHandler(f))
}
type channelUpdateHandler func(*discord.Channel)
// handle implements the handler interface.
func (h channelUpdateHandler) handle(v interface{}) {
h(v.(*discord.Channel))
}
// OnChannelUpdate registers the handler function for the "CHANNEL_UPDATE" event.
// This event is fired when a channel is updated, relevant to the current user.
func (c *Client) OnChannelUpdate(f func(c *discord.Channel)) {
c.registerHandler(eventChannelUpdate, channelUpdateHandler(f))
}
type channelDeleteHandler func(*discord.Channel)
// handle implements the handler interface.
func (h channelDeleteHandler) handle(v interface{}) {
h(v.(*discord.Channel))
}
// OnChannelDelete registers the handler function for the "CHANNEL_DELETE" event.
// This event is fired when a channel is deleted, relevant to the current user.
func (c *Client) OnChannelDelete(f func(c *discord.Channel)) {
c.registerHandler(eventChannelDelete, channelDeleteHandler(f))
}
// ChannelPinsUpdate is Fired when a message is pinned or unpinned in a text channel.
type ChannelPinsUpdate struct {
ChannelID string `json:"channel_id"`
LastPinTimestamp discord.Time `json:"last_pin_timestamp"`
}
type channelPinsUpdateHandler func(*ChannelPinsUpdate)
// handle implements the handler interface.
func (h channelPinsUpdateHandler) handle(v interface{}) {
h(v.(*ChannelPinsUpdate))
}
// OnChannelPinsUpdate registers the handler function for the "CHANNEL_PINS_UPDATE" event.
// This event is fired when a message is pinned or unpinned, but not when a pinned message
// is deleted.
func (c *Client) OnChannelPinsUpdate(f func(cpu *ChannelPinsUpdate)) {
c.registerHandler(eventChannelPinsUpdate, channelPinsUpdateHandler(f))
}
type guildCreateHandler func(*discord.Guild)
// handle implements the handler interface.
func (h guildCreateHandler) handle(v interface{}) {
h(v.(*discord.Guild))
}
// OnGuildCreate registers the handler function for the "GUILD_CREATE" event.
// This event can be sent in three different scenarios:
// 1. When a user is initially connecting, to lazily load and backfill information for all unavailable guilds sent in the Ready event.
// 2. When a Guild becomes available again to the client.
// 3. When the current user joins a new Guild.
func (c *Client) OnGuildCreate(f func(g *discord.Guild)) {
c.registerHandler(eventGuildCreate, guildCreateHandler(f))
}
type guildUpdateHandler func(*discord.Guild)
// handle implements the handler interface.
func (h guildUpdateHandler) handle(v interface{}) {
h(v.(*discord.Guild))
}
// HandleGuildUpdate registers the handler function for the "GUILD_UPDATE" event.
func (c *Client) OnGuildUpdate(f func(g *discord.Guild)) {
c.registerHandler(eventGuildUpdate, guildUpdateHandler(f))
}
type guildDeleteHandler func(*discord.UnavailableGuild)
// handle implements the handler interface.
func (h guildDeleteHandler) handle(v interface{}) {
h(v.(*discord.UnavailableGuild))
}
// OnGuildDelete registers the handler function for the "GUILD_DELETE" event.
// This event is fired when a guild becomes unavailable during a guild outage,
// or when the user leaves or is removed from a guild. If the unavailable field
// is not set, the user was removed from the guild.
func (c *Client) OnGuildDelete(f func(g *discord.UnavailableGuild)) {
c.registerHandler(eventGuildDelete, guildDeleteHandler(f))
}
type GuildBan struct {
*discord.User
GuildID string `json:"guild_id"`
}
type guildBanAddHandler func(*GuildBan)
// handle implements the handler interface.
func (h guildBanAddHandler) handle(v interface{}) {
h(v.(*GuildBan))
}
// OnGuildBanAdd registers the handler function for the "GUILD_BAN_ADD" event.
func (c *Client) OnGuildBanAdd(f func(ban *GuildBan)) {
c.registerHandler(eventGuildBanAdd, guildBanAddHandler(f))
}
type guildBanRemoveHandler func(*GuildBan)
// handle implements the handler interface.
func (h guildBanRemoveHandler) handle(v interface{}) {
h(v.(*GuildBan))
}
// OnGuildBanRemove registers the handler function for the "GUILD_BAN_REMOVE" event.
// This event is fired when a guild is updated.
func (c *Client) OnGuildBanRemove(f func(ban *GuildBan)) {
c.registerHandler(eventGuildBanRemove, guildBanRemoveHandler(f))
}
type GuildEmojis struct {
Emojis []discord.Emoji `json:"emojis"`
GuildID string `json:"guild_id"`
}
type guildEmojisUpdateHandler func(*GuildEmojis)
// handle implements the handler interface.
func (h guildEmojisUpdateHandler) handle(v interface{}) {
h(v.(*GuildEmojis))
}
// OnGuildEmojisUpdate registers the handler function for the "GUILD_EMOJIS_UPDATE" event.
// Fired when a guild's emojis have been updated.
func (c *Client) OnGuildEmojisUpdate(f func(emojis *GuildEmojis)) {
c.registerHandler(eventGuildEmojisUpdate, guildEmojisUpdateHandler(f))
}
type GuildIntegrationUpdate struct {
GuildID string `json:"guild_id"`
}
type guildIntegrationUpdateHandler func(*GuildIntegrationUpdate)
// handle implements the handler interface.
func (h guildIntegrationUpdateHandler) handle(v interface{}) {
h(v.(*GuildIntegrationUpdate))
}
// OnGuildIntegrationsUpdate registers the handler function for the "GUILD_INTEGRATIONS_UPDATE" event.
// Fired when a guild integration is updated.
func (c *Client) OnGuildIntegrationsUpdate(f func(u *GuildIntegrationUpdate)) {
c.registerHandler(eventGuildIntegrationsUpdate, guildIntegrationUpdateHandler(f))
}
type GuildMemberAdd struct {
*discord.GuildMember
GuildID string `json:"guild_id"`
}
type guildMemberAddHandler func(*GuildMemberAdd)
// handle implements the handler interface.
func (h guildMemberAddHandler) handle(v interface{}) {
h(v.(*GuildMemberAdd))
}
// OnGuildMemberAdd registers the handler function for the "GUILD_MEMBER_ADD" event.
// Fired when a new user joins a guild.
func (c *Client) OnGuildMemberAdd(f func(m *GuildMemberAdd)) {
c.registerHandler(eventGuildMemberAdd, guildMemberAddHandler(f))
}
type GuildMemberRemove struct {
User *discord.User `json:"user"`
GuildID string `json:"guild_id"`
}
type guildMemberRemoveHandler func(*GuildMemberRemove)
// handle implements the handler interface.
func (h guildMemberRemoveHandler) handle(v interface{}) {
h(v.(*GuildMemberRemove))
}
// OnGuildMemberRemove registers the handler function for the "GUILD_MEMBER_REMOVE" event.
// Fired when a user is removed from a guild (leave/kick/ban).
func (c *Client) OnGuildMemberRemove(f func(m *GuildMemberRemove)) {
c.registerHandler(eventGuildMemberRemove, guildMemberRemoveHandler(f))
}
type GuildMemberUpdate struct {
GuildID string `json:"guild_id"`
Roles []string `json:"roles"`
User *discord.User `json:"user"`
Nick string `json:"nick"`
}
type guildMemberUpdateHandler func(*GuildMemberUpdate)
// handle implements the handler interface.
func (h guildMemberUpdateHandler) handle(v interface{}) {
h(v.(*GuildMemberUpdate))
}
// OnGuildMemberUpdate registers the handler function for the "GUILD_MEMBER_UPDATE" event.
// Fired when a guild member is updated.
func (c *Client) OnGuildMemberUpdate(f func(m *GuildMemberUpdate)) {
c.registerHandler(eventGuildMemberUpdate, guildMemberUpdateHandler(f))
}
type GuildMembersChunk struct {
GuildID string `json:"guild_id"`
Members []discord.GuildMember `json:"members"`
}
type guildMembersChunkHandler func(*GuildMembersChunk)
// handle implements the handler interface.
func (h guildMembersChunkHandler) handle(v interface{}) {
h(v.(*GuildMembersChunk))
}
// OnGuildMembersChunk registers the handler function for the "GUILD_MEMBERS_CHUNK" event.
// Sent in response to Guild Request Members.
func (c *Client) OnGuildMembersChunk(f func(m *GuildMembersChunk)) {
c.registerHandler(eventGuildMembersChunk, guildMembersChunkHandler(f))
}
type GuildRole struct {
GuildID string `json:"guild_id"`
Role *discord.Role `json:"role"`
}
type guildRoleCreateHandler func(*GuildRole)
// handle implements the handler interface.
func (h guildRoleCreateHandler) handle(v interface{}) {
h(v.(*GuildRole))
}
// OnGuildRoleCreate registers the handler function for the "GUILD_ROLE_CREATE" event.
// Fired when a guild role is created.
func (c *Client) OnGuildRoleCreate(f func(r *GuildRole)) {
c.registerHandler(eventGuildRoleCreate, guildRoleCreateHandler(f))
}
type guildRoleUpdateHandler func(*GuildRole)
// handle implements the handler interface.
func (h guildRoleUpdateHandler) handle(v interface{}) {
h(v.(*GuildRole))
}
// OnGuildRoleUpdate registers the handler function for the "GUILD_ROLE_UPDATE" event.
// Fired when a guild role is updated.
func (c *Client) OnGuildRoleUpdate(f func(r *GuildRole)) {
c.registerHandler(eventGuildRoleUpdate, guildRoleUpdateHandler(f))
}
type GuildRoleDelete struct {
GuildID string `json:"guild_id"`
RoleID string `json:"role_id"`
}
type guildRoleDeleteHandler func(*GuildRoleDelete)
// handle implements the handler interface.
func (h guildRoleDeleteHandler) handle(v interface{}) {
h(v.(*GuildRoleDelete))
}
// OnGuildRoleDelete registers the handler function for the "GUILD_ROLE_DELETE" event.
// Fired when a guild role is deleted.
func (c *Client) OnGuildRoleDelete(f func(r *GuildRoleDelete)) {
c.registerHandler(eventGuildRoleDelete, guildRoleDeleteHandler(f))
}
type GuildInviteCreate struct {
ChannelID string `json:"channel_id"`
Code string `json:"code"`
CreatedAt discord.Time `json:"created_at"`
GuildID string `json:"guild_id"`
Inviter *discord.User `json:"inviter"`
MaxAge int `json:"max_age"`
MaxUses int `json:"max_uses"`
TargetUser *discord.User `json:"target_user"`
TargetUserType int `json:"target_user_type"`
Temporary bool `json:"temporary"`
Uses int `json:"uses"`
}
type guildInviteCreateHandler func(*GuildInviteCreate)
// handle implements the handler interface.
func (h guildInviteCreateHandler) handle(v interface{}) {
h(v.(*GuildInviteCreate))
}
// OnGuildInviteCreate registers the handler function for the "GUILD_ROLE_DELETE" event.
// Fired when a guild role is deleted.
func (c *Client) OnGuildInviteCreate(f func(i *GuildInviteCreate)) {
c.registerHandler(eventGuildInviteCreate, guildInviteCreateHandler(f))
}
type GuildInviteDelete struct {
ChannelID string `json:"channel_id"`
GuildID string `json:"guild_id"`
Code string `json:"code"`
}
type guildInviteDeleteHandler func(*GuildInviteDelete)
// handle implements the handler interface.
func (h guildInviteDeleteHandler) handle(v interface{}) {
h(v.(*GuildInviteDelete))
}
// OnGuildInviteDelete registers the handler function for the "GUILD_ROLE_DELETE" event.
// Fired when a guild role is deleted.
func (c *Client) OnGuildInviteDelete(f func(i *GuildInviteDelete)) {
c.registerHandler(eventGuildInviteDelete, guildInviteDeleteHandler(f))
}
type messageCreateHandler func(*discord.Message)
// handle implements the handler interface.
func (h messageCreateHandler) handle(v interface{}) {
h(v.(*discord.Message))
}
// OnMessageCreate registers the handler function for the "MESSAGE_CREATE" event.
// Fired when a message is created.
func (c *Client) OnMessageCreate(f func(m *discord.Message)) {
c.registerHandler(eventMessageCreate, messageCreateHandler(f))
}
type messageUpdateHandler func(*discord.Message)
// handle implements the handler interface.
func (h messageUpdateHandler) handle(v interface{}) {
h(v.(*discord.Message))
}
// OnMessageUpdate registers the handler function for the "MESSAGE_UPDATE" event.
// Fired when a message is updated. Unlike creates, message updates may contain only
// a subset of the full message object payload (but will always contain an id and channel_id).
func (c *Client) OnMessageUpdate(f func(m *discord.Message)) {
c.registerHandler(eventMessageUpdate, messageUpdateHandler(f))
}
type MessageDelete struct {
ChannelID string `json:"channel_id"`
MessageID string `json:"id"`
}
type messageDeleteHandler func(*MessageDelete)
// handle implements the handler interface.
func (h messageDeleteHandler) handle(v interface{}) {
h(v.(*MessageDelete))
}
// OnMessageDelete registers the handler function for the "MESSAGE_DELETE" event.
// Fired when a message is deleted.
func (c *Client) OnMessageDelete(f func(m *MessageDelete)) {
c.registerHandler(eventMessageDelete, messageDeleteHandler(f))
}
type MessageDeleteBulk struct {
GuildID string `json:"guild_id"`
ChannelID string `json:"channel_id"`
IDs []string `json:"ids"`
}
type messageDeleteBulkHandler func(*MessageDeleteBulk)
// handle implements the handler interface.
func (h messageDeleteBulkHandler) handle(v interface{}) {
h(v.(*MessageDeleteBulk))
}
// OnMessageDeleteBulk registers the handler function for the "MESSAGE_DELETE_BULK" event.
// Fired when multiple messages are deleted at once.
func (c *Client) OnMessageDeleteBulk(f func(mdb *MessageDeleteBulk)) {
c.registerHandler(eventMessageDeleteBulk, messageDeleteBulkHandler(f))
}
type MessageAck struct {
ChannelID string `json:"channel_id"`
MessageID string `json:"message_id"`
}
type messageAckHandler func(*MessageAck)
// handle implements the handler interface.
func (h messageAckHandler) handle(v interface{}) {
h(v.(*MessageAck))
}
// OnMessageAck registers the handler function for the "MESSAGE_ACK" event.
func (c *Client) OnMessageAck(f func(ack *MessageAck)) {
c.registerHandler(eventMessageAck, messageAckHandler(f))
}
type MessageReaction struct {
UserID string `json:"user_id"`
GuildID string `json:"guild_id"`
ChannelID string `json:"channel_id"`
MessageID string `json:"message_id"`
Emoji *discord.Emoji `json:"emoji"`
}
type messageReactionAddHandler func(*MessageReaction)
// handle implements the handler interface.
func (h messageReactionAddHandler) handle(v interface{}) {
h(v.(*MessageReaction))
}
// OnMessageReactionAdd registers the handler function for the "MESSAGE_REACTION_ADD" event.
// Fired when a user adds a reaction to a message.
func (c *Client) OnMessageReactionAdd(f func(r *MessageReaction)) {
c.registerHandler(eventMessageReactionAdd, messageReactionAddHandler(f))
}
type messageReactionRemoveHandler func(*MessageReaction)
// handle implements the handler interface.
func (h messageReactionRemoveHandler) handle(v interface{}) {
h(v.(*MessageReaction))
}
// OnMessageReactionRemove registers the handler function for the "MESSAGE_REACTION_REMOVE" event.
// Fired when a user removes a reaction from a message.
func (c *Client) OnMessageReactionRemove(f func(r *MessageReaction)) {
c.registerHandler(eventMessageReactionRemove, messageReactionRemoveHandler(f))
}
type MessageReactionRemoveAll struct {
GuildID string `json:"guild_id"`
ChannelID string `json:"channel_id"`
MessageID string `json:"message_id"`
}
type messageReactionRemoveAllHandler func(*MessageReactionRemoveAll)
// handle implements the handler interface.
func (h messageReactionRemoveAllHandler) handle(v interface{}) {
h(v.(*MessageReactionRemoveAll))
}
// OnMessageReactionRemoveAll registers the handler function for the "MESSAGE_REACTION_REMOVE_ALL" event.
// Fired when a user explicitly removes all reactions from a message.
func (c *Client) OnMessageReactionRemoveAll(f func(r *MessageReactionRemoveAll)) {
c.registerHandler(eventMessageReactionRemoveAll, messageReactionRemoveAllHandler(f))
}
type MessageReactionRemoveEmoji struct {
GuildID string `json:"guild_id"`
ChannelID string `json:"channel_id"`
MessageID string `json:"message_id"`
Emoji *discord.Emoji `json:"emoji"`
}
type messageReactionRemoveEmojiHandler func(*MessageReactionRemoveEmoji)
// handle implements the handler interface.
func (h messageReactionRemoveEmojiHandler) handle(v interface{}) {
h(v.(*MessageReactionRemoveEmoji))
}
// HandleMessageReactionRemoveEmoji registers the handler function for the "MESSAGE_REACTION_REMOVE_ALL" event.
// Fired when a user explicitly removes all reactions from a message.
func (c *Client) OnMessageReactionRemoveEmoji(f func(r *MessageReactionRemoveEmoji)) {
c.registerHandler(eventMessageReactionRemoveEmoji, messageReactionRemoveEmojiHandler(f))
}
type presenceUpdateHandler func(*discord.Presence)
// handle implements the handler interface.
func (h presenceUpdateHandler) handle(v interface{}) {
h(v.(*discord.Presence))
}
// OnPresenceUpdate registers the handler function for the "PRESENCE_UPDATE" event.
// This event is fired when a user's presence is updated for a guild.
// The user object within this event can be partial, the only field which must be sent
// is the id field, everything else is optional. Along with this limitation, no fields
// are required, and the types of the fields are not validated. Your client should expect
// any combination of fields and types within this event.
func (c *Client) OnPresenceUpdate(f func(p *discord.Presence)) {
c.registerHandler(eventPresenceUpdate, presenceUpdateHandler(f))
}
type TypingStart struct {
ChannelID string `json:"channel_id"`
GuildID string `json:"guild_id"`
UserID string `json:"user_id"`
Timestamp int64 `json:"timestamp"`
}
type typingStartHandler func(*TypingStart)
// handle implements the handler interface.
func (h typingStartHandler) handle(v interface{}) {
h(v.(*TypingStart))
}
// OnTypingStart registers the handler function for the "TYPING_START" event.
// Fired when a user starts typing in a channel.
func (c *Client) OnTypingStart(f func(ts *TypingStart)) {
c.registerHandler(eventTypingStart, typingStartHandler(f))
}
type userUpdateHandler func(*discord.User)
// handle implements the handler interface.
func (h userUpdateHandler) handle(v interface{}) {
h(v.(*discord.User))
}
// OnUserUpdate registers the handler function for the "USER_UPDATE" event.
// Fired when properties about the user change.
func (c *Client) OnUserUpdate(f func(u *discord.User)) {
c.registerHandler(eventUserUpdate, userUpdateHandler(f))
}
type voiceStateUpdateHandler func(*voice.StateUpdate)
// handle implements the handler interface.
func (h voiceStateUpdateHandler) handle(v interface{}) {
h(v.(*voice.StateUpdate))
}
// OnVoiceStateUpdate registers the handler function for the "VOICE_STATE_UPDATE" event.
// Fired when someone joins/leaves/moves voice channels.
func (c *Client) OnVoiceStateUpdate(f func(update *voice.StateUpdate)) {
c.registerHandler(eventVoiceStateUpdate, voiceStateUpdateHandler(f))
}
type voiceServerUpdateHandler func(*voice.ServerUpdate)
// handle implements the handler interface.
func (h voiceServerUpdateHandler) handle(v interface{}) {
h(v.(*voice.ServerUpdate))
}
// OnVoiceServerUpdate registers the handler function for the "VOICE_SERVER_UPDATE" event.
// Fired when a guild's voice server is updated. This is Fired when initially connecting to voice,
// and when the current voice instance fails over to a new server.
func (c *Client) OnVoiceServerUpdate(f func(update *voice.ServerUpdate)) {
c.registerHandler(eventVoiceServerUpdate, voiceServerUpdateHandler(f))
}
type WebhooksUpdate struct {
GuildID string `json:"guild_id"`
ChannelID string `json:"channel_id"`
}
type webhooksUpdateHandler func(*WebhooksUpdate)
// handle implements the handler interface.
func (h webhooksUpdateHandler) handle(v interface{}) {
h(v.(*WebhooksUpdate))
}
// OnWebhooksUpdate registers the handler function for the "WEBHOOKS_UPDATE" event.
// Fired when a guild channel's webhook is created, updated, or deleted.
func (c *Client) OnWebhooksUpdate(f func(wu *WebhooksUpdate)) {
c.registerHandler(eventWebhooksUpdate, webhooksUpdateHandler(f))
}