discorb 0.19.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build_version.yml +2 -2
  3. data/.rubocop.yml +12 -75
  4. data/Changelog.md +10 -0
  5. data/Rakefile +482 -454
  6. data/lib/discorb/allowed_mentions.rb +68 -72
  7. data/lib/discorb/app_command/command.rb +466 -398
  8. data/lib/discorb/app_command/common.rb +65 -25
  9. data/lib/discorb/app_command/handler.rb +304 -266
  10. data/lib/discorb/app_command.rb +5 -5
  11. data/lib/discorb/application.rb +198 -197
  12. data/lib/discorb/asset.rb +101 -101
  13. data/lib/discorb/attachment.rb +134 -119
  14. data/lib/discorb/audit_logs.rb +412 -385
  15. data/lib/discorb/automod.rb +279 -269
  16. data/lib/discorb/channel/base.rb +107 -108
  17. data/lib/discorb/channel/category.rb +32 -32
  18. data/lib/discorb/channel/container.rb +44 -44
  19. data/lib/discorb/channel/dm.rb +26 -28
  20. data/lib/discorb/channel/guild.rb +311 -246
  21. data/lib/discorb/channel/stage.rb +156 -140
  22. data/lib/discorb/channel/text.rb +430 -336
  23. data/lib/discorb/channel/thread.rb +374 -325
  24. data/lib/discorb/channel/voice.rb +85 -79
  25. data/lib/discorb/channel.rb +5 -5
  26. data/lib/discorb/client.rb +635 -621
  27. data/lib/discorb/color.rb +178 -182
  28. data/lib/discorb/common.rb +168 -164
  29. data/lib/discorb/components/button.rb +107 -106
  30. data/lib/discorb/components/select_menu.rb +157 -145
  31. data/lib/discorb/components/text_input.rb +103 -106
  32. data/lib/discorb/components.rb +68 -66
  33. data/lib/discorb/dictionary.rb +135 -135
  34. data/lib/discorb/embed.rb +404 -398
  35. data/lib/discorb/emoji.rb +309 -302
  36. data/lib/discorb/emoji_table.rb +16099 -8857
  37. data/lib/discorb/error.rb +131 -131
  38. data/lib/discorb/event.rb +360 -314
  39. data/lib/discorb/event_handler.rb +39 -39
  40. data/lib/discorb/exe/about.rb +17 -17
  41. data/lib/discorb/exe/irb.rb +72 -67
  42. data/lib/discorb/exe/new.rb +323 -315
  43. data/lib/discorb/exe/run.rb +69 -68
  44. data/lib/discorb/exe/setup.rb +57 -55
  45. data/lib/discorb/exe/show.rb +12 -12
  46. data/lib/discorb/extend.rb +25 -45
  47. data/lib/discorb/extension.rb +89 -83
  48. data/lib/discorb/flag.rb +126 -128
  49. data/lib/discorb/gateway.rb +984 -804
  50. data/lib/discorb/gateway_events.rb +670 -638
  51. data/lib/discorb/gateway_requests.rb +45 -48
  52. data/lib/discorb/guild.rb +2115 -1626
  53. data/lib/discorb/guild_template.rb +280 -241
  54. data/lib/discorb/http.rb +247 -232
  55. data/lib/discorb/image.rb +42 -42
  56. data/lib/discorb/integration.rb +169 -161
  57. data/lib/discorb/intents.rb +161 -163
  58. data/lib/discorb/interaction/autocomplete.rb +76 -62
  59. data/lib/discorb/interaction/command.rb +279 -224
  60. data/lib/discorb/interaction/components.rb +114 -104
  61. data/lib/discorb/interaction/modal.rb +36 -32
  62. data/lib/discorb/interaction/response.rb +379 -336
  63. data/lib/discorb/interaction/root.rb +271 -257
  64. data/lib/discorb/interaction.rb +5 -5
  65. data/lib/discorb/invite.rb +154 -153
  66. data/lib/discorb/member.rb +344 -311
  67. data/lib/discorb/message.rb +615 -544
  68. data/lib/discorb/message_meta.rb +197 -186
  69. data/lib/discorb/modules.rb +371 -290
  70. data/lib/discorb/permission.rb +305 -291
  71. data/lib/discorb/presence.rb +352 -346
  72. data/lib/discorb/rate_limit.rb +81 -76
  73. data/lib/discorb/reaction.rb +55 -54
  74. data/lib/discorb/role.rb +272 -240
  75. data/lib/discorb/shard.rb +76 -74
  76. data/lib/discorb/sticker.rb +193 -171
  77. data/lib/discorb/user.rb +205 -188
  78. data/lib/discorb/utils/colored_puts.rb +16 -16
  79. data/lib/discorb/utils.rb +12 -16
  80. data/lib/discorb/voice_state.rb +305 -281
  81. data/lib/discorb/webhook.rb +537 -507
  82. data/lib/discorb.rb +62 -56
  83. data/sig/discorb/application.rbs +2 -0
  84. data/sig/discorb/automod.rbs +10 -1
  85. data/sig/discorb/guild.rbs +2 -0
  86. data/sig/discorb/message.rbs +2 -0
  87. data/sig/discorb/user.rbs +22 -20
  88. metadata +2 -2
@@ -1,638 +1,670 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- module Gateway
5
- #
6
- # Represents an event.
7
- # @abstract
8
- #
9
- class GatewayEvent
10
- #
11
- # Initializes a new instance of the GatewayEvent class.
12
- # @private
13
- #
14
- # @param [Hash] data The data of the event.
15
- #
16
- def initialize(data)
17
- @data = data
18
- end
19
-
20
- def inspect
21
- "#<#{self.class}>"
22
- end
23
- end
24
-
25
- #
26
- # Represents a reaction event.
27
- #
28
- class ReactionEvent < GatewayEvent
29
- # @return [Hash] The raw data of the event.
30
- attr_reader :data
31
- # @return [Discorb::Snowflake] The ID of the user who reacted.
32
- attr_reader :user_id
33
- alias member_id user_id
34
- # @return [Discorb::Snowflake] The ID of the channel the message was sent in.
35
- attr_reader :channel_id
36
- # @return [Discorb::Snowflake] The ID of the message.
37
- attr_reader :message_id
38
- # @return [Discorb::Snowflake] The ID of the guild the message was sent in.
39
- attr_reader :guild_id
40
- # @macro client_cache
41
- # @return [Discorb::User, Discorb::Member] The user who reacted.
42
- attr_reader :user
43
- alias member user
44
- # @macro client_cache
45
- # @return [Discorb::Channel] The channel the message was sent in.
46
- attr_reader :channel
47
- # @macro client_cache
48
- # @return [Discorb::Guild] The guild the message was sent in.
49
- attr_reader :guild
50
- # @macro client_cache
51
- # @return [Discorb::Message] The message the reaction was sent in.
52
- attr_reader :message
53
- # @return [Discorb::UnicodeEmoji, Discorb::PartialEmoji] The emoji that was reacted with.
54
- attr_reader :emoji
55
-
56
- #
57
- # Initializes a new instance of the ReactionEvent class.
58
- # @private
59
- #
60
- # @param [Discorb::Client] client The client that instantiated the object.
61
- # @param [Hash] data The data of the event.
62
- #
63
- def initialize(client, data)
64
- @client = client
65
- @data = data
66
- if data.key?(:user_id)
67
- @user_id = Snowflake.new(data[:user_id])
68
- else
69
- @member_data = data[:member]
70
- end
71
- @channel_id = Snowflake.new(data[:channel_id])
72
- @message_id = Snowflake.new(data[:message_id])
73
- @guild_id = Snowflake.new(data[:guild_id])
74
- @guild = client.guilds[data[:guild_id]]
75
- @channel = client.channels[data[:channel_id]] unless @guild.nil?
76
-
77
- @user = client.users[data[:user_id]]
78
-
79
- unless @guild.nil?
80
- @user = if data.key?(:member)
81
- @guild.members[data[:member][:user][:id]] ||
82
- Member.new(
83
- @client,
84
- @guild_id,
85
- data[:member][:user],
86
- data[:member]
87
- )
88
- else
89
- @guild.members[data[:user_id]]
90
- end || @user
91
- end
92
-
93
- @message = client.messages[data[:message_id]]
94
- @emoji = data[:emoji][:id].nil? ? UnicodeEmoji.new(data[:emoji][:name]) : PartialEmoji.new(data[:emoji])
95
- end
96
-
97
- # Fetch the message.
98
- # If message is cached, it will be returned.
99
- # @async
100
- #
101
- # @param [Boolean] force Whether to force fetching the message.
102
- #
103
- # @return [Async::Task<Discorb::Message>] The message.
104
- def fetch_message(force: false)
105
- Async do
106
- next @message if !force && @message
107
-
108
- @message = @channel.fetch_message(@message_id).wait
109
- end
110
- end
111
- end
112
-
113
- #
114
- # Represents a `INTEGRATION_DELETE` event.
115
- #
116
- class IntegrationDeleteEvent < GatewayEvent
117
- # @return [Discorb::Snowflake] The ID of the integration.
118
- attr_reader :id
119
-
120
- # @!attribute [r] guild
121
- # @macro client_cache
122
- # @return [Discorb::Guild] The guild of the integration.
123
- # @!attribute [r] user
124
- # @macro client_cache
125
- # @return [Discorb::User] The user associated with the integration.
126
-
127
- #
128
- # Initialize a new instance of the IntegrationDeleteEvent class.
129
- # @private
130
- #
131
- #
132
- # @param [Hash] data The data of the event.
133
- #
134
- #
135
- def initialize(_client, data)
136
- @id = Snowflake.new(data[:id])
137
- @guild_id = data[:guild_id]
138
- @user_id = data[:application_id]
139
- end
140
-
141
- def guild
142
- @client.guilds[@guild_id]
143
- end
144
-
145
- def user
146
- @client.users[@user_id]
147
- end
148
- end
149
-
150
- #
151
- # Represents a `MESSAGE_REACTION_REMOVE_ALL` event.
152
- #
153
- class ReactionRemoveAllEvent < GatewayEvent
154
- # @return [Discorb::Snowflake] The ID of the channel the message was sent in.
155
- attr_reader :channel_id
156
- # @return [Discorb::Snowflake] The ID of the message.
157
- attr_reader :message_id
158
- # @return [Discorb::Snowflake] The ID of the guild the message was sent in.
159
- attr_reader :guild_id
160
- # @macro client_cache
161
- # @return [Discorb::Channel] The channel the message was sent in.
162
- attr_reader :channel
163
- # @macro client_cache
164
- # @return [Discorb::Guild] The guild the message was sent in.
165
- attr_reader :guild
166
- # @macro client_cache
167
- # @return [Discorb::Message] The message the reaction was sent in.
168
- attr_reader :message
169
-
170
- #
171
- # Initialize a new instance of the ReactionRemoveAllEvent class.
172
- # @private
173
- #
174
- # @param [Discorb::Client] client The client that instantiated the object.
175
- # @param [Hash] data The data of the event.
176
- #
177
- def initialize(client, data)
178
- @client = client
179
- @data = data
180
- @guild_id = Snowflake.new(data[:guild_id])
181
- @channel_id = Snowflake.new(data[:channel_id])
182
- @message_id = Snowflake.new(data[:message_id])
183
- @guild = client.guilds[data[:guild_id]]
184
- @channel = client.channels[data[:channel_id]]
185
- @message = client.messages[data[:message_id]]
186
- end
187
-
188
- # Fetch the message.
189
- # If message is cached, it will be returned.
190
- # @async
191
- #
192
- # @param [Boolean] force Whether to force fetching the message.
193
- #
194
- # @return [Async::Task<Discorb::Message>] The message.
195
- def fetch_message(force: false)
196
- Async do
197
- next @message if !force && @message
198
-
199
- @message = @channel.fetch_message(@message_id).wait
200
- end
201
- end
202
- end
203
-
204
- #
205
- # Represents a `MESSAGE_REACTION_REMOVE_EMOJI` event.
206
- #
207
- class ReactionRemoveEmojiEvent < GatewayEvent
208
- # @return [Discorb::Snowflake] The ID of the channel the message was sent in.
209
- attr_reader :channel_id
210
- # @return [Discorb::Snowflake] The ID of the message.
211
- attr_reader :message_id
212
- # @return [Discorb::Snowflake] The ID of the guild the message was sent in.
213
- attr_reader :guild_id
214
- # @macro client_cache
215
- # @return [Discorb::Channel] The channel the message was sent in.
216
- attr_reader :channel
217
- # @macro client_cache
218
- # @return [Discorb::Guild] The guild the message was sent in.
219
- attr_reader :guild
220
- # @macro client_cache
221
- # @return [Discorb::Message] The message the reaction was sent in.
222
- attr_reader :message
223
- # @return [Discorb::UnicodeEmoji, Discorb::PartialEmoji] The emoji that was reacted with.
224
- attr_reader :emoji
225
-
226
- #
227
- # Initialize a new instance of the ReactionRemoveEmojiEvent class.
228
- # @private
229
- #
230
- # @param [Discorb::Client] client The client that instantiated the object.
231
- # @param [Hash] data The data of the event.
232
- #
233
- def initialize(client, data)
234
- @client = client
235
- @data = data
236
- @guild_id = Snowflake.new(data[:guild_id])
237
- @channel_id = Snowflake.new(data[:channel_id])
238
- @message_id = Snowflake.new(data[:message_id])
239
- @guild = client.guilds[data[:guild_id]]
240
- @channel = client.channels[data[:channel_id]]
241
- @message = client.messages[data[:message_id]]
242
- @emoji = data[:emoji][:id].nil? ? DiscordEmoji.new(data[:emoji][:name]) : PartialEmoji.new(data[:emoji])
243
- end
244
-
245
- # Fetch the message.
246
- # If message is cached, it will be returned.
247
- # @async
248
- #
249
- # @param [Boolean] force Whether to force fetching the message.
250
- #
251
- # @return [Async::Task<Discorb::Message>] The message.
252
- def fetch_message(force: false)
253
- Async do
254
- next @message if !force && @message
255
-
256
- @message = @channel.fetch_message(@message_id).wait
257
- end
258
- end
259
- end
260
-
261
- #
262
- # Represents a `GUILD_SCHEDULED_EVENT_USER_ADD` and `GUILD_SCHEDULED_EVENT_USER_REMOVE` event.
263
- #
264
- class ScheduledEventUserEvent < GatewayEvent
265
- # @return [Discorb::User] The user that triggered the event.
266
- attr_reader :user
267
- # @return [Discorb::Guild] The guild the event was triggered in.
268
- attr_reader :guild
269
- # @return [Discorb::ScheduledEvent] The scheduled event.
270
- attr_reader :scheduled_event
271
-
272
- #
273
- # Initialize a new instance of the ScheduledEventUserEvent class.
274
- # @private
275
- #
276
- # @param [Discorb::Client] client The client that instantiated the object.
277
- # @param [Hash] data The data of the event.
278
- #
279
- def initialize(client, data)
280
- @client = client
281
- @scheduled_event_id = Snowflake.new(data[:scheduled_event_id])
282
- @user_id = Snowflake.new(data[:user_id])
283
- @guild_id = Snowflake.new(data[:guild_id])
284
- @guild = client.guilds[data[:guild_id]]
285
- @scheduled_event = @guild.scheduled_events[@scheduled_event_id]
286
- @user = client.users[data[:user_id]]
287
- end
288
- end
289
-
290
- #
291
- # Represents a `MESSAGE_UPDATE` event.
292
- #
293
- class MessageUpdateEvent < GatewayEvent
294
- # @return [Discorb::Message] The message before update.
295
- attr_reader :before
296
- # @return [Discorb::Message] The message after update.
297
- attr_reader :after
298
- # @return [Discorb::Snowflake] The ID of the message.
299
- attr_reader :id
300
- # @return [Discorb::Snowflake] The ID of the channel the message was sent in.
301
- attr_reader :channel_id
302
- # @return [Discorb::Snowflake] The ID of the guild the message was sent in.
303
- attr_reader :guild_id
304
- # @return [String] The new content of the message.
305
- attr_reader :content
306
- # @return [Time] The time the message was edited.
307
- attr_reader :timestamp
308
- # @return [Boolean] Whether the message pings @everyone.
309
- attr_reader :mention_everyone
310
- # @macro client_cache
311
- # @return [Array<Discorb::Role>] The roles mentioned in the message.
312
- attr_reader :mention_roles
313
- # @return [Array<Discorb::Attachment>] The attachments in the message.
314
- attr_reader :attachments
315
- # @return [Array<Discorb::Embed>] The embeds in the message.
316
- attr_reader :embeds
317
-
318
- # @!attribute [r] channel
319
- # @macro client_cache
320
- # @return [Discorb::Channel] The channel the message was sent in.
321
- # @!attribute [r] guild
322
- # @macro client_cache
323
- # @return [Discorb::Guild] The guild the message was sent in.
324
-
325
- def initialize(client, data, before, after)
326
- @client = client
327
- @data = data
328
- @before = before
329
- @after = after
330
- @id = Snowflake.new(data[:id])
331
- @channel_id = Snowflake.new(data[:channel_id])
332
- @guild_id = Snowflake.new(data[:guild_id]) if data.key?(:guild_id)
333
- @content = data[:content]
334
- @timestamp = Time.iso8601(data[:edited_timestamp])
335
- @mention_everyone = data[:mention_everyone]
336
- @mention_roles = data[:mention_roles].map { |r| guild.roles[r] } if data.key?(:mention_roles)
337
- @attachments = data[:attachments].map { |a| Attachment.from_hash(a) } if data.key?(:attachments)
338
- @embeds = data[:embeds] ? data[:embeds].map { |e| Embed.from_hash(e) } : [] if data.key?(:embeds)
339
- end
340
-
341
- def channel
342
- @client.channels[@channel_id]
343
- end
344
-
345
- def guild
346
- @client.guilds[@guild_id]
347
- end
348
-
349
- # Fetch the message.
350
- # @async
351
- #
352
- # @return [Async::Task<Discorb::Message>] The message.
353
- def fetch_message
354
- Async do
355
- channel.fetch_message(@id).wait
356
- end
357
- end
358
- end
359
-
360
- #
361
- # Represents a message but it has only ID.
362
- #
363
- class UnknownDeleteBulkMessage < GatewayEvent
364
- # @return [Discorb::Snowflake] The ID of the message.
365
- attr_reader :id
366
-
367
- # @!attribute [r] channel
368
- # @macro client_cache
369
- # @return [Discorb::Channel] The channel the message was sent in.
370
- # @!attribute [r] guild
371
- # @macro client_cache
372
- # @return [Discorb::Guild] The guild the message was sent in.
373
-
374
- #
375
- # Initialize a new instance of the UnknownDeleteBulkMessage class.
376
- # @private
377
- #
378
- # @param [Discorb::Client] client The client that instantiated the object.
379
- # @param [Hash] data The data of the event.
380
- #
381
- def initialize(client, id, data)
382
- @client = client
383
- @id = Snowflake.new(id)
384
- @data = data
385
- @channel_id = Snowflake.new(data[:channel_id])
386
- @guild_id = Snowflake.new(data[:guild_id]) if data.key?(:guild_id)
387
- end
388
-
389
- def channel
390
- @client.channels[@channel_id]
391
- end
392
-
393
- def guild
394
- @client.guilds[@guild_id]
395
- end
396
- end
397
-
398
- #
399
- # Represents a `INVITE_DELETE` event.
400
- #
401
- class InviteDeleteEvent < GatewayEvent
402
- # @return [String] The invite code.
403
- attr_reader :code
404
-
405
- # @!attribute [r] channel
406
- # @macro client_cache
407
- # @return [Discorb::Channel] The channel the message was sent in.
408
- # @!attribute [r] guild
409
- # @macro client_cache
410
- # @return [Discorb::Guild] The guild the message was sent in.
411
-
412
- #
413
- # Initialize a new instance of the InviteDeleteEvent class.
414
- # @private
415
- #
416
- # @param [Discorb::Client] client The client that instantiated the object.
417
- # @param [Hash] data The data of the event.
418
- #
419
- def initialize(client, data)
420
- @client = client
421
- @data = data
422
- @channel_id = Snowflake.new(data[:channel])
423
- @guild_id = Snowflake.new(data[:guild_id])
424
- @code = data[:code]
425
- end
426
-
427
- def channel
428
- @client.channels[@channel_id]
429
- end
430
-
431
- def guild
432
- @client.guilds[@guild_id]
433
- end
434
- end
435
-
436
- #
437
- # Represents a `TYPING_START` event.
438
- #
439
- class TypingStartEvent < GatewayEvent
440
- # @return [Discorb::Snowflake] The ID of the channel the user is typing in.
441
- attr_reader :user_id
442
-
443
- # @!attribute [r] channel
444
- # @macro client_cache
445
- # @return [Discorb::Channel] The channel the user is typing in.
446
- # @!attribute [r] guild
447
- # @macro client_cache
448
- # @return [Discorb::Guild] The guild the user is typing in.
449
- # @!attribute [r] user
450
- # @macro client_cache
451
- # @return [Discorb::User, Discorb::Member] The user that is typing.
452
-
453
- #
454
- # Initialize a new instance of the TypingStartEvent class.
455
- # @private
456
- #
457
- # @param [Discorb::Client] client The client that instantiated the object.
458
- # @param [Hash] data The data of the event.
459
- #
460
- def initialize(client, data)
461
- @client = client
462
- @data = data
463
- @channel_id = Snowflake.new(data[:channel_id])
464
- @guild_id = Snowflake.new(data[:guild_id]) if data.key?(:guild_id)
465
- @user_id = Snowflake.new(data[:user_id])
466
- @timestamp = Time.at(data[:timestamp])
467
- if guild
468
- @member = guild.members[@user_id] || Member.new(
469
- @client,
470
- @guild_id,
471
- @client.users[@user_id].instance_variable_get(:@data),
472
- data[:member]
473
- )
474
- end
475
- end
476
-
477
- def user
478
- @member || guild&.members&.[](@user_id) || @client.users[@user_id]
479
- end
480
-
481
- alias member user
482
-
483
- def channel
484
- @client.channels[@channel_id]
485
- end
486
-
487
- def guild
488
- @client.guilds[@guild_id]
489
- end
490
- end
491
-
492
- #
493
- # Represents a message pin event.
494
- #
495
- class MessagePinEvent < GatewayEvent
496
- # @return [Discorb::Message] The message that was pinned.
497
- attr_reader :message
498
- # @return [:pinned, :unpinned] The type of event.
499
- attr_reader :type
500
-
501
- # @!attribute [r] pinned?
502
- # @return [Boolean] Whether the message was pinned.
503
- # @!attribute [r] unpinned?
504
- # @return [Boolean] Whether the message was unpinned.
505
-
506
- def initialize(client, data, message)
507
- @client = client
508
- @data = data
509
- @message = message
510
- @type = if message.nil?
511
- :unknown
512
- elsif @message.pinned?
513
- :pinned
514
- else
515
- :unpinned
516
- end
517
- end
518
-
519
- def pinned?
520
- @type == :pinned
521
- end
522
-
523
- def unpinned?
524
- @type == :unpinned
525
- end
526
- end
527
-
528
- #
529
- # Represents a `WEBHOOKS_UPDATE` event.
530
- #
531
- class WebhooksUpdateEvent < GatewayEvent
532
- # @!attribute [r] channel
533
- # @macro client_cache
534
- # @return [Discorb::Channel] The channel where the webhook was updated.
535
- # @!attribute [r] guild
536
- # @macro client_cache
537
- # @return [Discorb::Guild] The guild where the webhook was updated.
538
-
539
- #
540
- # Initialize a new instance of the WebhooksUpdateEvent class.
541
- # @private
542
- #
543
- # @param [Discorb::Client] client The client that instantiated the object.
544
- # @param [Hash] data The data of the event.
545
- #
546
- def initialize(client, data)
547
- @client = client
548
- @data = data
549
- @guild_id = Snowflake.new(data[:guild_id])
550
- @channel_id = Snowflake.new(data[:channel_id])
551
- end
552
-
553
- def guild
554
- @client.guilds[@guild_id]
555
- end
556
-
557
- def channel
558
- @client.channels[@channel_id]
559
- end
560
- end
561
-
562
- #
563
- # Represents a `AUTO_MODERATION_ACTION_EXECUTION` event.
564
- #
565
- class AutoModerationActionExecutionEvent < GatewayEvent
566
- # @return [Discorb::Snowflake] The id of the rule.
567
- attr_reader :rule_id
568
-
569
- # @return [Symbol] The type of action that was executed.
570
- attr_reader :rule_trigger_type
571
-
572
- # @return [Discorb::Snowflake] The id of the message that triggered the action.
573
- # @return [nil] If the message was deleted.
574
- attr_reader :message_id
575
-
576
- # @return [Discorb::Snowflake] The id of the system message that was sent.
577
- # @return [nil] If the system message channel was not set.
578
- attr_reader :alert_system_message_id
579
-
580
- # @return [String] The content of the message that was sent.
581
- attr_reader :content
582
-
583
- # @return [String] The keyword that triggered the action.
584
- # @return [nil] If the action was not triggered by a keyword.
585
- attr_reader :matched_keyword
586
-
587
- # @return [String] The content that triggered the action.
588
- # @return [nil] If the action was not triggered by a keyword.
589
- attr_reader :matched_content
590
-
591
- # @return [Discorb::AutoModRule::Action] The action that was executed.
592
- attr_reader :action
593
-
594
- #
595
- # Initialize a new instance of the AutoModerationActionExecutionEvent class.
596
- # @private
597
- #
598
- # @param [Discorb::Client] client The client that instantiated the object.
599
- # @param [Hash] data The data of the event.
600
- #
601
- def initialize(client, data)
602
- @client = client
603
- @data = data
604
- @rule_id = Snowflake.new(data[:rule_id])
605
- @rule_trigger_type = Discorb::AutoModRule::TRIGGER_TYPES[data[:rule_trigger_type]]
606
- @action = Discorb::AutoModRule::Action.new(data[:action])
607
- @user_id = Snowflake.new(data[:user_id])
608
- @guild_id = Snowflake.new(data[:guild_id])
609
- @channel_id = data[:channel_id] && Snowflake.new(data[:channel_id])
610
- @message_id = data[:message_id] && Snowflake.new(data[:message_id])
611
- @alert_system_message_id = data[:alert_system_message_id] && Snowflake.new(data[:alert_system_message_id])
612
- @content = data[:content]
613
- @matched_keyword = data[:matched_keyword]
614
- @matched_content = data[:matched_content]
615
- end
616
-
617
- # @!attribute [r] guild
618
- # @return [Discorb::Guild] The guild where the rule was executed.
619
- def guild
620
- @client.guilds[@guild_id]
621
- end
622
-
623
- # @!attribute [r] channel
624
- # @return [Discorb::Channel] The channel where the rule was executed.
625
- def channel
626
- @client.channels[@channel_id]
627
- end
628
-
629
- # @!attribute [r] member
630
- # @return [Discorb::Member] The member that triggered the action.
631
- def member
632
- guild.members[@user_id]
633
- end
634
-
635
- alias user member
636
- end
637
- end
638
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ module Gateway
5
+ #
6
+ # Represents an event.
7
+ # @abstract
8
+ #
9
+ class GatewayEvent
10
+ #
11
+ # Initializes a new instance of the GatewayEvent class.
12
+ # @private
13
+ #
14
+ # @param [Hash] data The data of the event.
15
+ #
16
+ def initialize(data)
17
+ @data = data
18
+ end
19
+
20
+ def inspect
21
+ "#<#{self.class}>"
22
+ end
23
+ end
24
+
25
+ #
26
+ # Represents a reaction event.
27
+ #
28
+ class ReactionEvent < GatewayEvent
29
+ # @return [Hash] The raw data of the event.
30
+ attr_reader :data
31
+ # @return [Discorb::Snowflake] The ID of the user who reacted.
32
+ attr_reader :user_id
33
+ alias member_id user_id
34
+ # @return [Discorb::Snowflake] The ID of the channel the message was sent in.
35
+ attr_reader :channel_id
36
+ # @return [Discorb::Snowflake] The ID of the message.
37
+ attr_reader :message_id
38
+ # @return [Discorb::Snowflake] The ID of the guild the message was sent in.
39
+ attr_reader :guild_id
40
+ # @macro client_cache
41
+ # @return [Discorb::User, Discorb::Member] The user who reacted.
42
+ attr_reader :user
43
+ alias member user
44
+ # @macro client_cache
45
+ # @return [Discorb::Channel] The channel the message was sent in.
46
+ attr_reader :channel
47
+ # @macro client_cache
48
+ # @return [Discorb::Guild] The guild the message was sent in.
49
+ attr_reader :guild
50
+ # @macro client_cache
51
+ # @return [Discorb::Message] The message the reaction was sent in.
52
+ attr_reader :message
53
+ # @return [Discorb::UnicodeEmoji, Discorb::PartialEmoji] The emoji that was reacted with.
54
+ attr_reader :emoji
55
+
56
+ #
57
+ # Initializes a new instance of the ReactionEvent class.
58
+ # @private
59
+ #
60
+ # @param [Discorb::Client] client The client that instantiated the object.
61
+ # @param [Hash] data The data of the event.
62
+ #
63
+ def initialize(client, data)
64
+ @client = client
65
+ @data = data
66
+ if data.key?(:user_id)
67
+ @user_id = Snowflake.new(data[:user_id])
68
+ else
69
+ @member_data = data[:member]
70
+ end
71
+ @channel_id = Snowflake.new(data[:channel_id])
72
+ @message_id = Snowflake.new(data[:message_id])
73
+ @guild_id = Snowflake.new(data[:guild_id])
74
+ @guild = client.guilds[data[:guild_id]]
75
+ @channel = client.channels[data[:channel_id]] unless @guild.nil?
76
+
77
+ @user = client.users[data[:user_id]]
78
+
79
+ unless @guild.nil?
80
+ @user =
81
+ if data.key?(:member)
82
+ @guild.members[data[:member][:user][:id]] ||
83
+ Member.new(
84
+ @client,
85
+ @guild_id,
86
+ data[:member][:user],
87
+ data[:member]
88
+ )
89
+ else
90
+ @guild.members[data[:user_id]]
91
+ end || @user
92
+ end
93
+
94
+ @message = client.messages[data[:message_id]]
95
+ @emoji =
96
+ (
97
+ if data[:emoji][:id].nil?
98
+ UnicodeEmoji.new(data[:emoji][:name])
99
+ else
100
+ PartialEmoji.new(data[:emoji])
101
+ end
102
+ )
103
+ end
104
+
105
+ # Fetch the message.
106
+ # If message is cached, it will be returned.
107
+ # @async
108
+ #
109
+ # @param [Boolean] force Whether to force fetching the message.
110
+ #
111
+ # @return [Async::Task<Discorb::Message>] The message.
112
+ def fetch_message(force: false)
113
+ Async do
114
+ next @message if !force && @message
115
+
116
+ @message = @channel.fetch_message(@message_id).wait
117
+ end
118
+ end
119
+ end
120
+
121
+ #
122
+ # Represents a `INTEGRATION_DELETE` event.
123
+ #
124
+ class IntegrationDeleteEvent < GatewayEvent
125
+ # @return [Discorb::Snowflake] The ID of the integration.
126
+ attr_reader :id
127
+
128
+ # @!attribute [r] guild
129
+ # @macro client_cache
130
+ # @return [Discorb::Guild] The guild of the integration.
131
+ # @!attribute [r] user
132
+ # @macro client_cache
133
+ # @return [Discorb::User] The user associated with the integration.
134
+
135
+ #
136
+ # Initialize a new instance of the IntegrationDeleteEvent class.
137
+ # @private
138
+ #
139
+ #
140
+ # @param [Hash] data The data of the event.
141
+ #
142
+ #
143
+ def initialize(_client, data)
144
+ @id = Snowflake.new(data[:id])
145
+ @guild_id = data[:guild_id]
146
+ @user_id = data[:application_id]
147
+ end
148
+
149
+ def guild
150
+ @client.guilds[@guild_id]
151
+ end
152
+
153
+ def user
154
+ @client.users[@user_id]
155
+ end
156
+ end
157
+
158
+ #
159
+ # Represents a `MESSAGE_REACTION_REMOVE_ALL` event.
160
+ #
161
+ class ReactionRemoveAllEvent < GatewayEvent
162
+ # @return [Discorb::Snowflake] The ID of the channel the message was sent in.
163
+ attr_reader :channel_id
164
+ # @return [Discorb::Snowflake] The ID of the message.
165
+ attr_reader :message_id
166
+ # @return [Discorb::Snowflake] The ID of the guild the message was sent in.
167
+ attr_reader :guild_id
168
+ # @macro client_cache
169
+ # @return [Discorb::Channel] The channel the message was sent in.
170
+ attr_reader :channel
171
+ # @macro client_cache
172
+ # @return [Discorb::Guild] The guild the message was sent in.
173
+ attr_reader :guild
174
+ # @macro client_cache
175
+ # @return [Discorb::Message] The message the reaction was sent in.
176
+ attr_reader :message
177
+
178
+ #
179
+ # Initialize a new instance of the ReactionRemoveAllEvent class.
180
+ # @private
181
+ #
182
+ # @param [Discorb::Client] client The client that instantiated the object.
183
+ # @param [Hash] data The data of the event.
184
+ #
185
+ def initialize(client, data)
186
+ @client = client
187
+ @data = data
188
+ @guild_id = Snowflake.new(data[:guild_id])
189
+ @channel_id = Snowflake.new(data[:channel_id])
190
+ @message_id = Snowflake.new(data[:message_id])
191
+ @guild = client.guilds[data[:guild_id]]
192
+ @channel = client.channels[data[:channel_id]]
193
+ @message = client.messages[data[:message_id]]
194
+ end
195
+
196
+ # Fetch the message.
197
+ # If message is cached, it will be returned.
198
+ # @async
199
+ #
200
+ # @param [Boolean] force Whether to force fetching the message.
201
+ #
202
+ # @return [Async::Task<Discorb::Message>] The message.
203
+ def fetch_message(force: false)
204
+ Async do
205
+ next @message if !force && @message
206
+
207
+ @message = @channel.fetch_message(@message_id).wait
208
+ end
209
+ end
210
+ end
211
+
212
+ #
213
+ # Represents a `MESSAGE_REACTION_REMOVE_EMOJI` event.
214
+ #
215
+ class ReactionRemoveEmojiEvent < GatewayEvent
216
+ # @return [Discorb::Snowflake] The ID of the channel the message was sent in.
217
+ attr_reader :channel_id
218
+ # @return [Discorb::Snowflake] The ID of the message.
219
+ attr_reader :message_id
220
+ # @return [Discorb::Snowflake] The ID of the guild the message was sent in.
221
+ attr_reader :guild_id
222
+ # @macro client_cache
223
+ # @return [Discorb::Channel] The channel the message was sent in.
224
+ attr_reader :channel
225
+ # @macro client_cache
226
+ # @return [Discorb::Guild] The guild the message was sent in.
227
+ attr_reader :guild
228
+ # @macro client_cache
229
+ # @return [Discorb::Message] The message the reaction was sent in.
230
+ attr_reader :message
231
+ # @return [Discorb::UnicodeEmoji, Discorb::PartialEmoji] The emoji that was reacted with.
232
+ attr_reader :emoji
233
+
234
+ #
235
+ # Initialize a new instance of the ReactionRemoveEmojiEvent class.
236
+ # @private
237
+ #
238
+ # @param [Discorb::Client] client The client that instantiated the object.
239
+ # @param [Hash] data The data of the event.
240
+ #
241
+ def initialize(client, data)
242
+ @client = client
243
+ @data = data
244
+ @guild_id = Snowflake.new(data[:guild_id])
245
+ @channel_id = Snowflake.new(data[:channel_id])
246
+ @message_id = Snowflake.new(data[:message_id])
247
+ @guild = client.guilds[data[:guild_id]]
248
+ @channel = client.channels[data[:channel_id]]
249
+ @message = client.messages[data[:message_id]]
250
+ @emoji =
251
+ (
252
+ if data[:emoji][:id].nil?
253
+ DiscordEmoji.new(data[:emoji][:name])
254
+ else
255
+ PartialEmoji.new(data[:emoji])
256
+ end
257
+ )
258
+ end
259
+
260
+ # Fetch the message.
261
+ # If message is cached, it will be returned.
262
+ # @async
263
+ #
264
+ # @param [Boolean] force Whether to force fetching the message.
265
+ #
266
+ # @return [Async::Task<Discorb::Message>] The message.
267
+ def fetch_message(force: false)
268
+ Async do
269
+ next @message if !force && @message
270
+
271
+ @message = @channel.fetch_message(@message_id).wait
272
+ end
273
+ end
274
+ end
275
+
276
+ #
277
+ # Represents a `GUILD_SCHEDULED_EVENT_USER_ADD` and `GUILD_SCHEDULED_EVENT_USER_REMOVE` event.
278
+ #
279
+ class ScheduledEventUserEvent < GatewayEvent
280
+ # @return [Discorb::User] The user that triggered the event.
281
+ attr_reader :user
282
+ # @return [Discorb::Guild] The guild the event was triggered in.
283
+ attr_reader :guild
284
+ # @return [Discorb::ScheduledEvent] The scheduled event.
285
+ attr_reader :scheduled_event
286
+
287
+ #
288
+ # Initialize a new instance of the ScheduledEventUserEvent class.
289
+ # @private
290
+ #
291
+ # @param [Discorb::Client] client The client that instantiated the object.
292
+ # @param [Hash] data The data of the event.
293
+ #
294
+ def initialize(client, data)
295
+ @client = client
296
+ @scheduled_event_id = Snowflake.new(data[:scheduled_event_id])
297
+ @user_id = Snowflake.new(data[:user_id])
298
+ @guild_id = Snowflake.new(data[:guild_id])
299
+ @guild = client.guilds[data[:guild_id]]
300
+ @scheduled_event = @guild.scheduled_events[@scheduled_event_id]
301
+ @user = client.users[data[:user_id]]
302
+ end
303
+ end
304
+
305
+ #
306
+ # Represents a `MESSAGE_UPDATE` event.
307
+ #
308
+ class MessageUpdateEvent < GatewayEvent
309
+ # @return [Discorb::Message] The message before update.
310
+ attr_reader :before
311
+ # @return [Discorb::Message] The message after update.
312
+ attr_reader :after
313
+ # @return [Discorb::Snowflake] The ID of the message.
314
+ attr_reader :id
315
+ # @return [Discorb::Snowflake] The ID of the channel the message was sent in.
316
+ attr_reader :channel_id
317
+ # @return [Discorb::Snowflake] The ID of the guild the message was sent in.
318
+ attr_reader :guild_id
319
+ # @return [String] The new content of the message.
320
+ attr_reader :content
321
+ # @return [Time] The time the message was edited.
322
+ attr_reader :timestamp
323
+ # @return [Boolean] Whether the message pings @everyone.
324
+ attr_reader :mention_everyone
325
+ # @macro client_cache
326
+ # @return [Array<Discorb::Role>] The roles mentioned in the message.
327
+ attr_reader :mention_roles
328
+ # @return [Array<Discorb::Attachment>] The attachments in the message.
329
+ attr_reader :attachments
330
+ # @return [Array<Discorb::Embed>] The embeds in the message.
331
+ attr_reader :embeds
332
+
333
+ # @!attribute [r] channel
334
+ # @macro client_cache
335
+ # @return [Discorb::Channel] The channel the message was sent in.
336
+ # @!attribute [r] guild
337
+ # @macro client_cache
338
+ # @return [Discorb::Guild] The guild the message was sent in.
339
+
340
+ def initialize(client, data, before, after)
341
+ @client = client
342
+ @data = data
343
+ @before = before
344
+ @after = after
345
+ @id = Snowflake.new(data[:id])
346
+ @channel_id = Snowflake.new(data[:channel_id])
347
+ @guild_id = Snowflake.new(data[:guild_id]) if data.key?(:guild_id)
348
+ @content = data[:content]
349
+ @timestamp = Time.iso8601(data[:edited_timestamp])
350
+ @mention_everyone = data[:mention_everyone]
351
+ @mention_roles =
352
+ data[:mention_roles].map { |r| guild.roles[r] } if data.key?(
353
+ :mention_roles
354
+ )
355
+ @attachments =
356
+ data[:attachments].map { |a| Attachment.from_hash(a) } if data.key?(
357
+ :attachments
358
+ )
359
+ @embeds =
360
+ (
361
+ if data[:embeds]
362
+ data[:embeds].map { |e| Embed.from_hash(e) }
363
+ else
364
+ []
365
+ end
366
+ ) if data.key?(:embeds)
367
+ end
368
+
369
+ def channel
370
+ @client.channels[@channel_id]
371
+ end
372
+
373
+ def guild
374
+ @client.guilds[@guild_id]
375
+ end
376
+
377
+ # Fetch the message.
378
+ # @async
379
+ #
380
+ # @return [Async::Task<Discorb::Message>] The message.
381
+ def fetch_message
382
+ Async { channel.fetch_message(@id).wait }
383
+ end
384
+ end
385
+
386
+ #
387
+ # Represents a message but it has only ID.
388
+ #
389
+ class UnknownDeleteBulkMessage < GatewayEvent
390
+ # @return [Discorb::Snowflake] The ID of the message.
391
+ attr_reader :id
392
+
393
+ # @!attribute [r] channel
394
+ # @macro client_cache
395
+ # @return [Discorb::Channel] The channel the message was sent in.
396
+ # @!attribute [r] guild
397
+ # @macro client_cache
398
+ # @return [Discorb::Guild] The guild the message was sent in.
399
+
400
+ #
401
+ # Initialize a new instance of the UnknownDeleteBulkMessage class.
402
+ # @private
403
+ #
404
+ # @param [Discorb::Client] client The client that instantiated the object.
405
+ # @param [Hash] data The data of the event.
406
+ #
407
+ def initialize(client, id, data)
408
+ @client = client
409
+ @id = Snowflake.new(id)
410
+ @data = data
411
+ @channel_id = Snowflake.new(data[:channel_id])
412
+ @guild_id = Snowflake.new(data[:guild_id]) if data.key?(:guild_id)
413
+ end
414
+
415
+ def channel
416
+ @client.channels[@channel_id]
417
+ end
418
+
419
+ def guild
420
+ @client.guilds[@guild_id]
421
+ end
422
+ end
423
+
424
+ #
425
+ # Represents a `INVITE_DELETE` event.
426
+ #
427
+ class InviteDeleteEvent < GatewayEvent
428
+ # @return [String] The invite code.
429
+ attr_reader :code
430
+
431
+ # @!attribute [r] channel
432
+ # @macro client_cache
433
+ # @return [Discorb::Channel] The channel the message was sent in.
434
+ # @!attribute [r] guild
435
+ # @macro client_cache
436
+ # @return [Discorb::Guild] The guild the message was sent in.
437
+
438
+ #
439
+ # Initialize a new instance of the InviteDeleteEvent class.
440
+ # @private
441
+ #
442
+ # @param [Discorb::Client] client The client that instantiated the object.
443
+ # @param [Hash] data The data of the event.
444
+ #
445
+ def initialize(client, data)
446
+ @client = client
447
+ @data = data
448
+ @channel_id = Snowflake.new(data[:channel])
449
+ @guild_id = Snowflake.new(data[:guild_id])
450
+ @code = data[:code]
451
+ end
452
+
453
+ def channel
454
+ @client.channels[@channel_id]
455
+ end
456
+
457
+ def guild
458
+ @client.guilds[@guild_id]
459
+ end
460
+ end
461
+
462
+ #
463
+ # Represents a `TYPING_START` event.
464
+ #
465
+ class TypingStartEvent < GatewayEvent
466
+ # @return [Discorb::Snowflake] The ID of the channel the user is typing in.
467
+ attr_reader :user_id
468
+
469
+ # @!attribute [r] channel
470
+ # @macro client_cache
471
+ # @return [Discorb::Channel] The channel the user is typing in.
472
+ # @!attribute [r] guild
473
+ # @macro client_cache
474
+ # @return [Discorb::Guild] The guild the user is typing in.
475
+ # @!attribute [r] user
476
+ # @macro client_cache
477
+ # @return [Discorb::User, Discorb::Member] The user that is typing.
478
+
479
+ #
480
+ # Initialize a new instance of the TypingStartEvent class.
481
+ # @private
482
+ #
483
+ # @param [Discorb::Client] client The client that instantiated the object.
484
+ # @param [Hash] data The data of the event.
485
+ #
486
+ def initialize(client, data)
487
+ @client = client
488
+ @data = data
489
+ @channel_id = Snowflake.new(data[:channel_id])
490
+ @guild_id = Snowflake.new(data[:guild_id]) if data.key?(:guild_id)
491
+ @user_id = Snowflake.new(data[:user_id])
492
+ @timestamp = Time.at(data[:timestamp])
493
+ if guild
494
+ @member =
495
+ guild.members[@user_id] ||
496
+ Member.new(
497
+ @client,
498
+ @guild_id,
499
+ @client.users[@user_id].instance_variable_get(:@data),
500
+ data[:member]
501
+ )
502
+ end
503
+ end
504
+
505
+ def user
506
+ @member || guild&.members&.[](@user_id) || @client.users[@user_id]
507
+ end
508
+
509
+ alias member user
510
+
511
+ def channel
512
+ @client.channels[@channel_id]
513
+ end
514
+
515
+ def guild
516
+ @client.guilds[@guild_id]
517
+ end
518
+ end
519
+
520
+ #
521
+ # Represents a message pin event.
522
+ #
523
+ class MessagePinEvent < GatewayEvent
524
+ # @return [Discorb::Message] The message that was pinned.
525
+ attr_reader :message
526
+ # @return [:pinned, :unpinned] The type of event.
527
+ attr_reader :type
528
+
529
+ # @!attribute [r] pinned?
530
+ # @return [Boolean] Whether the message was pinned.
531
+ # @!attribute [r] unpinned?
532
+ # @return [Boolean] Whether the message was unpinned.
533
+
534
+ def initialize(client, data, message)
535
+ @client = client
536
+ @data = data
537
+ @message = message
538
+ @type =
539
+ if message.nil?
540
+ :unknown
541
+ elsif @message.pinned?
542
+ :pinned
543
+ else
544
+ :unpinned
545
+ end
546
+ end
547
+
548
+ def pinned?
549
+ @type == :pinned
550
+ end
551
+
552
+ def unpinned?
553
+ @type == :unpinned
554
+ end
555
+ end
556
+
557
+ #
558
+ # Represents a `WEBHOOKS_UPDATE` event.
559
+ #
560
+ class WebhooksUpdateEvent < GatewayEvent
561
+ # @!attribute [r] channel
562
+ # @macro client_cache
563
+ # @return [Discorb::Channel] The channel where the webhook was updated.
564
+ # @!attribute [r] guild
565
+ # @macro client_cache
566
+ # @return [Discorb::Guild] The guild where the webhook was updated.
567
+
568
+ #
569
+ # Initialize a new instance of the WebhooksUpdateEvent class.
570
+ # @private
571
+ #
572
+ # @param [Discorb::Client] client The client that instantiated the object.
573
+ # @param [Hash] data The data of the event.
574
+ #
575
+ def initialize(client, data)
576
+ @client = client
577
+ @data = data
578
+ @guild_id = Snowflake.new(data[:guild_id])
579
+ @channel_id = Snowflake.new(data[:channel_id])
580
+ end
581
+
582
+ def guild
583
+ @client.guilds[@guild_id]
584
+ end
585
+
586
+ def channel
587
+ @client.channels[@channel_id]
588
+ end
589
+ end
590
+
591
+ #
592
+ # Represents a `AUTO_MODERATION_ACTION_EXECUTION` event.
593
+ #
594
+ class AutoModerationActionExecutionEvent < GatewayEvent
595
+ # @return [Discorb::Snowflake] The id of the rule.
596
+ attr_reader :rule_id
597
+
598
+ # @return [Symbol] The type of action that was executed.
599
+ attr_reader :rule_trigger_type
600
+
601
+ # @return [Discorb::Snowflake] The id of the message that triggered the action.
602
+ # @return [nil] If the message was deleted.
603
+ attr_reader :message_id
604
+
605
+ # @return [Discorb::Snowflake] The id of the system message that was sent.
606
+ # @return [nil] If the system message channel was not set.
607
+ attr_reader :alert_system_message_id
608
+
609
+ # @return [String] The content of the message that was sent.
610
+ attr_reader :content
611
+
612
+ # @return [String] The keyword that triggered the action.
613
+ # @return [nil] If the action was not triggered by a keyword.
614
+ attr_reader :matched_keyword
615
+
616
+ # @return [String] The content that triggered the action.
617
+ # @return [nil] If the action was not triggered by a keyword.
618
+ attr_reader :matched_content
619
+
620
+ # @return [Discorb::AutoModRule::Action] The action that was executed.
621
+ attr_reader :action
622
+
623
+ #
624
+ # Initialize a new instance of the AutoModerationActionExecutionEvent class.
625
+ # @private
626
+ #
627
+ # @param [Discorb::Client] client The client that instantiated the object.
628
+ # @param [Hash] data The data of the event.
629
+ #
630
+ def initialize(client, data)
631
+ @client = client
632
+ @data = data
633
+ @rule_id = Snowflake.new(data[:rule_id])
634
+ @rule_trigger_type =
635
+ Discorb::AutoModRule::TRIGGER_TYPES[data[:rule_trigger_type]]
636
+ @action = Discorb::AutoModRule::Action.new(data[:action])
637
+ @user_id = Snowflake.new(data[:user_id])
638
+ @guild_id = Snowflake.new(data[:guild_id])
639
+ @channel_id = data[:channel_id] && Snowflake.new(data[:channel_id])
640
+ @message_id = data[:message_id] && Snowflake.new(data[:message_id])
641
+ @alert_system_message_id =
642
+ data[:alert_system_message_id] &&
643
+ Snowflake.new(data[:alert_system_message_id])
644
+ @content = data[:content]
645
+ @matched_keyword = data[:matched_keyword]
646
+ @matched_content = data[:matched_content]
647
+ end
648
+
649
+ # @!attribute [r] guild
650
+ # @return [Discorb::Guild] The guild where the rule was executed.
651
+ def guild
652
+ @client.guilds[@guild_id]
653
+ end
654
+
655
+ # @!attribute [r] channel
656
+ # @return [Discorb::Channel] The channel where the rule was executed.
657
+ def channel
658
+ @client.channels[@channel_id]
659
+ end
660
+
661
+ # @!attribute [r] member
662
+ # @return [Discorb::Member] The member that triggered the action.
663
+ def member
664
+ guild.members[@user_id]
665
+ end
666
+
667
+ alias user member
668
+ end
669
+ end
670
+ end