discorb 0.17.1 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -12,582 +12,12 @@ module Discorb
12
12
  # This module is internal use only.
13
13
  #
14
14
  module Gateway
15
- #
16
- # Represents an event.
17
- # @abstract
18
- #
19
- class GatewayEvent
20
- #
21
- # Initializes a new instance of the GatewayEvent class.
22
- # @private
23
- #
24
- # @param [Hash] data The data of the event.
25
- #
26
- def initialize(data)
27
- @data = data
28
- end
29
-
30
- def inspect
31
- "#<#{self.class}>"
32
- end
33
- end
34
-
35
- #
36
- # Represents a reaction event.
37
- #
38
- class ReactionEvent < GatewayEvent
39
- # @return [Hash] The raw data of the event.
40
- attr_reader :data
41
- # @return [Discorb::Snowflake] The ID of the user who reacted.
42
- attr_reader :user_id
43
- alias member_id user_id
44
- # @return [Discorb::Snowflake] The ID of the channel the message was sent in.
45
- attr_reader :channel_id
46
- # @return [Discorb::Snowflake] The ID of the message.
47
- attr_reader :message_id
48
- # @return [Discorb::Snowflake] The ID of the guild the message was sent in.
49
- attr_reader :guild_id
50
- # @macro client_cache
51
- # @return [Discorb::User] The user who reacted.
52
- attr_reader :user
53
- # @macro client_cache
54
- # @return [Discorb::Channel] The channel the message was sent in.
55
- attr_reader :channel
56
- # @macro client_cache
57
- # @return [Discorb::Guild] The guild the message was sent in.
58
- attr_reader :guild
59
- # @macro client_cache
60
- # @return [Discorb::Message] The message the reaction was sent in.
61
- attr_reader :message
62
- # @macro client_cache
63
- # @return [Discorb::Member] The member who reacted.
64
- attr_reader :member
65
- # @return [Discorb::UnicodeEmoji, Discorb::PartialEmoji] The emoji that was reacted with.
66
- attr_reader :emoji
67
- # @macro client_cache
68
- # @return [Discorb::Member, Discorb::User] The user or member who reacted.
69
- attr_reader :fired_by
70
-
71
- alias reactor fired_by
72
- alias from fired_by
73
-
74
- #
75
- # Initializes a new instance of the ReactionEvent class.
76
- # @private
77
- #
78
- # @param [Discorb::Client] client The client that instantiated the object.
79
- # @param [Hash] data The data of the event.
80
- #
81
- def initialize(client, data)
82
- @client = client
83
- @data = data
84
- if data.key?(:user_id)
85
- @user_id = Snowflake.new(data[:user_id])
86
- else
87
- @member_data = data[:member]
88
- end
89
- @channel_id = Snowflake.new(data[:channel_id])
90
- @message_id = Snowflake.new(data[:message_id])
91
- @guild_id = Snowflake.new(data[:guild_id])
92
- @guild = client.guilds[data[:guild_id]]
93
- @channel = client.channels[data[:channel_id]] unless @guild.nil?
94
-
95
- @user = client.users[data[:user_id]] if data.key?(:user_id)
96
-
97
- unless @guild.nil?
98
- @member = if data.key?(:member)
99
- @guild.members[data[:member][:user][:id]] || Member.new(@client, @guild_id, data[:member][:user],
100
- data[:member])
101
- else
102
- @guild.members[data[:user_id]]
103
- end
104
- end
105
-
106
- @fired_by = @member || @user || @client.users[data[:user_id]]
107
-
108
- @message = client.messages[data[:message_id]]
109
- @emoji = data[:emoji][:id].nil? ? UnicodeEmoji.new(data[:emoji][:name]) : PartialEmoji.new(data[:emoji])
110
- end
111
-
112
- # Fetch the message.
113
- # If message is cached, it will be returned.
114
- # @async
115
- #
116
- # @param [Boolean] force Whether to force fetching the message.
117
- #
118
- # @return [Async::Task<Discorb::Message>] The message.
119
- def fetch_message(force: false)
120
- Async do
121
- next @message if !force && @message
122
-
123
- @message = @channel.fetch_message(@message_id).wait
124
- end
125
- end
126
- end
127
-
128
- #
129
- # Represents a `INTEGRATION_DELETE` event.
130
- #
131
- class IntegrationDeleteEvent < GatewayEvent
132
- # @return [Discorb::Snowflake] The ID of the integration.
133
- attr_reader :id
134
-
135
- # @!attribute [r] guild
136
- # @macro client_cache
137
- # @return [Discorb::Guild] The guild of the integration.
138
- # @!attribute [r] user
139
- # @macro client_cache
140
- # @return [Discorb::User] The user associated with the integration.
141
-
142
- #
143
- # Initialize a new instance of the IntegrationDeleteEvent class.
144
- # @private
145
- #
146
- #
147
- # @param [Hash] data The data of the event.
148
- #
149
- #
150
- def initialize(_client, data)
151
- @id = Snowflake.new(data[:id])
152
- @guild_id = data[:guild_id]
153
- @user_id = data[:application_id]
154
- end
155
-
156
- def guild
157
- @client.guilds[@guild_id]
158
- end
159
-
160
- def user
161
- @client.users[@user_id]
162
- end
163
- end
164
-
165
- #
166
- # Represents a `MESSAGE_REACTION_REMOVE_ALL` event.
167
- #
168
- class ReactionRemoveAllEvent < GatewayEvent
169
- # @return [Discorb::Snowflake] The ID of the channel the message was sent in.
170
- attr_reader :channel_id
171
- # @return [Discorb::Snowflake] The ID of the message.
172
- attr_reader :message_id
173
- # @return [Discorb::Snowflake] The ID of the guild the message was sent in.
174
- attr_reader :guild_id
175
- # @macro client_cache
176
- # @return [Discorb::Channel] The channel the message was sent in.
177
- attr_reader :channel
178
- # @macro client_cache
179
- # @return [Discorb::Guild] The guild the message was sent in.
180
- attr_reader :guild
181
- # @macro client_cache
182
- # @return [Discorb::Message] The message the reaction was sent in.
183
- attr_reader :message
184
-
185
- #
186
- # Initialize a new instance of the ReactionRemoveAllEvent class.
187
- # @private
188
- #
189
- # @param [Discorb::Client] client The client that instantiated the object.
190
- # @param [Hash] data The data of the event.
191
- #
192
- def initialize(client, data)
193
- @client = client
194
- @data = data
195
- @guild_id = Snowflake.new(data[:guild_id])
196
- @channel_id = Snowflake.new(data[:channel_id])
197
- @message_id = Snowflake.new(data[:message_id])
198
- @guild = client.guilds[data[:guild_id]]
199
- @channel = client.channels[data[:channel_id]]
200
- @message = client.messages[data[:message_id]]
201
- end
202
-
203
- # Fetch the message.
204
- # If message is cached, it will be returned.
205
- # @async
206
- #
207
- # @param [Boolean] force Whether to force fetching the message.
208
- #
209
- # @return [Async::Task<Discorb::Message>] The message.
210
- def fetch_message(force: false)
211
- Async do
212
- next @message if !force && @message
213
-
214
- @message = @channel.fetch_message(@message_id).wait
215
- end
216
- end
217
- end
218
-
219
- #
220
- # Represents a `MESSAGE_REACTION_REMOVE_EMOJI` event.
221
- #
222
- class ReactionRemoveEmojiEvent < GatewayEvent
223
- # @return [Discorb::Snowflake] The ID of the channel the message was sent in.
224
- attr_reader :channel_id
225
- # @return [Discorb::Snowflake] The ID of the message.
226
- attr_reader :message_id
227
- # @return [Discorb::Snowflake] The ID of the guild the message was sent in.
228
- attr_reader :guild_id
229
- # @macro client_cache
230
- # @return [Discorb::Channel] The channel the message was sent in.
231
- attr_reader :channel
232
- # @macro client_cache
233
- # @return [Discorb::Guild] The guild the message was sent in.
234
- attr_reader :guild
235
- # @macro client_cache
236
- # @return [Discorb::Message] The message the reaction was sent in.
237
- attr_reader :message
238
- # @return [Discorb::UnicodeEmoji, Discorb::PartialEmoji] The emoji that was reacted with.
239
- attr_reader :emoji
240
-
241
- #
242
- # Initialize a new instance of the ReactionRemoveEmojiEvent class.
243
- # @private
244
- #
245
- # @param [Discorb::Client] client The client that instantiated the object.
246
- # @param [Hash] data The data of the event.
247
- #
248
- def initialize(client, data)
249
- @client = client
250
- @data = data
251
- @guild_id = Snowflake.new(data[:guild_id])
252
- @channel_id = Snowflake.new(data[:channel_id])
253
- @message_id = Snowflake.new(data[:message_id])
254
- @guild = client.guilds[data[:guild_id]]
255
- @channel = client.channels[data[:channel_id]]
256
- @message = client.messages[data[:message_id]]
257
- @emoji = data[:emoji][:id].nil? ? DiscordEmoji.new(data[:emoji][:name]) : PartialEmoji.new(data[:emoji])
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 = data[:mention_roles].map { |r| guild.roles[r] } if data.key?(:mention_roles)
352
- @attachments = data[:attachments].map { |a| Attachment.from_hash(a) } if data.key?(:attachments)
353
- @embeds = data[:embeds] ? data[:embeds].map { |e| Embed.from_hash(e) } : [] if data.key?(:embeds)
354
- end
355
-
356
- def channel
357
- @client.channels[@channel_id]
358
- end
359
-
360
- def guild
361
- @client.guilds[@guild_id]
362
- end
363
-
364
- # Fetch the message.
365
- # @async
366
- #
367
- # @return [Async::Task<Discorb::Message>] The message.
368
- def fetch_message
369
- Async do
370
- channel.fetch_message(@id).wait
371
- end
372
- end
373
- end
374
-
375
- #
376
- # Represents a message but it has only ID.
377
- #
378
- class UnknownDeleteBulkMessage < GatewayEvent
379
- # @return [Discorb::Snowflake] The ID of the message.
380
- attr_reader :id
381
-
382
- # @!attribute [r] channel
383
- # @macro client_cache
384
- # @return [Discorb::Channel] The channel the message was sent in.
385
- # @!attribute [r] guild
386
- # @macro client_cache
387
- # @return [Discorb::Guild] The guild the message was sent in.
388
-
389
- #
390
- # Initialize a new instance of the UnknownDeleteBulkMessage class.
391
- # @private
392
- #
393
- # @param [Discorb::Client] client The client that instantiated the object.
394
- # @param [Hash] data The data of the event.
395
- #
396
- def initialize(client, id, data)
397
- @client = client
398
- @id = id
399
- @data = data
400
- @channel_id = Snowflake.new(data[:channel_id])
401
- @guild_id = Snowflake.new(data[:guild_id]) if data.key?(:guild_id)
402
- end
403
-
404
- def channel
405
- @client.channels[@channel_id]
406
- end
407
-
408
- def guild
409
- @client.guilds[@guild_id]
410
- end
411
- end
412
-
413
- #
414
- # Represents a `INVITE_DELETE` event.
415
- #
416
- class InviteDeleteEvent < GatewayEvent
417
- # @return [String] The invite code.
418
- attr_reader :code
419
-
420
- # @!attribute [r] channel
421
- # @macro client_cache
422
- # @return [Discorb::Channel] The channel the message was sent in.
423
- # @!attribute [r] guild
424
- # @macro client_cache
425
- # @return [Discorb::Guild] The guild the message was sent in.
426
-
427
- #
428
- # Initialize a new instance of the InviteDeleteEvent class.
429
- # @private
430
- #
431
- # @param [Discorb::Client] client The client that instantiated the object.
432
- # @param [Hash] data The data of the event.
433
- #
434
- def initialize(client, data)
435
- @client = client
436
- @data = data
437
- @channel_id = Snowflake.new(data[:channel])
438
- @guild_id = Snowflake.new(data[:guild_id])
439
- @code = data[:code]
440
- end
441
-
442
- def channel
443
- @client.channels[@channel_id]
444
- end
445
-
446
- def guild
447
- @client.guilds[@guild_id]
448
- end
449
- end
450
-
451
- #
452
- # Represents a `TYPING_START` event.
453
- #
454
- class TypingStartEvent < GatewayEvent
455
- # @return [Discorb::Snowflake] The ID of the channel the user is typing in.
456
- attr_reader :user_id
457
- # @macro client_cache
458
- # @return [Discorb::Member] The member that is typing.
459
- attr_reader :member
460
-
461
- # @!attribute [r] channel
462
- # @macro client_cache
463
- # @return [Discorb::Channel] The channel the user is typing in.
464
- # @!attribute [r] guild
465
- # @macro client_cache
466
- # @return [Discorb::Guild] The guild the user is typing in.
467
- # @!attribute [r] user
468
- # @macro client_cache
469
- # @return [Discorb::User] The user that is typing.
470
- # @!attribute [r] fired_by
471
- # @macro client_cache
472
- # @return [Discorb::Member, Discorb::User] The member or user that started typing.
473
-
474
- #
475
- # Initialize a new instance of the TypingStartEvent class.
476
- # @private
477
- #
478
- # @param [Discorb::Client] client The client that instantiated the object.
479
- # @param [Hash] data The data of the event.
480
- #
481
- def initialize(client, data)
482
- @client = client
483
- @data = data
484
- @channel_id = Snowflake.new(data[:channel_id])
485
- @guild_id = Snowflake.new(data[:guild_id]) if data.key?(:guild_id)
486
- @user_id = Snowflake.new(data[:user_id])
487
- @timestamp = Time.at(data[:timestamp])
488
- if guild
489
- @member = guild.members[@user_id] || Member.new(
490
- @client,
491
- @guild_id,
492
- @client.users[@user_id].instance_variable_get(:@data),
493
- data[:member]
494
- )
495
- end
496
- end
497
-
498
- def user
499
- @client.users[@user_id]
500
- end
501
-
502
- def channel
503
- @client.channels[@channel_id]
504
- end
505
-
506
- def guild
507
- @client.guilds[@guild_id]
508
- end
509
-
510
- def fired_by
511
- @member || user
512
- end
513
-
514
- alias from fired_by
515
- end
516
-
517
- #
518
- # Represents a message pin event.
519
- #
520
- class MessagePinEvent < GatewayEvent
521
- # @return [Discorb::Message] The message that was pinned.
522
- attr_reader :message
523
- # @return [:pinned, :unpinned] The type of event.
524
- attr_reader :type
525
-
526
- # @!attribute [r] pinned?
527
- # @return [Boolean] Whether the message was pinned.
528
- # @!attribute [r] unpinned?
529
- # @return [Boolean] Whether the message was unpinned.
530
-
531
- def initialize(client, data, message)
532
- @client = client
533
- @data = data
534
- @message = message
535
- @type = if message.nil?
536
- :unknown
537
- elsif @message.pinned?
538
- :pinned
539
- else
540
- :unpinned
541
- end
542
- end
543
-
544
- def pinned?
545
- @type == :pinned
546
- end
547
-
548
- def unpinned?
549
- @type = :unpinned
550
- end
551
- end
552
-
553
- #
554
- # Represents a `WEBHOOKS_UPDATE` event.
555
- #
556
- class WebhooksUpdateEvent < GatewayEvent
557
- # @!attribute [r] channel
558
- # @macro client_cache
559
- # @return [Discorb::Channel] The channel where the webhook was updated.
560
- # @!attribute [r] guild
561
- # @macro client_cache
562
- # @return [Discorb::Guild] The guild where the webhook was updated.
563
-
564
- #
565
- # Initialize a new instance of the WebhooksUpdateEvent class.
566
- # @private
567
- #
568
- # @param [Discorb::Client] client The client that instantiated the object.
569
- # @param [Hash] data The data of the event.
570
- #
571
- def initialize(client, data)
572
- @client = client
573
- @data = data
574
- @guild_id = Snowflake.new(data[:guild_id])
575
- @channel_id = Snowflake.new(data[:channel_id])
576
- end
577
-
578
- def guild
579
- @client.guilds[@guild_id]
580
- end
581
-
582
- def channel
583
- @client.channels[@channel_id]
584
- end
585
- end
586
-
587
15
  #
588
16
  # A module to handle gateway events.
589
17
  #
590
18
  module Handler
19
+ # @type instance: Discorb::Client
20
+
591
21
  private
592
22
 
593
23
  def connect_gateway(reconnect)
@@ -623,10 +53,11 @@ module Discorb
623
53
  headers: [["User-Agent", Discorb::USER_AGENT]],
624
54
  handler: RawConnection,
625
55
  )
56
+ con = self.connection
626
57
  zlib_stream = Zlib::Inflate.new(Zlib::MAX_WBITS)
627
58
  buffer = +""
628
59
  begin
629
- while (message = connection.read)
60
+ while (message = con.read)
630
61
  buffer << message
631
62
  if message.end_with?((+"\x00\x00\xff\xff").force_encoding("ASCII-8BIT"))
632
63
  begin
@@ -652,7 +83,7 @@ module Discorb
652
83
  next if @status == :closed
653
84
 
654
85
  logger.error "Gateway connection closed accidentally: #{e.class}: #{e.message}"
655
- connection.force_close
86
+ con.force_close
656
87
  connect_gateway(true)
657
88
  next
658
89
  end
@@ -663,7 +94,7 @@ module Discorb
663
94
  raise ClientError.new("Authentication failed"), cause: nil
664
95
  when 4009
665
96
  logger.info "Session timed out, reconnecting."
666
- connection.force_close
97
+ con.force_close
667
98
  connect_gateway(true)
668
99
  next
669
100
  when 4014
@@ -678,19 +109,19 @@ module Discorb
678
109
  ERROR
679
110
  when 1001
680
111
  logger.info "Gateway closed with code 1001, reconnecting."
681
- connection.force_close
112
+ con.force_close
682
113
  connect_gateway(true)
683
114
  next
684
115
  else
685
116
  logger.error "Discord WebSocket closed with code #{e.code}."
686
117
  logger.debug "#{e.message}"
687
- connection.force_close
118
+ con.force_close
688
119
  connect_gateway(false)
689
120
  next
690
121
  end
691
122
  rescue StandardError => e
692
123
  logger.error "Discord WebSocket error: #{e.full_message}"
693
- connection.force_close
124
+ con.force_close
694
125
  connect_gateway(false)
695
126
  next
696
127
  end
@@ -909,11 +340,11 @@ module Discorb
909
340
  return logger.warn "Unknown thread id #{data[:id]}, ignoring" unless (thread = @channels[data[:id]])
910
341
 
911
342
  if (member = thread.members[data[:id]])
912
- old = ThreadChannel::Member.new(self, member.instance_variable_get(:@data))
343
+ old = ThreadChannel::Member.new(self, member.instance_variable_get(:@data), data[:guild_id])
913
344
  member.send(:_set_data, data)
914
345
  else
915
346
  old = nil
916
- member = ThreadChannel::Member.new(self, data)
347
+ member = ThreadChannel::Member.new(self, data, data[:guild_id])
917
348
  thread.members[data[:user_id]] = member
918
349
  end
919
350
  dispatch(:thread_member_update, thread, old, member)
@@ -923,7 +354,7 @@ module Discorb
923
354
  thread.instance_variable_set(:@member_count, data[:member_count])
924
355
  members = []
925
356
  (data[:added_members] || []).each do |raw_member|
926
- member = ThreadChannel::Member.new(self, raw_member)
357
+ member = ThreadChannel::Member.new(self, raw_member, data[:guild_id])
927
358
  thread.members[member.id] = member
928
359
  members << member
929
360
  end
@@ -1173,7 +604,7 @@ module Discorb
1173
604
  target_reaction.instance_variable_set(:@count, target_reaction.count + 1)
1174
605
  else
1175
606
  target_message.reactions << Reaction.new(
1176
- self,
607
+ target_message,
1177
608
  {
1178
609
  count: 1,
1179
610
  me: @user.id == data[:user_id],
@@ -1257,6 +688,14 @@ module Discorb
1257
688
  when "GUILD_SCHEDULED_EVENT_USER_REMOVE"
1258
689
  logger.warn("Unknown guild id #{data[:guild_id]}, ignoring") unless (guild = @guilds[data[:guild_id]])
1259
690
  dispatch(:scheduled_event_user_remove, ScheduledEventUserEvent.new(self, data))
691
+ when "AUTO_MODERATION_ACTION_EXECUTION"
692
+ dispatch(:auto_moderation_action_execution, AutoModerationActionExecutionEvent.new(self, data))
693
+ when "AUTO_MODERATION_RULE_CREATE"
694
+ dispatch(:auto_moderation_rule_create, AutoModRule.new(self, data))
695
+ when "AUTO_MODERATION_RULE_UPDATE"
696
+ dispatch(:auto_moderation_rule_update, AutoModRule.new(self, data))
697
+ when "AUTO_MODERATION_RULE_DELETE"
698
+ dispatch(:auto_moderation_rule_delete, AutoModRule.new(self, data))
1260
699
  else
1261
700
  if respond_to?("event_" + event_name.downcase)
1262
701
  __send__("event_" + event_name.downcase, data)