discorb 0.17.1 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/lint.yml +1 -3
  3. data/.github/workflows/validate.yml +21 -0
  4. data/Changelog.md +10 -0
  5. data/Gemfile +6 -0
  6. data/Rakefile +210 -98
  7. data/Steepfile +28 -0
  8. data/docs/events.md +42 -6
  9. data/docs/tutorial.md +7 -7
  10. data/docs/voice_events.md +2 -2
  11. data/examples/commands/message.rb +12 -7
  12. data/examples/commands/permission.rb +2 -1
  13. data/examples/commands/slash.rb +23 -19
  14. data/examples/commands/user.rb +15 -12
  15. data/examples/components/authorization_button.rb +2 -1
  16. data/examples/components/select_menu.rb +4 -1
  17. data/examples/extension/main.rb +1 -0
  18. data/examples/extension/message_expander.rb +1 -0
  19. data/examples/sig/commands/message.rbs +5 -0
  20. data/examples/simple/eval.rb +1 -0
  21. data/examples/simple/ping_pong.rb +1 -0
  22. data/examples/simple/rolepanel.rb +16 -5
  23. data/examples/simple/shard.rb +2 -1
  24. data/examples/simple/wait_for_message.rb +3 -0
  25. data/exe/discorb +3 -3
  26. data/lib/discorb/allowed_mentions.rb +1 -1
  27. data/lib/discorb/app_command/command.rb +12 -13
  28. data/lib/discorb/app_command/handler.rb +20 -6
  29. data/lib/discorb/audit_logs.rb +6 -2
  30. data/lib/discorb/automod.rb +269 -0
  31. data/lib/discorb/channel/guild.rb +2 -1
  32. data/lib/discorb/channel/stage.rb +1 -1
  33. data/lib/discorb/channel/text.rb +11 -20
  34. data/lib/discorb/channel/thread.rb +15 -11
  35. data/lib/discorb/client.rb +12 -10
  36. data/lib/discorb/color.rb +37 -60
  37. data/lib/discorb/common.rb +1 -1
  38. data/lib/discorb/dictionary.rb +1 -1
  39. data/lib/discorb/embed.rb +4 -3
  40. data/lib/discorb/emoji.rb +2 -2
  41. data/lib/discorb/exe/about.rb +1 -1
  42. data/lib/discorb/exe/new.rb +1 -5
  43. data/lib/discorb/extension.rb +0 -4
  44. data/lib/discorb/flag.rb +2 -2
  45. data/lib/discorb/gateway.rb +21 -582
  46. data/lib/discorb/gateway_events.rb +638 -0
  47. data/lib/discorb/guild.rb +136 -17
  48. data/lib/discorb/guild_template.rb +1 -1
  49. data/lib/discorb/http.rb +47 -25
  50. data/lib/discorb/intents.rb +27 -18
  51. data/lib/discorb/interaction/command.rb +14 -10
  52. data/lib/discorb/interaction/response.rb +74 -14
  53. data/lib/discorb/member.rb +3 -3
  54. data/lib/discorb/message.rb +13 -11
  55. data/lib/discorb/message_meta.rb +2 -3
  56. data/lib/discorb/modules.rb +3 -2
  57. data/lib/discorb/presence.rb +4 -2
  58. data/lib/discorb/reaction.rb +2 -2
  59. data/lib/discorb/role.rb +1 -1
  60. data/lib/discorb/sticker.rb +3 -3
  61. data/lib/discorb/user.rb +2 -2
  62. data/lib/discorb/voice_state.rb +5 -5
  63. data/lib/discorb/webhook.rb +15 -6
  64. data/lib/discorb.rb +2 -2
  65. data/rbs_collection.lock.yaml +88 -96
  66. data/rbs_collection.yaml +21 -17
  67. data/sig/async.rbs +11 -5
  68. data/sig/discorb/activity.rbs +23 -0
  69. data/sig/discorb/allowed_mentions.rbs +44 -0
  70. data/sig/discorb/app_command/base.rbs +282 -0
  71. data/sig/discorb/app_command/handler.rbs +171 -0
  72. data/sig/discorb/application.rbs +142 -0
  73. data/sig/discorb/asset.rbs +32 -0
  74. data/sig/discorb/attachment.rbs +91 -0
  75. data/sig/discorb/audit_log.rbs +231 -0
  76. data/sig/discorb/automod.rbs +128 -0
  77. data/sig/discorb/avatar.rbs +26 -0
  78. data/sig/discorb/channel/base.rbs +179 -0
  79. data/sig/discorb/channel/category.rbs +56 -0
  80. data/sig/discorb/channel/container.rbs +29 -0
  81. data/sig/discorb/channel/dm.rbs +14 -0
  82. data/sig/discorb/channel/news.rbs +20 -0
  83. data/sig/discorb/channel/stage.rbs +77 -0
  84. data/sig/discorb/channel/text.rbs +158 -0
  85. data/sig/discorb/channel/thread.rbs +185 -0
  86. data/sig/discorb/channel/voice.rbs +41 -0
  87. data/sig/discorb/client.rbs +2495 -0
  88. data/sig/discorb/color.rbs +142 -0
  89. data/sig/discorb/component/base.rbs +28 -0
  90. data/sig/discorb/component/button.rbs +65 -0
  91. data/sig/discorb/component/select_menu.rbs +107 -0
  92. data/sig/discorb/component/text_input.rbs +69 -0
  93. data/sig/discorb/connectable.rbs +8 -0
  94. data/sig/discorb/custom_emoji.rbs +90 -0
  95. data/sig/discorb/dictionary.rbs +85 -0
  96. data/sig/discorb/discord_model.rbs +15 -0
  97. data/sig/discorb/embed.rbs +279 -0
  98. data/sig/discorb/emoji.rbs +13 -0
  99. data/sig/discorb/error.rbs +73 -0
  100. data/sig/discorb/event_handler.rbs +27 -0
  101. data/sig/discorb/extension.rbs +1734 -0
  102. data/sig/discorb/flag.rbs +72 -0
  103. data/sig/discorb/gateway.rbs +481 -0
  104. data/sig/discorb/guild.rbs +870 -0
  105. data/sig/discorb/guild_template.rbs +174 -0
  106. data/sig/discorb/http.rbs +147 -0
  107. data/sig/discorb/image.rbs +20 -0
  108. data/sig/discorb/integration.rbs +118 -0
  109. data/sig/discorb/intents.rbs +97 -0
  110. data/sig/discorb/interaction/autocomplete.rbs +9 -0
  111. data/sig/discorb/interaction/base.rbs +66 -0
  112. data/sig/discorb/interaction/command.rbs +66 -0
  113. data/sig/discorb/interaction/message_component.rbs +140 -0
  114. data/sig/discorb/interaction/modal.rbs +50 -0
  115. data/sig/discorb/interaction/responder.rbs +157 -0
  116. data/sig/discorb/invite.rbs +86 -0
  117. data/sig/discorb/member.rbs +187 -0
  118. data/sig/discorb/message.rbs +469 -0
  119. data/sig/discorb/messageable.rbs +153 -0
  120. data/sig/discorb/partial_emoji.rbs +35 -0
  121. data/sig/discorb/permissions.rbs +149 -0
  122. data/sig/discorb/presence.rbs +237 -0
  123. data/sig/discorb/reaction.rbs +33 -0
  124. data/sig/discorb/role.rbs +145 -0
  125. data/sig/discorb/scheduled_event.rbs +148 -0
  126. data/sig/discorb/shard.rbs +62 -0
  127. data/sig/discorb/snowflake.rbs +56 -0
  128. data/sig/discorb/stage_instance.rbs +63 -0
  129. data/sig/discorb/sticker.rbs +116 -0
  130. data/sig/discorb/system_channel_flag.rbs +17 -0
  131. data/sig/discorb/unicode_emoji.rbs +49 -0
  132. data/sig/discorb/user.rbs +93 -0
  133. data/sig/discorb/utils.rbs +8 -0
  134. data/sig/discorb/voice_region.rbs +30 -0
  135. data/sig/discorb/voice_state.rbs +71 -0
  136. data/sig/discorb/webhook.rbs +327 -0
  137. data/sig/discorb/welcome_screen.rbs +78 -0
  138. data/sig/discorb.rbs +5 -8661
  139. data/sig/manifest.yaml +3 -0
  140. data/sig/override.rbs +19 -0
  141. metadata +80 -3
@@ -0,0 +1,638 @@
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