discorb 0.15.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +1 -0
  3. data/.github/workflows/build_main.yml +2 -2
  4. data/.github/workflows/build_version.yml +1 -1
  5. data/.github/workflows/codeql-analysis.yml +1 -1
  6. data/.github/workflows/lint-push.yml +3 -5
  7. data/.github/workflows/lint.yml +1 -1
  8. data/.github/workflows/spec.yml +30 -0
  9. data/.lefthook/commit-msg/validator.rb +5 -0
  10. data/.rspec +2 -0
  11. data/.rspec_parallel +2 -0
  12. data/.rubocop.yml +49 -8
  13. data/Changelog.md +32 -1
  14. data/Gemfile +14 -8
  15. data/Rakefile +46 -25
  16. data/bin/console +3 -3
  17. data/docs/Examples.md +1 -1
  18. data/docs/application_command.md +138 -46
  19. data/docs/cli/irb.md +2 -2
  20. data/docs/cli/new.md +14 -9
  21. data/docs/cli/run.md +7 -11
  22. data/docs/cli.md +17 -10
  23. data/docs/events.md +257 -193
  24. data/docs/extension.md +1 -2
  25. data/docs/faq.md +0 -1
  26. data/docs/tutorial.md +12 -12
  27. data/docs/voice_events.md +106 -106
  28. data/examples/commands/message.rb +63 -0
  29. data/examples/commands/permission.rb +18 -0
  30. data/examples/commands/slash.rb +44 -0
  31. data/examples/commands/user.rb +51 -0
  32. data/examples/components/authorization_button.rb +2 -2
  33. data/examples/components/select_menu.rb +2 -2
  34. data/examples/extension/main.rb +1 -1
  35. data/examples/extension/message_expander.rb +5 -2
  36. data/examples/simple/eval.rb +2 -2
  37. data/examples/simple/ping_pong.rb +1 -1
  38. data/examples/simple/rolepanel.rb +2 -2
  39. data/examples/simple/shard.rb +17 -0
  40. data/examples/simple/wait_for_message.rb +1 -1
  41. data/exe/discorb +31 -16
  42. data/lefthook.yml +45 -0
  43. data/lib/discorb/allowed_mentions.rb +8 -0
  44. data/lib/discorb/app_command/command.rb +184 -60
  45. data/lib/discorb/app_command/common.rb +25 -0
  46. data/lib/discorb/app_command/handler.rb +116 -34
  47. data/lib/discorb/app_command.rb +2 -1
  48. data/lib/discorb/application.rb +17 -7
  49. data/lib/discorb/asset.rb +10 -2
  50. data/lib/discorb/attachment.rb +17 -2
  51. data/lib/discorb/audit_logs.rb +53 -12
  52. data/lib/discorb/channel/base.rb +108 -0
  53. data/lib/discorb/channel/category.rb +32 -0
  54. data/lib/discorb/channel/container.rb +44 -0
  55. data/lib/discorb/channel/dm.rb +28 -0
  56. data/lib/discorb/channel/guild.rb +245 -0
  57. data/lib/discorb/channel/stage.rb +140 -0
  58. data/lib/discorb/channel/text.rb +345 -0
  59. data/lib/discorb/channel/thread.rb +321 -0
  60. data/lib/discorb/channel/voice.rb +79 -0
  61. data/lib/discorb/channel.rb +2 -1126
  62. data/lib/discorb/client.rb +160 -64
  63. data/lib/discorb/common.rb +18 -3
  64. data/lib/discorb/components/button.rb +7 -7
  65. data/lib/discorb/components/select_menu.rb +6 -18
  66. data/lib/discorb/components/text_input.rb +12 -2
  67. data/lib/discorb/components.rb +1 -1
  68. data/lib/discorb/dictionary.rb +2 -0
  69. data/lib/discorb/embed.rb +55 -14
  70. data/lib/discorb/emoji.rb +59 -5
  71. data/lib/discorb/emoji_table.rb +4970 -4
  72. data/lib/discorb/error.rb +7 -1
  73. data/lib/discorb/event.rb +56 -21
  74. data/lib/discorb/exe/about.rb +1 -0
  75. data/lib/discorb/exe/irb.rb +2 -4
  76. data/lib/discorb/exe/new.rb +95 -28
  77. data/lib/discorb/exe/run.rb +9 -37
  78. data/lib/discorb/exe/setup.rb +25 -12
  79. data/lib/discorb/exe/show.rb +4 -3
  80. data/lib/discorb/extend.rb +1 -0
  81. data/lib/discorb/extension.rb +6 -3
  82. data/lib/discorb/flag.rb +11 -0
  83. data/lib/discorb/gateway.rb +312 -169
  84. data/lib/discorb/gateway_requests.rb +4 -7
  85. data/lib/discorb/guild.rb +255 -89
  86. data/lib/discorb/guild_template.rb +34 -7
  87. data/lib/discorb/http.rb +23 -11
  88. data/lib/discorb/integration.rb +27 -9
  89. data/lib/discorb/intents.rb +8 -8
  90. data/lib/discorb/interaction/autocomplete.rb +31 -19
  91. data/lib/discorb/interaction/command.rb +70 -17
  92. data/lib/discorb/interaction/components.rb +20 -4
  93. data/lib/discorb/interaction/modal.rb +0 -1
  94. data/lib/discorb/interaction/response.rb +73 -22
  95. data/lib/discorb/interaction/root.rb +29 -14
  96. data/lib/discorb/interaction.rb +1 -0
  97. data/lib/discorb/invite.rb +16 -9
  98. data/lib/discorb/member.rb +46 -5
  99. data/lib/discorb/message.rb +56 -15
  100. data/lib/discorb/message_meta.rb +39 -9
  101. data/lib/discorb/modules.rb +56 -14
  102. data/lib/discorb/permission.rb +14 -5
  103. data/lib/discorb/presence.rb +43 -10
  104. data/lib/discorb/rate_limit.rb +13 -3
  105. data/lib/discorb/reaction.rb +10 -4
  106. data/lib/discorb/role.rb +31 -4
  107. data/lib/discorb/shard.rb +74 -0
  108. data/lib/discorb/sticker.rb +30 -21
  109. data/lib/discorb/user.rb +13 -1
  110. data/lib/discorb/utils/colored_puts.rb +1 -0
  111. data/lib/discorb/voice_state.rb +30 -8
  112. data/lib/discorb/webhook.rb +88 -25
  113. data/lib/discorb.rb +10 -6
  114. data/po/yard.pot +9 -9
  115. data/sig/discorb.rbs +7232 -5837
  116. metadata +23 -6
  117. data/examples/commands/bookmarker.rb +0 -42
  118. data/examples/commands/hello.rb +0 -10
  119. data/examples/commands/inspect.rb +0 -25
  120. data/lib/discorb/log.rb +0 -81
data/lib/discorb/guild.rb CHANGED
@@ -21,7 +21,8 @@ module Discorb
21
21
  attr_reader :afk_timeout
22
22
  # @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::Role}] A dictionary of roles in the guild.
23
23
  attr_reader :roles
24
- # @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}] A dictionary of custom emojis in the guild.
24
+ # @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}]
25
+ # A dictionary of custom emojis in the guild.
25
26
  attr_reader :emojis
26
27
  # @return [Array<Symbol>] features that are enabled in the guild.
27
28
  # @see https://discord.com/developers/docs/resources/guild#guild-object-guild-features Official Discord API docs
@@ -76,7 +77,8 @@ module Discorb
76
77
  attr_reader :welcome_screen
77
78
  # @return [:default, :explicit, :safe, :age_restricted] The nsfw level of the guild.
78
79
  attr_reader :nsfw_level
79
- # @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::StageInstance}] A dictionary of stage instances in the guild.
80
+ # @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::StageInstance}]
81
+ # A dictionary of stage instances in the guild.
80
82
  attr_reader :stage_instances
81
83
  # @return [:none, :low, :medium, :high, :very_high] The verification level of the guild.
82
84
  attr_reader :verification_level
@@ -100,6 +102,8 @@ module Discorb
100
102
  attr_reader :scheduled_events
101
103
  alias events scheduled_events
102
104
 
105
+ include Discorb::ChannelContainer
106
+
103
107
  # @!attribute [r] afk_channel
104
108
  # @return [Discorb::VoiceChannel] The AFK channel for this guild.
105
109
  # @macro client_cache
@@ -115,27 +119,36 @@ module Discorb
115
119
  # @!attribute [r] me
116
120
  # @return [Discorb::Member] The client's member in the guild.
117
121
 
118
- @mfa_levels = %i[none elevated].freeze
119
- @nsfw_levels = %i[default explicit safe age_restricted].freeze
120
- @verification_levels = %i[none low medium high very_high].freeze
121
- @default_message_notifications = %i[all_messages only_mentions].freeze
122
- @explicit_content_filter = %i[disabled_in_text members_without_roles all_members].freeze
122
+ # @private
123
+ # @return [Array<Symbol>] The mapping of mfa_level.
124
+ MFA_LEVELS = %i[none elevated].freeze
125
+ # @private
126
+ # @return [Array<Symbol>] The mapping of nsfw_level.
127
+ NSFW_LEVELS = %i[default explicit safe age_restricted].freeze
128
+ # @private
129
+ # @return [Array<Symbol>] The mapping of verification_level.
130
+ VERIFICATION_LEVELS = %i[none low medium high very_high].freeze
131
+ # @private
132
+ # @return [Array<Symbol>] The mapping of default_message_notifications.
133
+ DEFAULT_MESSAGE_NOTIFICATIONS = %i[all_messages only_mentions].freeze
134
+ # @private
135
+ # @return [Array<Symbol>] The mapping of explicit_content_filter.
136
+ EXPLICIT_CONTENT_FILTER = %i[disabled_in_text members_without_roles all_members].freeze
123
137
 
138
+ #
139
+ # Creates a new guild object.
124
140
  # @private
141
+ #
142
+ # @param [Discorb::Client] client The client that owns this guild.
143
+ # @param [Hash] data The data of the guild.
144
+ # @param [Boolean] is_create_event Whether the guild is created by a `GUILD_CREATE` event.
145
+ #
125
146
  def initialize(client, data, is_create_event)
126
147
  @client = client
127
148
  @data = {}
128
149
  _set_data(data, is_create_event)
129
150
  end
130
151
 
131
- # @private
132
- def update!
133
- Async do
134
- _, data = @client.get("/guilds/#{@id}").wait
135
- _set_data(data, false)
136
- end
137
- end
138
-
139
152
  def afk_channel
140
153
  @client.channels[@afk_channel_id]
141
154
  end
@@ -184,7 +197,13 @@ module Discorb
184
197
  #
185
198
  def fetch_scheduled_events(with_user_count: true)
186
199
  Async do
187
- _resp, events = @client.http.request(Route.new("/guilds/#{@id}/scheduled-events?with_user_count=#{with_user_count}", "//guilds/:guild_id/scheduled-events", :get)).wait
200
+ _resp, events = @client.http.request(
201
+ Route.new(
202
+ "/guilds/#{@id}/scheduled-events?with_user_count=#{with_user_count}",
203
+ "//guilds/:guild_id/scheduled-events",
204
+ :get
205
+ )
206
+ ).wait
188
207
  @scheduled_events = events.map { |e| ScheduledEvent.new(@client, e) }
189
208
  end
190
209
  end
@@ -200,7 +219,13 @@ module Discorb
200
219
  #
201
220
  def fetch_scheduled_event(id)
202
221
  Async do
203
- _resp, event = @client.http.request(Route.new("/guilds/#{@id}/scheduled-events/#{id}", "//guilds/:guild_id/scheduled-events/:scheduled_event_id", :get)).wait
222
+ _resp, event = @client.http.request(
223
+ Route.new(
224
+ "/guilds/#{@id}/scheduled-events/#{id}",
225
+ "//guilds/:guild_id/scheduled-events/:scheduled_event_id",
226
+ :get
227
+ )
228
+ ).wait
204
229
  rescue Discorb::NotFoundError
205
230
  return nil
206
231
  else
@@ -237,36 +262,39 @@ module Discorb
237
262
  payload = case type
238
263
  when :stage_instance
239
264
  raise ArgumentError, "channel must be provided for stage_instance events" unless channel
265
+
240
266
  {
241
267
  name: name,
242
268
  description: description,
243
269
  scheduled_start_time: start_time.iso8601,
244
270
  scheduled_end_time: end_time&.iso8601,
245
- privacy_level: Discorb::ScheduledEvent.privacy_level.key(privacy_level),
271
+ privacy_level: Discorb::ScheduledEvent::PRIVACY_LEVEL.key(privacy_level),
246
272
  channel_id: channel&.id,
247
- entity_type: Discorb::ScheduledEvent.entity_type.key(:stage_instance),
273
+ entity_type: Discorb::ScheduledEvent::ENTITY_TYPE.key(:stage_instance),
248
274
  }
249
275
  when :voice
250
276
  raise ArgumentError, "channel must be provided for voice events" unless channel
277
+
251
278
  {
252
279
  name: name,
253
280
  description: description,
254
281
  scheduled_start_time: start_time.iso8601,
255
282
  scheduled_end_time: end_time&.iso8601,
256
- privacy_level: Discorb::ScheduledEvent.privacy_level.key(privacy_level),
283
+ privacy_level: Discorb::ScheduledEvent::PRIVACY_LEVEL.key(privacy_level),
257
284
  channel_id: channel&.id,
258
- entity_type: Discorb::ScheduledEvent.entity_type.key(:voice),
285
+ entity_type: Discorb::ScheduledEvent::ENTITY_TYPE.key(:voice),
259
286
  }
260
287
  when :external
261
288
  raise ArgumentError, "location must be provided for external events" unless location
262
289
  raise ArgumentError, "end_time must be provided for external events" unless end_time
290
+
263
291
  {
264
292
  name: name,
265
293
  description: description,
266
294
  scheduled_start_time: start_time.iso8601,
267
295
  scheduled_end_time: end_time.iso8601,
268
- privacy_level: Discorb::ScheduledEvent.privacy_level.key(privacy_level),
269
- entity_type: Discorb::ScheduledEvent.entity_type.key(:external),
296
+ privacy_level: Discorb::ScheduledEvent::PRIVACY_LEVEL.key(privacy_level),
297
+ entity_type: Discorb::ScheduledEvent::ENTITY_TYPE.key(:external),
270
298
  entity_metadata: {
271
299
  location: location,
272
300
  },
@@ -274,7 +302,9 @@ module Discorb
274
302
  else
275
303
  raise ArgumentError, "Invalid scheduled event type: #{type}"
276
304
  end
277
- _resp, event = @client.http.request(Route.new("/guilds/#{@id}/scheduled-events", "//guilds/:guild_id/scheduled-events", :post), payload).wait
305
+ _resp, event = @client.http.request(
306
+ Route.new("/guilds/#{@id}/scheduled-events", "//guilds/:guild_id/scheduled-events", :post), payload
307
+ ).wait
278
308
  Discorb::ScheduledEvent.new(@client, event)
279
309
  end
280
310
  end
@@ -284,7 +314,8 @@ module Discorb
284
314
  # @async
285
315
  # @note This querys the API every time. We recommend using {#emojis} instead.
286
316
  #
287
- # @return [Async::Task<Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}>] A dictionary of emoji in the guild.
317
+ # @return [Async::Task<Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}>]
318
+ # A dictionary of emoji in the guild.
288
319
  #
289
320
  def fetch_emoji_list
290
321
  Async do
@@ -312,7 +343,8 @@ module Discorb
312
343
  # @return [Async::Task<Discorb::CustomEmoji>] The emoji with the given id.
313
344
  #
314
345
  def fetch_emoji(id)
315
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/emojis/#{id}", "//guilds/:guild_id/emojis/:emoji_id", :get)).wait
346
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/emojis/#{id}",
347
+ "//guilds/:guild_id/emojis/:emoji_id", :get)).wait
316
348
  @emojis[e[:id]] = CustomEmoji.new(@client, self, data)
317
349
  end
318
350
 
@@ -329,10 +361,10 @@ module Discorb
329
361
  def create_emoji(name, image, roles: [])
330
362
  _resp, data = @client.http.request(Route.new("/guilds/#{@id}/emojis", "//guilds/:guild_id/emojis", :post),
331
363
  {
332
- name: name,
333
- image: image.to_s,
334
- roles: roles.map { |r| Discorb::Utils.try(r, :id) },
335
- }).wait
364
+ name: name,
365
+ image: image.to_s,
366
+ roles: roles.map { |r| Discorb::Utils.try(r, :id) },
367
+ }).wait
336
368
  @emojis[data[:id]] = CustomEmoji.new(@client, self, data)
337
369
  end
338
370
 
@@ -344,7 +376,8 @@ module Discorb
344
376
  #
345
377
  def fetch_webhooks
346
378
  Async do
347
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/webhooks", "//guilds/:guild_id/webhooks", :get)).wait
379
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/webhooks", "//guilds/:guild_id/webhooks",
380
+ :get)).wait
348
381
  data.map { |webhook| Webhook.new([@client, webhook]) }
349
382
  end
350
383
  end
@@ -357,7 +390,8 @@ module Discorb
357
390
  #
358
391
  def fetch_audit_log
359
392
  Async do
360
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/audit-logs", "//guilds/:guild_id/audit-logs", :get)).wait
393
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/audit-logs", "//guilds/:guild_id/audit-logs",
394
+ :get)).wait
361
395
  AuditLog.new(@client, data, self)
362
396
  end
363
397
  end
@@ -370,7 +404,8 @@ module Discorb
370
404
  #
371
405
  def fetch_channels
372
406
  Async do
373
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :get)).wait
407
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels",
408
+ :get)).wait
374
409
  data.map { |c| Channel.make_channel(@client, c) }
375
410
  end
376
411
  end
@@ -385,14 +420,23 @@ module Discorb
385
420
  # @param [Integer] slowmode Alias for `rate_limit_per_user`.
386
421
  # @param [Integer] position The position of the channel.
387
422
  # @param [Boolean] nsfw Whether the channel is nsfw.
388
- # @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites A list of permission overwrites.
423
+ # @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
424
+ # A list of permission overwrites.
389
425
  # @param [Discorb::CategoryChannel] parent The parent of the channel.
390
426
  # @param [String] reason The reason for creating the channel.
391
427
  #
392
428
  # @return [Async::Task<Discorb::TextChannel>] The created text channel.
393
429
  #
394
430
  def create_text_channel(
395
- name, topic: nil, rate_limit_per_user: nil, slowmode: nil, position: nil, nsfw: nil, permission_overwrites: nil, parent: nil, reason: nil
431
+ name,
432
+ topic: nil,
433
+ rate_limit_per_user: nil,
434
+ slowmode: nil,
435
+ position: nil,
436
+ nsfw: nil,
437
+ permission_overwrites: nil,
438
+ parent: nil,
439
+ reason: nil
396
440
  )
397
441
  Async do
398
442
  payload = { type: TextChannel.channel_type }
@@ -413,7 +457,8 @@ module Discorb
413
457
  end
414
458
  end
415
459
  payload[:parent_id] = parent.id if parent
416
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post), payload, audit_log_reason: reason).wait
460
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post),
461
+ payload, audit_log_reason: reason).wait
417
462
  payload[:parent_id] = parent&.id
418
463
  Channel.make_channel(@client, data)
419
464
  end
@@ -427,7 +472,8 @@ module Discorb
427
472
  # @param [Integer] bitrate The bitrate of the channel.
428
473
  # @param [Integer] user_limit The user limit of the channel.
429
474
  # @param [Integer] position The position of the channel.
430
- # @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites A list of permission overwrites.
475
+ # @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
476
+ # A list of permission overwrites.
431
477
  # @param [Discorb::CategoryChannel] parent The parent of the channel.
432
478
  # @param [String] reason The reason for creating the channel.
433
479
  #
@@ -453,7 +499,8 @@ module Discorb
453
499
  end
454
500
  end
455
501
  payload[:parent_id] = parent.id if parent
456
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post), payload, audit_log_reason: reason).wait
502
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post),
503
+ payload, audit_log_reason: reason).wait
457
504
  payload[:parent_id] = parent&.id
458
505
  Channel.make_channel(@client, data)
459
506
  end
@@ -464,7 +511,8 @@ module Discorb
464
511
  #
465
512
  # @param [String] name The name of the channel.
466
513
  # @param [Integer] position The position of the channel.
467
- # @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites A list of permission overwrites.
514
+ # @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
515
+ # A list of permission overwrites.
468
516
  # @param [Discorb::CategoryChannel] parent The parent of the channel.
469
517
  # @param [String] reason The reason for creating the channel.
470
518
  #
@@ -486,7 +534,8 @@ module Discorb
486
534
  end
487
535
  end
488
536
  payload[:parent_id] = parent&.id
489
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post), payload, audit_log_reason: reason).wait
537
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post),
538
+ payload, audit_log_reason: reason).wait
490
539
  Channel.make_channel(@client, data)
491
540
  end
492
541
  end
@@ -500,7 +549,8 @@ module Discorb
500
549
  # @param [String] name The name of the channel.
501
550
  # @param [Integer] bitrate The bitrate of the channel.
502
551
  # @param [Integer] position The position of the channel.
503
- # @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites A list of permission overwrites.
552
+ # @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
553
+ # A list of permission overwrites.
504
554
  # @param [Discorb::CategoryChannel] parent The parent of the channel.
505
555
  # @param [String] reason The reason for creating the channel.
506
556
  #
@@ -523,7 +573,8 @@ module Discorb
523
573
  end
524
574
  end
525
575
  payload[:parent_id] = parent&.id
526
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post), payload, audit_log_reason: reason).wait
576
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post),
577
+ payload, audit_log_reason: reason).wait
527
578
  Channel.make_channel(@client, data)
528
579
  end
529
580
  end
@@ -538,14 +589,23 @@ module Discorb
538
589
  # @param [Integer] slowmode Alias for `rate_limit_per_user`.
539
590
  # @param [Integer] position The position of the channel.
540
591
  # @param [Boolean] nsfw Whether the channel is nsfw.
541
- # @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites A list of permission overwrites.
592
+ # @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
593
+ # A list of permission overwrites.
542
594
  # @param [Discorb::CategoryChannel] parent The parent of the channel.
543
595
  # @param [String] reason The reason for creating the channel.
544
596
  #
545
597
  # @return [Async::Task<Discorb::NewsChannel>] The created news channel.
546
598
  #
547
599
  def create_news_channel(
548
- name, topic: nil, rate_limit_per_user: nil, slowmode: nil, position: nil, nsfw: nil, permission_overwrites: nil, parent: nil, reason: nil
600
+ name,
601
+ topic: nil,
602
+ rate_limit_per_user: nil,
603
+ slowmode: nil,
604
+ position: nil,
605
+ nsfw: nil,
606
+ permission_overwrites: nil,
607
+ parent: nil,
608
+ reason: nil
549
609
  )
550
610
  Async do
551
611
  payload = { type: NewsChannel.channel_type }
@@ -566,7 +626,8 @@ module Discorb
566
626
  end
567
627
  payload[:nsfw] = nsfw unless nsfw.nil?
568
628
  payload[:parent_id] = parent&.id
569
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post), payload, audit_log_reason: reason).wait
629
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post),
630
+ payload, audit_log_reason: reason).wait
570
631
  Channel.make_channel(@client, data)
571
632
  end
572
633
  end
@@ -579,7 +640,8 @@ module Discorb
579
640
  #
580
641
  def fetch_active_threads
581
642
  Async do
582
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/threads/active", "//guilds/:guild_id/threads/active", :get)).wait
643
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/threads/active",
644
+ "//guilds/:guild_id/threads/active", :get)).wait
583
645
  data[:threads].map { |t| Channel.make_thread(@client, t) }
584
646
  end
585
647
  end
@@ -595,7 +657,8 @@ module Discorb
595
657
  #
596
658
  def fetch_member(id)
597
659
  Async do
598
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/members/#{id}", "//guilds/:guild_id/members/:user_id", :get)).wait
660
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/members/#{id}",
661
+ "//guilds/:guild_id/members/:user_id", :get)).wait
599
662
  rescue Discorb::NotFoundError
600
663
  nil
601
664
  else
@@ -615,14 +678,24 @@ module Discorb
615
678
  def fetch_members(limit: 0, after: nil)
616
679
  Async do
617
680
  unless limit.zero?
618
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/members?#{URI.encode_www_form({ after: after, limit: limit })}", "//guilds/:guild_id/members", :get)).wait
681
+ _resp, data = @client.http.request(
682
+ Route.new(
683
+ "/guilds/#{@id}/members?#{URI.encode_www_form(
684
+ {
685
+ after: after,
686
+ limit: limit,
687
+ }
688
+ )}", "//guilds/:guild_id/members", :get
689
+ )
690
+ ).wait
619
691
  next data[:members].map { |m| Member.new(@client, @id, m[:user], m) }
620
692
  end
621
693
  ret = []
622
694
  after = 0
623
695
  loop do
624
696
  params = { after: after, limit: 100 }
625
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/members?#{URI.encode_www_form(params)}", "//guilds/:guild_id/members", :get)).wait
697
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/members?#{URI.encode_www_form(params)}",
698
+ "//guilds/:guild_id/members", :get)).wait
626
699
  ret += data.map { |m| Member.new(@client, @id, m[:user], m) }
627
700
  after = data.last[:user][:id]
628
701
  break if data.length != 1000
@@ -644,7 +717,16 @@ module Discorb
644
717
  #
645
718
  def fetch_members_named(name, limit: 1)
646
719
  Async do
647
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/members/search?#{URI.encode_www_form({ query: name, limit: limit })}", "//guilds/:guild_id/members/search", :get)).wait
720
+ _resp, data = @client.http.request(
721
+ Route.new(
722
+ "/guilds/#{@id}/members/search?#{URI.encode_www_form(
723
+ {
724
+ query: name,
725
+ limit: limit,
726
+ }
727
+ )}", "//guilds/:guild_id/members/search", :get
728
+ )
729
+ ).wait
648
730
  data.map { |d| Member.new(@client, @id, d[:user], d) }
649
731
  end
650
732
  end
@@ -673,7 +755,10 @@ module Discorb
673
755
  #
674
756
  def edit_nickname(nickname, reason: nil)
675
757
  Async do
676
- @client.http.request(Route.new("/guilds/#{@id}/members/@me/nick", "//guilds/:guild_id/members/@me/nick", :patch), { nick: nickname }, audit_log_reason: reason).wait
758
+ @client.http.request(
759
+ Route.new("/guilds/#{@id}/members/@me/nick", "//guilds/:guild_id/members/@me/nick",
760
+ :patch), { nick: nickname }, audit_log_reason: reason,
761
+ ).wait
677
762
  end
678
763
  end
679
764
 
@@ -692,7 +777,10 @@ module Discorb
692
777
  #
693
778
  def kick_member(member, reason: nil)
694
779
  Async do
695
- @client.http.request(Route.new("/guilds/#{@id}/members/#{member.id}", "//guilds/:guild_id/members/:user_id", :delete), audit_log_reason: reason).wait
780
+ @client.http.request(
781
+ Route.new("/guilds/#{@id}/members/#{member.id}", "//guilds/:guild_id/members/:user_id",
782
+ :delete), {}, audit_log_reason: reason,
783
+ ).wait
696
784
  end
697
785
  end
698
786
 
@@ -700,12 +788,24 @@ module Discorb
700
788
  # Fetch a list of bans in the guild.
701
789
  # @async
702
790
  #
791
+ # @param [Integer] limit The number of bans to fetch.
792
+ # @param [Discorb::Snowflake] before The ID of the ban to fetch before.
793
+ # @param [Discorb::Snowflake] after The ID of the ban to fetch after.
794
+ # @param [Discorb::Snowflake] around The ID of the ban to fetch around.
795
+ #
703
796
  # @return [Async::Task<Array<Discorb::Guild::Ban>>] The list of bans.
704
797
  #
705
- def fetch_bans
798
+ def fetch_bans(limit = 50, before: nil, after: nil, around: nil)
706
799
  Async do
707
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/bans", "//guilds/:guild_id/bans", :get)).wait
708
- data.map { |d| Ban.new(@client, self, d) }
800
+ params = {
801
+ limit: limit,
802
+ before: Discorb::Utils.try(after, :id),
803
+ after: Discorb::Utils.try(around, :id),
804
+ around: Discorb::Utils.try(before, :id),
805
+ }.filter { |_k, v| !v.nil? }.to_h
806
+ _resp, bans = @client.http.request(Route.new("/guilds/#{@id}/bans?#{URI.encode_www_form(params)}",
807
+ "//guilds/:guild_id/bans", :get)).wait
808
+ bans.map { |d| Ban.new(@client, self, d) }
709
809
  end
710
810
  end
711
811
 
@@ -720,7 +820,8 @@ module Discorb
720
820
  #
721
821
  def fetch_ban(user)
722
822
  Async do
723
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/bans/#{user.id}", "//guilds/:guild_id/bans/:user_id", :get)).wait
823
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/bans/#{user.id}",
824
+ "//guilds/:guild_id/bans/:user_id", :get)).wait
724
825
  rescue Discorb::NotFoundError
725
826
  nil
726
827
  else
@@ -754,7 +855,15 @@ module Discorb
754
855
  #
755
856
  def ban_member(member, delete_message_days: 0, reason: nil)
756
857
  Async do
757
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/bans", "//guilds/:guild_id/bans", :post), { user: member.id, delete_message_days: delete_message_days }, audit_log_reason: reason).wait
858
+ _resp, data = @client.http.request(
859
+ Route.new("/guilds/#{@id}/bans",
860
+ "//guilds/:guild_id/bans",
861
+ :post),
862
+ {
863
+ user: member.id,
864
+ delete_message_days: delete_message_days,
865
+ }, audit_log_reason: reason,
866
+ ).wait
758
867
  Ban.new(@client, self, data)
759
868
  end
760
869
  end
@@ -770,7 +879,8 @@ module Discorb
770
879
  #
771
880
  def unban_user(user, reason: nil)
772
881
  Async do
773
- @client.http.request(Route.new("/guilds/#{@id}/bans/#{user.id}", "//guilds/:guild_id/bans/:user_id", :delete), audit_log_reason: reason).wait
882
+ @client.http.request(Route.new("/guilds/#{@id}/bans/#{user.id}", "//guilds/:guild_id/bans/:user_id", :delete),
883
+ {}, audit_log_reason: reason).wait
774
884
  end
775
885
  end
776
886
 
@@ -806,7 +916,8 @@ module Discorb
806
916
  payload[:color] = color.to_i if color
807
917
  payload[:hoist] = hoist if hoist
808
918
  payload[:mentionable] = mentionable if mentionable
809
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/roles", "//guilds/:guild_id/roles", :post), payload, audit_log_reason: reason).wait
919
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/roles", "//guilds/:guild_id/roles", :post),
920
+ payload, audit_log_reason: reason).wait
810
921
  Role.new(@client, self, data)
811
922
  end
812
923
  end
@@ -827,7 +938,8 @@ module Discorb
827
938
  include_roles: @id.to_s,
828
939
  }
829
940
  param[:include_roles] = roles.map(&:id).map(&:to_s).join(";") if roles.any?
830
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/prune?#{URI.encode_www_form(params)}", "//guilds/:guild_id/prune", :get)).wait
941
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/prune?#{URI.encode_www_form(params)}",
942
+ "//guilds/:guild_id/prune", :get)).wait
831
943
  data[:pruned]
832
944
  end
833
945
  end
@@ -844,7 +956,8 @@ module Discorb
844
956
  #
845
957
  def prune(days = 7, roles: [], reason: nil)
846
958
  Async do
847
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/prune", "//guilds/:guild_id/prune", :post), { days: days, roles: roles.map(&:id) }, audit_log_reason: reason).wait
959
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/prune", "//guilds/:guild_id/prune", :post),
960
+ { days: days, roles: roles.map(&:id) }, audit_log_reason: reason).wait
848
961
  data[:pruned]
849
962
  end
850
963
  end
@@ -858,7 +971,7 @@ module Discorb
858
971
  def fetch_voice_regions
859
972
  Async do
860
973
  _resp, data = @client.http.request(Route.new("/guilds/#{@id}/voice", "//guilds/:guild_id/voice", :get)).wait
861
- data.map { |d| VoiceRegion.new(@client, d) }
974
+ data.map { |d| VoiceRegion.new(d) }
862
975
  end
863
976
  end
864
977
 
@@ -871,7 +984,7 @@ module Discorb
871
984
  def fetch_invites
872
985
  Async do
873
986
  _resp, data = @client.http.request(Route.new("/guilds/#{@id}/invites", "//guilds/:guild_id/invites", :get)).wait
874
- data.map { |d| Invite.new(@client, d) }
987
+ data.map { |d| Invite.new(@client, d, false) }
875
988
  end
876
989
  end
877
990
 
@@ -883,8 +996,9 @@ module Discorb
883
996
  #
884
997
  def fetch_integrations
885
998
  Async do
886
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/integrations", "//guilds/:guild_id/integrations", :get)).wait
887
- data.map { |d| Integration.new(@client, d) }
999
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/integrations", "//guilds/:guild_id/integrations",
1000
+ :get)).wait
1001
+ data.map { |d| Integration.new(@client, d, @id) }
888
1002
  end
889
1003
  end
890
1004
 
@@ -909,7 +1023,8 @@ module Discorb
909
1023
  #
910
1024
  def fetch_vanity_invite
911
1025
  Async do
912
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/vanity-url", "//guilds/:guild_id/vanity-url", :get)).wait
1026
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/vanity-url", "//guilds/:guild_id/vanity-url",
1027
+ :get)).wait
913
1028
  VanityInvite.new(@client, self, data)
914
1029
  end
915
1030
  end
@@ -922,7 +1037,8 @@ module Discorb
922
1037
  #
923
1038
  def fetch_welcome_screen
924
1039
  Async do
925
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/welcome-screen", "//guilds/:guild_id/welcome-screen", :get)).wait
1040
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/welcome-screen",
1041
+ "//guilds/:guild_id/welcome-screen", :get)).wait
926
1042
  WelcomeScreen.new(@client, self, data)
927
1043
  end
928
1044
  end
@@ -935,7 +1051,8 @@ module Discorb
935
1051
  #
936
1052
  def fetch_stickers
937
1053
  Async do
938
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/stickers", "//guilds/:guild_id/stickers", :get)).wait
1054
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/stickers", "//guilds/:guild_id/stickers",
1055
+ :get)).wait
939
1056
  data.map { |d| Sticker::GuildSticker.new(@client, d) }
940
1057
  end
941
1058
  end
@@ -951,7 +1068,8 @@ module Discorb
951
1068
  #
952
1069
  def fetch_sticker(id)
953
1070
  Async do
954
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/stickers/#{id}", "//guilds/:guild_id/stickers/:sticker_id", :get)).wait
1071
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/stickers/#{id}",
1072
+ "//guilds/:guild_id/stickers/:sticker_id", :get)).wait
955
1073
  rescue Discorb::NotFoundError
956
1074
  nil
957
1075
  else
@@ -967,7 +1085,8 @@ module Discorb
967
1085
  #
968
1086
  def fetch_templates
969
1087
  Async do
970
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/templates", "//guilds/:guild_id/templates", :get)).wait
1088
+ _resp, data = @client.http.request(Route.new("/guilds/#{@id}/templates", "//guilds/:guild_id/templates",
1089
+ :get)).wait
971
1090
  data.map { |d| GuildTemplate.new(@client, d) }
972
1091
  end
973
1092
  end
@@ -995,7 +1114,10 @@ module Discorb
995
1114
  #
996
1115
  def create_template(name, description = nil, reason: nil)
997
1116
  Async do
998
- _resp, data = @client.http.request(Route.new("/guilds/#{@id}/templates", "//guilds/:guild_id/templates", :post), { name: name, description: description }, audit_log_reason: reason).wait
1117
+ _resp, data = @client.http.request(
1118
+ Route.new("/guilds/#{@id}/templates", "//guilds/:guild_id/templates",
1119
+ :post), { name: name, description: description }, audit_log_reason: reason,
1120
+ ).wait
999
1121
  GuildTemplate.new(@client, data)
1000
1122
  end
1001
1123
  end
@@ -1012,7 +1134,14 @@ module Discorb
1012
1134
  # @!attribute [r] url
1013
1135
  # @return [String] The vanity URL.
1014
1136
 
1137
+ #
1138
+ # Initialize a new instance of the {VanityInvite} class.
1015
1139
  # @private
1140
+ #
1141
+ # @param [Discorb::Client] client The client.
1142
+ # @param [Discorb::Guild] guild The guild.
1143
+ # @param [Hash] data The data of the invite.
1144
+ #
1016
1145
  def initialize(client, guild, data)
1017
1146
  @client = client
1018
1147
  @guild = guild
@@ -1047,7 +1176,14 @@ module Discorb
1047
1176
  # @!attribute [r] json_url
1048
1177
  # @return [String] The JSON URL.
1049
1178
 
1179
+ #
1180
+ # Initialize a new instance of the {Widget} class.
1050
1181
  # @private
1182
+ #
1183
+ # @param [Discorb::Client] client The client.
1184
+ # @param [Discorb::Snowflake] guild_id The guild ID.
1185
+ # @param [Hash] data The data from Discord.
1186
+ #
1051
1187
  def initialize(client, guild_id, data)
1052
1188
  @client = client
1053
1189
  @enabled = data[:enabled]
@@ -1075,7 +1211,8 @@ module Discorb
1075
1211
  payload = {}
1076
1212
  payload[:enabled] = enabled unless enabled.nil?
1077
1213
  payload[:channel_id] = channel.id if channel_id
1078
- @client.http.request(Route.new("/guilds/#{@guild_id}/widget", "//guilds/:guild_id/widget", :patch), payload, audit_log_reason: reason).wait
1214
+ @client.http.request(Route.new("/guilds/#{@guild_id}/widget", "//guilds/:guild_id/widget", :patch), payload,
1215
+ audit_log_reason: reason).wait
1079
1216
  end
1080
1217
  end
1081
1218
 
@@ -1095,10 +1232,12 @@ module Discorb
1095
1232
  # @return [String] The iframe HTML.
1096
1233
  #
1097
1234
  def iframe(theme: "dark", width: 350, height: 500)
1235
+ # rubocop:disable Layout/LineLength
1098
1236
  [
1099
1237
  %(<iframe src="https://canary.discord.com/widget?id=#{@guild_id}&theme=#{theme}" width="#{width}" height="#{height}"),
1100
- %(allowtransparency="true" frameborder="0" sandbox="allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"></iframe>)
1238
+ %(allowtransparency="true" frameborder="0" sandbox="allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"></iframe>),
1101
1239
  ].join
1240
+ # rubocop:enable Layout/LineLength
1102
1241
  end
1103
1242
  end
1104
1243
 
@@ -1111,19 +1250,27 @@ module Discorb
1111
1250
  # @return [String] The reason for the ban.
1112
1251
  attr_reader :reason
1113
1252
 
1253
+ #
1254
+ # Initialize a new instance of the {Ban} class.
1114
1255
  # @private
1256
+ #
1257
+ # @param [Discorb::Client] client The client.
1258
+ # @param [Discorb::Guild] guild The guild.
1259
+ # @param [Hash] data The data from Discord.
1260
+ #
1115
1261
  def initialize(client, guild, data)
1116
1262
  @client = client
1117
1263
  @guild = guild
1118
1264
  @reason = data[:reason]
1119
1265
  @user = @client.users[data[:user][:id]] || User.new(@client, data[:user])
1120
1266
  end
1267
+
1268
+ def inspect
1269
+ "<#{self.class.name} #{@user}>"
1270
+ end
1121
1271
  end
1122
1272
 
1123
1273
  class << self
1124
- # @private
1125
- attr_reader :nsfw_levels, :mfa_levels, :verification_levels, :default_message_notifications, :explicit_content_filter
1126
-
1127
1274
  #
1128
1275
  # Returns a banner url from the guild's ID.
1129
1276
  #
@@ -1151,10 +1298,11 @@ module Discorb
1151
1298
  @name = data[:name]
1152
1299
  @members = Discorb::Dictionary.new
1153
1300
  data[:members]&.each do |m|
1154
- Member.new(@client, @id, m[:user], m)
1155
- end
1301
+ Member.new(@client, @id, m[:user], m)
1302
+ end
1156
1303
  @splash = data[:splash] && Asset.new(self, data[:splash], path: "splashes/#{@id}")
1157
- @discovery_splash = data[:discovery_splash] && Asset.new(self, data[:discovery_splash], path: "discovery-splashes/#{@id}")
1304
+ @discovery_splash = data[:discovery_splash] && Asset.new(self, data[:discovery_splash],
1305
+ path: "discovery-splashes/#{@id}")
1158
1306
  @owner_id = data[:owner_id]
1159
1307
  @permissions = Permission.new(data[:permissions].to_i)
1160
1308
  @afk_channel_id = data[:afk_channel_id]
@@ -1170,10 +1318,10 @@ module Discorb
1170
1318
  @emojis[e[:id]] = CustomEmoji.new(@client, self, e)
1171
1319
  end
1172
1320
  @features = data[:features].map { |f| f.downcase.to_sym }
1173
- @mfa_level = self.class.mfa_levels[data[:mfa_level]]
1174
- @verification_level = self.class.verification_levels[data[:verification_level]]
1175
- @default_message_notifications = self.class.default_message_notifications[data[:default_message_notifications]]
1176
- @explicit_content_filter = self.class.explicit_content_filter[data[:explicit_content_filter]]
1321
+ @mfa_level = MFA_LEVELS[data[:mfa_level]]
1322
+ @verification_level = VERIFICATION_LEVELS[data[:verification_level]]
1323
+ @default_message_notifications = DEFAULT_MESSAGE_NOTIFICATIONS[data[:default_message_notifications]]
1324
+ @explicit_content_filter = EXPLICIT_CONTENT_FILTER[data[:explicit_content_filter]]
1177
1325
  @system_channel_id = data[:system_channel_id]
1178
1326
  @system_channel_flag = SystemChannelFlag.new(0b111 - data[:system_channel_flags])
1179
1327
  @rules_channel_id = data[:rules_channel_id]
@@ -1188,7 +1336,7 @@ module Discorb
1188
1336
  @approximate_member_count = data[:approximate_member_count]
1189
1337
  @approximate_presence_count = data[:approximate_presence_count]
1190
1338
  @welcome_screen = data[:welcome_screen].nil? ? nil : WelcomeScreen.new(@client, self, data[:welcome_screen])
1191
- @nsfw_level = self.class.nsfw_levels[data[:nsfw_level]]
1339
+ @nsfw_level = NSFW_LEVELS[data[:nsfw_level]]
1192
1340
  return unless is_create_event
1193
1341
 
1194
1342
  @stickers = data[:stickers].nil? ? [] : data[:stickers].map { |s| Sticker::GuildSticker.new(self, s) }
@@ -1199,12 +1347,20 @@ module Discorb
1199
1347
  Channel.make_channel(@client, c.merge({ guild_id: @id }))
1200
1348
  end
1201
1349
  @channels = Dictionary.new(tmp_channels.to_h { |c| [c.id, c] }, sort: ->(c) { c[1].position })
1202
- @voice_states = Dictionary.new(data[:voice_states].to_h { |v| [Snowflake.new(v[:user_id]), VoiceState.new(@client, v.merge({ guild_id: @id }))] })
1350
+ @voice_states = Dictionary.new(data[:voice_states].to_h do |v|
1351
+ [Snowflake.new(v[:user_id]), VoiceState.new(@client, v.merge({ guild_id: @id }))]
1352
+ end)
1203
1353
  @threads = data[:threads] ? data[:threads].map { |t| Channel.make_channel(@client, t) } : []
1204
- @presences = Dictionary.new(data[:presences].to_h { |pr| [Snowflake.new(pr[:user][:id]), Presence.new(@client, pr)] })
1354
+ @presences = Dictionary.new(data[:presences].to_h do |pr|
1355
+ [Snowflake.new(pr[:user][:id]), Presence.new(@client, pr)]
1356
+ end)
1205
1357
  @max_presences = data[:max_presences]
1206
- @stage_instances = Dictionary.new(data[:stage_instances].to_h { |s| [Snowflake.new(s[:id]), StageInstance.new(@client, s)] })
1207
- @scheduled_events = Dictionary.new(data[:guild_scheduled_events].to_h { |s| [Snowflake.new(s[:id]), ScheduledEvent.new(@client, s)] })
1358
+ @stage_instances = Dictionary.new(data[:stage_instances].to_h do |s|
1359
+ [Snowflake.new(s[:id]), StageInstance.new(@client, s)]
1360
+ end)
1361
+ @scheduled_events = Dictionary.new(data[:guild_scheduled_events].to_h do |s|
1362
+ [Snowflake.new(s[:id]), ScheduledEvent.new(@client, s)]
1363
+ end)
1208
1364
  @data.update(data)
1209
1365
  end
1210
1366
  end
@@ -1239,7 +1395,14 @@ module Discorb
1239
1395
  # @return [Discorb::Guild] The guild the welcome screen belongs to.
1240
1396
  attr_reader :guild
1241
1397
 
1398
+ #
1399
+ # Initializes the welcome screen.
1242
1400
  # @private
1401
+ #
1402
+ # @param [Discorb::Client] client The client.
1403
+ # @param [Discorb::Guild] guild The guild the welcome screen belongs to.
1404
+ # @param [Hash] data The data of the welcome screen.
1405
+ #
1243
1406
  def initialize(client, guild, data)
1244
1407
  @client = client
1245
1408
  @description = data[:description]
@@ -1333,7 +1496,10 @@ module Discorb
1333
1496
  payload[:enabled] = enabled unless enabled == Discorb::Unset
1334
1497
  payload[:welcome_channels] = channels.map(&:to_hash) unless channels == Discorb::Unset
1335
1498
  payload[:description] = description unless description == Discorb::Unset
1336
- @client.http.request(Route.new("/guilds/#{@guild.id}/welcome-screen", "//guilds/:guild_id/welcome-screen", :patch), payload, audit_log_reason: reason).wait
1499
+ @client.http.request(
1500
+ Route.new("/guilds/#{@guild.id}/welcome-screen", "//guilds/:guild_id/welcome-screen",
1501
+ :patch), payload, audit_log_reason: reason,
1502
+ ).wait
1337
1503
  end
1338
1504
  end
1339
1505
  end