discorb 0.16.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +1 -0
- data/.github/workflows/build_main.yml +2 -2
- data/.github/workflows/build_version.yml +1 -1
- data/.github/workflows/codeql-analysis.yml +1 -1
- data/.github/workflows/lint-push.yml +3 -5
- data/.github/workflows/lint.yml +2 -4
- data/.github/workflows/spec.yml +33 -0
- data/.github/workflows/validate.yml +21 -0
- data/.gitignore +2 -0
- data/.lefthook/commit-msg/validator.rb +5 -0
- data/.rspec +2 -0
- data/.rspec_parallel +2 -0
- data/.rubocop.yml +43 -6
- data/Changelog.md +30 -1
- data/Gemfile +20 -8
- data/Rakefile +226 -98
- data/Steepfile +28 -0
- data/bin/console +3 -3
- data/docs/Examples.md +1 -1
- data/docs/application_command.md +156 -47
- data/docs/cli/irb.md +2 -2
- data/docs/cli/new.md +14 -9
- data/docs/cli/run.md +7 -11
- data/docs/cli.md +17 -10
- data/docs/events.md +247 -213
- data/docs/extension.md +1 -2
- data/docs/faq.md +0 -1
- data/docs/tutorial.md +18 -18
- data/docs/voice_events.md +106 -106
- data/examples/commands/message.rb +68 -0
- data/examples/commands/permission.rb +19 -0
- data/examples/commands/slash.rb +48 -0
- data/examples/commands/user.rb +54 -0
- data/examples/components/authorization_button.rb +4 -3
- data/examples/components/select_menu.rb +6 -3
- data/examples/extension/main.rb +2 -1
- data/examples/extension/message_expander.rb +6 -2
- data/examples/sig/commands/message.rbs +5 -0
- data/examples/simple/eval.rb +3 -2
- data/examples/simple/ping_pong.rb +2 -1
- data/examples/simple/rolepanel.rb +17 -6
- data/examples/simple/shard.rb +3 -2
- data/examples/simple/wait_for_message.rb +4 -1
- data/exe/discorb +33 -18
- data/lefthook.yml +45 -0
- data/lib/discorb/allowed_mentions.rb +2 -1
- data/lib/discorb/app_command/command.rb +130 -72
- data/lib/discorb/app_command/common.rb +25 -0
- data/lib/discorb/app_command/handler.rb +130 -33
- data/lib/discorb/app_command.rb +2 -1
- data/lib/discorb/application.rb +1 -0
- data/lib/discorb/asset.rb +1 -2
- data/lib/discorb/attachment.rb +1 -1
- data/lib/discorb/audit_logs.rb +19 -10
- data/lib/discorb/automod.rb +269 -0
- data/lib/discorb/channel/base.rb +108 -0
- data/lib/discorb/channel/category.rb +32 -0
- data/lib/discorb/channel/container.rb +44 -0
- data/lib/discorb/channel/dm.rb +28 -0
- data/lib/discorb/channel/guild.rb +246 -0
- data/lib/discorb/channel/stage.rb +140 -0
- data/lib/discorb/channel/text.rb +336 -0
- data/lib/discorb/channel/thread.rb +325 -0
- data/lib/discorb/channel/voice.rb +79 -0
- data/lib/discorb/channel.rb +2 -1165
- data/lib/discorb/client.rb +50 -36
- data/lib/discorb/color.rb +37 -60
- data/lib/discorb/common.rb +2 -1
- data/lib/discorb/components/button.rb +2 -1
- data/lib/discorb/components/select_menu.rb +4 -2
- data/lib/discorb/components/text_input.rb +12 -2
- data/lib/discorb/components.rb +1 -1
- data/lib/discorb/dictionary.rb +1 -1
- data/lib/discorb/embed.rb +26 -10
- data/lib/discorb/emoji.rb +31 -4
- data/lib/discorb/emoji_table.rb +4969 -3
- data/lib/discorb/event.rb +29 -4
- data/lib/discorb/exe/about.rb +2 -1
- data/lib/discorb/exe/irb.rb +2 -4
- data/lib/discorb/exe/new.rb +89 -26
- data/lib/discorb/exe/run.rb +8 -22
- data/lib/discorb/exe/setup.rb +25 -12
- data/lib/discorb/exe/show.rb +4 -3
- data/lib/discorb/extend.rb +1 -0
- data/lib/discorb/extension.rb +6 -7
- data/lib/discorb/flag.rb +13 -2
- data/lib/discorb/gateway.rb +79 -589
- data/lib/discorb/gateway_events.rb +638 -0
- data/lib/discorb/guild.rb +318 -67
- data/lib/discorb/guild_template.rb +11 -5
- data/lib/discorb/http.rb +53 -24
- data/lib/discorb/integration.rb +4 -1
- data/lib/discorb/intents.rb +28 -19
- data/lib/discorb/interaction/autocomplete.rb +28 -16
- data/lib/discorb/interaction/command.rb +42 -14
- data/lib/discorb/interaction/components.rb +5 -2
- data/lib/discorb/interaction/modal.rb +0 -1
- data/lib/discorb/interaction/response.rb +125 -26
- data/lib/discorb/interaction/root.rb +13 -13
- data/lib/discorb/interaction.rb +1 -0
- data/lib/discorb/invite.rb +5 -2
- data/lib/discorb/member.rb +28 -8
- data/lib/discorb/message.rb +60 -25
- data/lib/discorb/message_meta.rb +3 -3
- data/lib/discorb/modules.rb +59 -16
- data/lib/discorb/presence.rb +2 -0
- data/lib/discorb/rate_limit.rb +7 -2
- data/lib/discorb/reaction.rb +2 -2
- data/lib/discorb/role.rb +20 -5
- data/lib/discorb/shard.rb +1 -1
- data/lib/discorb/sticker.rb +9 -8
- data/lib/discorb/user.rb +4 -3
- data/lib/discorb/utils/colored_puts.rb +1 -0
- data/lib/discorb/voice_state.rb +6 -2
- data/lib/discorb/webhook.rb +64 -31
- data/lib/discorb.rb +7 -5
- data/po/yard.pot +20 -20
- data/rbs_collection.lock.yaml +88 -0
- data/rbs_collection.yaml +21 -0
- data/sig/async.rbs +11 -0
- data/sig/discorb/activity.rbs +23 -0
- data/sig/discorb/allowed_mentions.rbs +44 -0
- data/sig/discorb/app_command/base.rbs +282 -0
- data/sig/discorb/app_command/handler.rbs +171 -0
- data/sig/discorb/application.rbs +142 -0
- data/sig/discorb/asset.rbs +32 -0
- data/sig/discorb/attachment.rbs +91 -0
- data/sig/discorb/audit_log.rbs +231 -0
- data/sig/discorb/automod.rbs +128 -0
- data/sig/discorb/avatar.rbs +26 -0
- data/sig/discorb/channel/base.rbs +179 -0
- data/sig/discorb/channel/category.rbs +56 -0
- data/sig/discorb/channel/container.rbs +29 -0
- data/sig/discorb/channel/dm.rbs +14 -0
- data/sig/discorb/channel/news.rbs +20 -0
- data/sig/discorb/channel/stage.rbs +77 -0
- data/sig/discorb/channel/text.rbs +158 -0
- data/sig/discorb/channel/thread.rbs +185 -0
- data/sig/discorb/channel/voice.rbs +41 -0
- data/sig/discorb/client.rbs +2495 -0
- data/sig/discorb/color.rbs +142 -0
- data/sig/discorb/component/base.rbs +28 -0
- data/sig/discorb/component/button.rbs +65 -0
- data/sig/discorb/component/select_menu.rbs +107 -0
- data/sig/discorb/component/text_input.rbs +69 -0
- data/sig/discorb/connectable.rbs +8 -0
- data/sig/discorb/custom_emoji.rbs +90 -0
- data/sig/discorb/dictionary.rbs +85 -0
- data/sig/discorb/discord_model.rbs +15 -0
- data/sig/discorb/embed.rbs +279 -0
- data/sig/discorb/emoji.rbs +13 -0
- data/sig/discorb/error.rbs +73 -0
- data/sig/discorb/event_handler.rbs +27 -0
- data/sig/discorb/extension.rbs +1734 -0
- data/sig/discorb/flag.rbs +72 -0
- data/sig/discorb/gateway.rbs +481 -0
- data/sig/discorb/guild.rbs +870 -0
- data/sig/discorb/guild_template.rbs +174 -0
- data/sig/discorb/http.rbs +147 -0
- data/sig/discorb/image.rbs +20 -0
- data/sig/discorb/integration.rbs +118 -0
- data/sig/discorb/intents.rbs +97 -0
- data/sig/discorb/interaction/autocomplete.rbs +9 -0
- data/sig/discorb/interaction/base.rbs +66 -0
- data/sig/discorb/interaction/command.rbs +66 -0
- data/sig/discorb/interaction/message_component.rbs +140 -0
- data/sig/discorb/interaction/modal.rbs +50 -0
- data/sig/discorb/interaction/responder.rbs +157 -0
- data/sig/discorb/invite.rbs +86 -0
- data/sig/discorb/member.rbs +187 -0
- data/sig/discorb/message.rbs +469 -0
- data/sig/discorb/messageable.rbs +153 -0
- data/sig/discorb/partial_emoji.rbs +35 -0
- data/sig/discorb/permissions.rbs +149 -0
- data/sig/discorb/presence.rbs +237 -0
- data/sig/discorb/reaction.rbs +33 -0
- data/sig/discorb/role.rbs +145 -0
- data/sig/discorb/scheduled_event.rbs +148 -0
- data/sig/discorb/shard.rbs +62 -0
- data/sig/discorb/snowflake.rbs +56 -0
- data/sig/discorb/stage_instance.rbs +63 -0
- data/sig/discorb/sticker.rbs +116 -0
- data/sig/discorb/system_channel_flag.rbs +17 -0
- data/sig/discorb/unicode_emoji.rbs +49 -0
- data/sig/discorb/user.rbs +93 -0
- data/sig/discorb/utils.rbs +8 -0
- data/sig/discorb/voice_region.rbs +30 -0
- data/sig/discorb/voice_state.rbs +71 -0
- data/sig/discorb/webhook.rbs +327 -0
- data/sig/discorb/welcome_screen.rbs +78 -0
- data/sig/discorb.rbs +6 -7230
- data/sig/manifest.yaml +3 -0
- data/sig/override.rbs +19 -0
- data/template-replace/files/css/common.css +4 -0
- metadata +102 -6
- data/examples/commands/bookmarker.rb +0 -42
- data/examples/commands/hello.rb +0 -10
- data/examples/commands/inspect.rb +0 -25
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}]
|
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}]
|
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
|
@@ -193,7 +197,13 @@ module Discorb
|
|
193
197
|
#
|
194
198
|
def fetch_scheduled_events(with_user_count: true)
|
195
199
|
Async do
|
196
|
-
_resp, events = @client.http.request(
|
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
|
197
207
|
@scheduled_events = events.map { |e| ScheduledEvent.new(@client, e) }
|
198
208
|
end
|
199
209
|
end
|
@@ -209,10 +219,13 @@ module Discorb
|
|
209
219
|
#
|
210
220
|
def fetch_scheduled_event(id)
|
211
221
|
Async do
|
212
|
-
_resp, event = @client.http.request(
|
213
|
-
|
214
|
-
|
215
|
-
|
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
|
216
229
|
ScheduledEvent.new(@client, event)
|
217
230
|
end
|
218
231
|
end
|
@@ -246,6 +259,7 @@ module Discorb
|
|
246
259
|
payload = case type
|
247
260
|
when :stage_instance
|
248
261
|
raise ArgumentError, "channel must be provided for stage_instance events" unless channel
|
262
|
+
|
249
263
|
{
|
250
264
|
name: name,
|
251
265
|
description: description,
|
@@ -257,6 +271,7 @@ module Discorb
|
|
257
271
|
}
|
258
272
|
when :voice
|
259
273
|
raise ArgumentError, "channel must be provided for voice events" unless channel
|
274
|
+
|
260
275
|
{
|
261
276
|
name: name,
|
262
277
|
description: description,
|
@@ -269,6 +284,7 @@ module Discorb
|
|
269
284
|
when :external
|
270
285
|
raise ArgumentError, "location must be provided for external events" unless location
|
271
286
|
raise ArgumentError, "end_time must be provided for external events" unless end_time
|
287
|
+
|
272
288
|
{
|
273
289
|
name: name,
|
274
290
|
description: description,
|
@@ -283,7 +299,9 @@ module Discorb
|
|
283
299
|
else
|
284
300
|
raise ArgumentError, "Invalid scheduled event type: #{type}"
|
285
301
|
end
|
286
|
-
_resp, event = @client.http.request(
|
302
|
+
_resp, event = @client.http.request(
|
303
|
+
Route.new("/guilds/#{@id}/scheduled-events", "//guilds/:guild_id/scheduled-events", :post), payload
|
304
|
+
).wait
|
287
305
|
Discorb::ScheduledEvent.new(@client, event)
|
288
306
|
end
|
289
307
|
end
|
@@ -293,7 +311,8 @@ module Discorb
|
|
293
311
|
# @async
|
294
312
|
# @note This querys the API every time. We recommend using {#emojis} instead.
|
295
313
|
#
|
296
|
-
# @return [Async::Task<Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}>]
|
314
|
+
# @return [Async::Task<Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}>]
|
315
|
+
# A dictionary of emoji in the guild.
|
297
316
|
#
|
298
317
|
def fetch_emoji_list
|
299
318
|
Async do
|
@@ -321,8 +340,16 @@ module Discorb
|
|
321
340
|
# @return [Async::Task<Discorb::CustomEmoji>] The emoji with the given id.
|
322
341
|
#
|
323
342
|
def fetch_emoji(id)
|
324
|
-
|
325
|
-
|
343
|
+
Async do
|
344
|
+
_resp, data = @client.http.request(
|
345
|
+
Route.new(
|
346
|
+
"/guilds/#{@id}/emojis/#{id}",
|
347
|
+
"//guilds/:guild_id/emojis/:emoji_id",
|
348
|
+
:get
|
349
|
+
)
|
350
|
+
).wait
|
351
|
+
@emojis[e[:id]] = CustomEmoji.new(@client, self, data)
|
352
|
+
end
|
326
353
|
end
|
327
354
|
|
328
355
|
#
|
@@ -336,13 +363,17 @@ module Discorb
|
|
336
363
|
# @return [Async::Task<Discorb::CustomEmoji>] The created emoji.
|
337
364
|
#
|
338
365
|
def create_emoji(name, image, roles: [])
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
366
|
+
Async do
|
367
|
+
_resp, data = @client.http.request(
|
368
|
+
Route.new("/guilds/#{@id}/emojis", "//guilds/:guild_id/emojis", :post),
|
369
|
+
{
|
370
|
+
name: name,
|
371
|
+
image: image.to_s,
|
372
|
+
roles: roles.map { |r| Discorb::Utils.try(r, :id) },
|
373
|
+
}
|
374
|
+
).wait
|
375
|
+
@emojis[data[:id]] = CustomEmoji.new(@client, self, data)
|
376
|
+
end
|
346
377
|
end
|
347
378
|
|
348
379
|
#
|
@@ -353,8 +384,9 @@ module Discorb
|
|
353
384
|
#
|
354
385
|
def fetch_webhooks
|
355
386
|
Async do
|
356
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/webhooks", "//guilds/:guild_id/webhooks",
|
357
|
-
|
387
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/webhooks", "//guilds/:guild_id/webhooks",
|
388
|
+
:get)).wait
|
389
|
+
data.map { |webhook| Webhook.from_data(@client, webhook) }
|
358
390
|
end
|
359
391
|
end
|
360
392
|
|
@@ -366,7 +398,8 @@ module Discorb
|
|
366
398
|
#
|
367
399
|
def fetch_audit_log
|
368
400
|
Async do
|
369
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/audit-logs", "//guilds/:guild_id/audit-logs",
|
401
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/audit-logs", "//guilds/:guild_id/audit-logs",
|
402
|
+
:get)).wait
|
370
403
|
AuditLog.new(@client, data, self)
|
371
404
|
end
|
372
405
|
end
|
@@ -379,7 +412,8 @@ module Discorb
|
|
379
412
|
#
|
380
413
|
def fetch_channels
|
381
414
|
Async do
|
382
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels",
|
415
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels",
|
416
|
+
:get)).wait
|
383
417
|
data.map { |c| Channel.make_channel(@client, c) }
|
384
418
|
end
|
385
419
|
end
|
@@ -394,14 +428,23 @@ module Discorb
|
|
394
428
|
# @param [Integer] slowmode Alias for `rate_limit_per_user`.
|
395
429
|
# @param [Integer] position The position of the channel.
|
396
430
|
# @param [Boolean] nsfw Whether the channel is nsfw.
|
397
|
-
# @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
|
431
|
+
# @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
|
432
|
+
# A list of permission overwrites.
|
398
433
|
# @param [Discorb::CategoryChannel] parent The parent of the channel.
|
399
434
|
# @param [String] reason The reason for creating the channel.
|
400
435
|
#
|
401
436
|
# @return [Async::Task<Discorb::TextChannel>] The created text channel.
|
402
437
|
#
|
403
438
|
def create_text_channel(
|
404
|
-
name,
|
439
|
+
name,
|
440
|
+
topic: nil,
|
441
|
+
rate_limit_per_user: nil,
|
442
|
+
slowmode: nil,
|
443
|
+
position: nil,
|
444
|
+
nsfw: nil,
|
445
|
+
permission_overwrites: nil,
|
446
|
+
parent: nil,
|
447
|
+
reason: nil
|
405
448
|
)
|
406
449
|
Async do
|
407
450
|
payload = { type: TextChannel.channel_type }
|
@@ -422,7 +465,8 @@ module Discorb
|
|
422
465
|
end
|
423
466
|
end
|
424
467
|
payload[:parent_id] = parent.id if parent
|
425
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post),
|
468
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post),
|
469
|
+
payload, audit_log_reason: reason).wait
|
426
470
|
payload[:parent_id] = parent&.id
|
427
471
|
Channel.make_channel(@client, data)
|
428
472
|
end
|
@@ -436,7 +480,8 @@ module Discorb
|
|
436
480
|
# @param [Integer] bitrate The bitrate of the channel.
|
437
481
|
# @param [Integer] user_limit The user limit of the channel.
|
438
482
|
# @param [Integer] position The position of the channel.
|
439
|
-
# @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
|
483
|
+
# @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
|
484
|
+
# A list of permission overwrites.
|
440
485
|
# @param [Discorb::CategoryChannel] parent The parent of the channel.
|
441
486
|
# @param [String] reason The reason for creating the channel.
|
442
487
|
#
|
@@ -462,7 +507,8 @@ module Discorb
|
|
462
507
|
end
|
463
508
|
end
|
464
509
|
payload[:parent_id] = parent.id if parent
|
465
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post),
|
510
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post),
|
511
|
+
payload, audit_log_reason: reason).wait
|
466
512
|
payload[:parent_id] = parent&.id
|
467
513
|
Channel.make_channel(@client, data)
|
468
514
|
end
|
@@ -473,7 +519,8 @@ module Discorb
|
|
473
519
|
#
|
474
520
|
# @param [String] name The name of the channel.
|
475
521
|
# @param [Integer] position The position of the channel.
|
476
|
-
# @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
|
522
|
+
# @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
|
523
|
+
# A list of permission overwrites.
|
477
524
|
# @param [Discorb::CategoryChannel] parent The parent of the channel.
|
478
525
|
# @param [String] reason The reason for creating the channel.
|
479
526
|
#
|
@@ -495,7 +542,8 @@ module Discorb
|
|
495
542
|
end
|
496
543
|
end
|
497
544
|
payload[:parent_id] = parent&.id
|
498
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post),
|
545
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post),
|
546
|
+
payload, audit_log_reason: reason).wait
|
499
547
|
Channel.make_channel(@client, data)
|
500
548
|
end
|
501
549
|
end
|
@@ -509,7 +557,8 @@ module Discorb
|
|
509
557
|
# @param [String] name The name of the channel.
|
510
558
|
# @param [Integer] bitrate The bitrate of the channel.
|
511
559
|
# @param [Integer] position The position of the channel.
|
512
|
-
# @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
|
560
|
+
# @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
|
561
|
+
# A list of permission overwrites.
|
513
562
|
# @param [Discorb::CategoryChannel] parent The parent of the channel.
|
514
563
|
# @param [String] reason The reason for creating the channel.
|
515
564
|
#
|
@@ -532,7 +581,8 @@ module Discorb
|
|
532
581
|
end
|
533
582
|
end
|
534
583
|
payload[:parent_id] = parent&.id
|
535
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post),
|
584
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post),
|
585
|
+
payload, audit_log_reason: reason).wait
|
536
586
|
Channel.make_channel(@client, data)
|
537
587
|
end
|
538
588
|
end
|
@@ -547,14 +597,23 @@ module Discorb
|
|
547
597
|
# @param [Integer] slowmode Alias for `rate_limit_per_user`.
|
548
598
|
# @param [Integer] position The position of the channel.
|
549
599
|
# @param [Boolean] nsfw Whether the channel is nsfw.
|
550
|
-
# @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
|
600
|
+
# @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
|
601
|
+
# A list of permission overwrites.
|
551
602
|
# @param [Discorb::CategoryChannel] parent The parent of the channel.
|
552
603
|
# @param [String] reason The reason for creating the channel.
|
553
604
|
#
|
554
605
|
# @return [Async::Task<Discorb::NewsChannel>] The created news channel.
|
555
606
|
#
|
556
607
|
def create_news_channel(
|
557
|
-
name,
|
608
|
+
name,
|
609
|
+
topic: nil,
|
610
|
+
rate_limit_per_user: nil,
|
611
|
+
slowmode: nil,
|
612
|
+
position: nil,
|
613
|
+
nsfw: nil,
|
614
|
+
permission_overwrites: nil,
|
615
|
+
parent: nil,
|
616
|
+
reason: nil
|
558
617
|
)
|
559
618
|
Async do
|
560
619
|
payload = { type: NewsChannel.channel_type }
|
@@ -575,7 +634,8 @@ module Discorb
|
|
575
634
|
end
|
576
635
|
payload[:nsfw] = nsfw unless nsfw.nil?
|
577
636
|
payload[:parent_id] = parent&.id
|
578
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post),
|
637
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post),
|
638
|
+
payload, audit_log_reason: reason).wait
|
579
639
|
Channel.make_channel(@client, data)
|
580
640
|
end
|
581
641
|
end
|
@@ -588,7 +648,8 @@ module Discorb
|
|
588
648
|
#
|
589
649
|
def fetch_active_threads
|
590
650
|
Async do
|
591
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/threads/active",
|
651
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/threads/active",
|
652
|
+
"//guilds/:guild_id/threads/active", :get)).wait
|
592
653
|
data[:threads].map { |t| Channel.make_thread(@client, t) }
|
593
654
|
end
|
594
655
|
end
|
@@ -604,7 +665,8 @@ module Discorb
|
|
604
665
|
#
|
605
666
|
def fetch_member(id)
|
606
667
|
Async do
|
607
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/members/#{id}",
|
668
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/members/#{id}",
|
669
|
+
"//guilds/:guild_id/members/:user_id", :get)).wait
|
608
670
|
rescue Discorb::NotFoundError
|
609
671
|
nil
|
610
672
|
else
|
@@ -624,17 +686,27 @@ module Discorb
|
|
624
686
|
def fetch_members(limit: 0, after: nil)
|
625
687
|
Async do
|
626
688
|
unless limit.zero?
|
627
|
-
_resp, data = @client.http.request(
|
689
|
+
_resp, data = @client.http.request(
|
690
|
+
Route.new(
|
691
|
+
"/guilds/#{@id}/members?#{URI.encode_www_form(
|
692
|
+
{
|
693
|
+
after: after,
|
694
|
+
limit: limit,
|
695
|
+
}
|
696
|
+
)}", "//guilds/:guild_id/members", :get
|
697
|
+
)
|
698
|
+
).wait
|
628
699
|
next data[:members].map { |m| Member.new(@client, @id, m[:user], m) }
|
629
700
|
end
|
630
701
|
ret = []
|
631
702
|
after = 0
|
632
703
|
loop do
|
633
704
|
params = { after: after, limit: 100 }
|
634
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/members?#{URI.encode_www_form(params)}",
|
705
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/members?#{URI.encode_www_form(params)}",
|
706
|
+
"//guilds/:guild_id/members", :get)).wait
|
635
707
|
ret += data.map { |m| Member.new(@client, @id, m[:user], m) }
|
636
708
|
after = data.last[:user][:id]
|
637
|
-
break if data.length !=
|
709
|
+
break if data.length != 100
|
638
710
|
end
|
639
711
|
ret
|
640
712
|
end
|
@@ -653,7 +725,16 @@ module Discorb
|
|
653
725
|
#
|
654
726
|
def fetch_members_named(name, limit: 1)
|
655
727
|
Async do
|
656
|
-
_resp, data = @client.http.request(
|
728
|
+
_resp, data = @client.http.request(
|
729
|
+
Route.new(
|
730
|
+
"/guilds/#{@id}/members/search?#{URI.encode_www_form(
|
731
|
+
{
|
732
|
+
query: name,
|
733
|
+
limit: limit,
|
734
|
+
}
|
735
|
+
)}", "//guilds/:guild_id/members/search", :get
|
736
|
+
)
|
737
|
+
).wait
|
657
738
|
data.map { |d| Member.new(@client, @id, d[:user], d) }
|
658
739
|
end
|
659
740
|
end
|
@@ -682,7 +763,10 @@ module Discorb
|
|
682
763
|
#
|
683
764
|
def edit_nickname(nickname, reason: nil)
|
684
765
|
Async do
|
685
|
-
@client.http.request(
|
766
|
+
@client.http.request(
|
767
|
+
Route.new("/guilds/#{@id}/members/@me/nick", "//guilds/:guild_id/members/@me/nick",
|
768
|
+
:patch), { nick: nickname }, audit_log_reason: reason,
|
769
|
+
).wait
|
686
770
|
end
|
687
771
|
end
|
688
772
|
|
@@ -701,7 +785,10 @@ module Discorb
|
|
701
785
|
#
|
702
786
|
def kick_member(member, reason: nil)
|
703
787
|
Async do
|
704
|
-
@client.http.request(
|
788
|
+
@client.http.request(
|
789
|
+
Route.new("/guilds/#{@id}/members/#{member.id}", "//guilds/:guild_id/members/:user_id",
|
790
|
+
:delete), {}, audit_log_reason: reason,
|
791
|
+
).wait
|
705
792
|
end
|
706
793
|
end
|
707
794
|
|
@@ -709,12 +796,24 @@ module Discorb
|
|
709
796
|
# Fetch a list of bans in the guild.
|
710
797
|
# @async
|
711
798
|
#
|
799
|
+
# @param [Integer] limit The number of bans to fetch.
|
800
|
+
# @param [Discorb::Snowflake] before The ID of the ban to fetch before.
|
801
|
+
# @param [Discorb::Snowflake] after The ID of the ban to fetch after.
|
802
|
+
# @param [Discorb::Snowflake] around The ID of the ban to fetch around.
|
803
|
+
#
|
712
804
|
# @return [Async::Task<Array<Discorb::Guild::Ban>>] The list of bans.
|
713
805
|
#
|
714
|
-
def fetch_bans
|
806
|
+
def fetch_bans(limit = 50, before: nil, after: nil, around: nil)
|
715
807
|
Async do
|
716
|
-
|
717
|
-
|
808
|
+
params = {
|
809
|
+
limit: limit,
|
810
|
+
before: Discorb::Utils.try(after, :id),
|
811
|
+
after: Discorb::Utils.try(around, :id),
|
812
|
+
around: Discorb::Utils.try(before, :id),
|
813
|
+
}.filter { |_k, v| !v.nil? }.to_h
|
814
|
+
_resp, bans = @client.http.request(Route.new("/guilds/#{@id}/bans?#{URI.encode_www_form(params)}",
|
815
|
+
"//guilds/:guild_id/bans", :get)).wait
|
816
|
+
bans.map { |d| Ban.new(@client, self, d) }
|
718
817
|
end
|
719
818
|
end
|
720
819
|
|
@@ -729,7 +828,8 @@ module Discorb
|
|
729
828
|
#
|
730
829
|
def fetch_ban(user)
|
731
830
|
Async do
|
732
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/bans/#{user.id}",
|
831
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/bans/#{user.id}",
|
832
|
+
"//guilds/:guild_id/bans/:user_id", :get)).wait
|
733
833
|
rescue Discorb::NotFoundError
|
734
834
|
nil
|
735
835
|
else
|
@@ -763,7 +863,15 @@ module Discorb
|
|
763
863
|
#
|
764
864
|
def ban_member(member, delete_message_days: 0, reason: nil)
|
765
865
|
Async do
|
766
|
-
_resp, data = @client.http.request(
|
866
|
+
_resp, data = @client.http.request(
|
867
|
+
Route.new("/guilds/#{@id}/bans",
|
868
|
+
"//guilds/:guild_id/bans",
|
869
|
+
:post),
|
870
|
+
{
|
871
|
+
user: member.id,
|
872
|
+
delete_message_days: delete_message_days,
|
873
|
+
}, audit_log_reason: reason,
|
874
|
+
).wait
|
767
875
|
Ban.new(@client, self, data)
|
768
876
|
end
|
769
877
|
end
|
@@ -779,7 +887,8 @@ module Discorb
|
|
779
887
|
#
|
780
888
|
def unban_user(user, reason: nil)
|
781
889
|
Async do
|
782
|
-
@client.http.request(Route.new("/guilds/#{@id}/bans/#{user.id}", "//guilds/:guild_id/bans/:user_id", :delete),
|
890
|
+
@client.http.request(Route.new("/guilds/#{@id}/bans/#{user.id}", "//guilds/:guild_id/bans/:user_id", :delete),
|
891
|
+
{}, audit_log_reason: reason).wait
|
783
892
|
end
|
784
893
|
end
|
785
894
|
|
@@ -815,7 +924,8 @@ module Discorb
|
|
815
924
|
payload[:color] = color.to_i if color
|
816
925
|
payload[:hoist] = hoist if hoist
|
817
926
|
payload[:mentionable] = mentionable if mentionable
|
818
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/roles", "//guilds/:guild_id/roles", :post),
|
927
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/roles", "//guilds/:guild_id/roles", :post),
|
928
|
+
payload, audit_log_reason: reason).wait
|
819
929
|
Role.new(@client, self, data)
|
820
930
|
end
|
821
931
|
end
|
@@ -836,7 +946,8 @@ module Discorb
|
|
836
946
|
include_roles: @id.to_s,
|
837
947
|
}
|
838
948
|
param[:include_roles] = roles.map(&:id).map(&:to_s).join(";") if roles.any?
|
839
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/prune?#{URI.encode_www_form(params)}",
|
949
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/prune?#{URI.encode_www_form(params)}",
|
950
|
+
"//guilds/:guild_id/prune", :get)).wait
|
840
951
|
data[:pruned]
|
841
952
|
end
|
842
953
|
end
|
@@ -853,7 +964,8 @@ module Discorb
|
|
853
964
|
#
|
854
965
|
def prune(days = 7, roles: [], reason: nil)
|
855
966
|
Async do
|
856
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/prune", "//guilds/:guild_id/prune", :post),
|
967
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/prune", "//guilds/:guild_id/prune", :post),
|
968
|
+
{ days: days, roles: roles.map(&:id) }, audit_log_reason: reason).wait
|
857
969
|
data[:pruned]
|
858
970
|
end
|
859
971
|
end
|
@@ -892,7 +1004,8 @@ module Discorb
|
|
892
1004
|
#
|
893
1005
|
def fetch_integrations
|
894
1006
|
Async do
|
895
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/integrations", "//guilds/:guild_id/integrations",
|
1007
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/integrations", "//guilds/:guild_id/integrations",
|
1008
|
+
:get)).wait
|
896
1009
|
data.map { |d| Integration.new(@client, d, @id) }
|
897
1010
|
end
|
898
1011
|
end
|
@@ -918,7 +1031,8 @@ module Discorb
|
|
918
1031
|
#
|
919
1032
|
def fetch_vanity_invite
|
920
1033
|
Async do
|
921
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/vanity-url", "//guilds/:guild_id/vanity-url",
|
1034
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/vanity-url", "//guilds/:guild_id/vanity-url",
|
1035
|
+
:get)).wait
|
922
1036
|
VanityInvite.new(@client, self, data)
|
923
1037
|
end
|
924
1038
|
end
|
@@ -931,7 +1045,8 @@ module Discorb
|
|
931
1045
|
#
|
932
1046
|
def fetch_welcome_screen
|
933
1047
|
Async do
|
934
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/welcome-screen",
|
1048
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/welcome-screen",
|
1049
|
+
"//guilds/:guild_id/welcome-screen", :get)).wait
|
935
1050
|
WelcomeScreen.new(@client, self, data)
|
936
1051
|
end
|
937
1052
|
end
|
@@ -944,7 +1059,8 @@ module Discorb
|
|
944
1059
|
#
|
945
1060
|
def fetch_stickers
|
946
1061
|
Async do
|
947
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/stickers", "//guilds/:guild_id/stickers",
|
1062
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/stickers", "//guilds/:guild_id/stickers",
|
1063
|
+
:get)).wait
|
948
1064
|
data.map { |d| Sticker::GuildSticker.new(@client, d) }
|
949
1065
|
end
|
950
1066
|
end
|
@@ -960,7 +1076,8 @@ module Discorb
|
|
960
1076
|
#
|
961
1077
|
def fetch_sticker(id)
|
962
1078
|
Async do
|
963
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/stickers/#{id}",
|
1079
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/stickers/#{id}",
|
1080
|
+
"//guilds/:guild_id/stickers/:sticker_id", :get)).wait
|
964
1081
|
rescue Discorb::NotFoundError
|
965
1082
|
nil
|
966
1083
|
else
|
@@ -976,7 +1093,8 @@ module Discorb
|
|
976
1093
|
#
|
977
1094
|
def fetch_templates
|
978
1095
|
Async do
|
979
|
-
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/templates", "//guilds/:guild_id/templates",
|
1096
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/templates", "//guilds/:guild_id/templates",
|
1097
|
+
:get)).wait
|
980
1098
|
data.map { |d| GuildTemplate.new(@client, d) }
|
981
1099
|
end
|
982
1100
|
end
|
@@ -1004,11 +1122,108 @@ module Discorb
|
|
1004
1122
|
#
|
1005
1123
|
def create_template(name, description = nil, reason: nil)
|
1006
1124
|
Async do
|
1007
|
-
_resp, data = @client.http.request(
|
1125
|
+
_resp, data = @client.http.request(
|
1126
|
+
Route.new("/guilds/#{@id}/templates", "//guilds/:guild_id/templates",
|
1127
|
+
:post), { name: name, description: description }, audit_log_reason: reason,
|
1128
|
+
).wait
|
1008
1129
|
GuildTemplate.new(@client, data)
|
1009
1130
|
end
|
1010
1131
|
end
|
1011
1132
|
|
1133
|
+
#
|
1134
|
+
# Fetch the automod rules in the guild.
|
1135
|
+
# @async
|
1136
|
+
#
|
1137
|
+
# @return [Async::Task<Array<Discorb::AutoModRule>>] The automod rules.
|
1138
|
+
#
|
1139
|
+
def fetch_automod_rules
|
1140
|
+
Async do
|
1141
|
+
_resp, data = @client.http.request(
|
1142
|
+
Route.new("/guilds/#{@id}/auto-moderation/rules", "//guilds/:guild_id/auto-moderation/rules", :get)
|
1143
|
+
)
|
1144
|
+
data.map { |d| AutoModRule.new(@client, d) }
|
1145
|
+
end
|
1146
|
+
end
|
1147
|
+
|
1148
|
+
alias fetch_automod_rule_list fetch_automod_rules
|
1149
|
+
|
1150
|
+
#
|
1151
|
+
# Fetch the automod rule by ID.
|
1152
|
+
#
|
1153
|
+
# @param [#to_s] id The ID of the automod rule.
|
1154
|
+
#
|
1155
|
+
# @return [Async::Task<Array<Discord::AutoModRule>>] The automod rule.
|
1156
|
+
#
|
1157
|
+
def fetch_automod_rule(id)
|
1158
|
+
Async do
|
1159
|
+
_resp, data = @client.http.request(
|
1160
|
+
Route.new(
|
1161
|
+
"/guilds/#{@id}/auto-moderation/rules/#{id}",
|
1162
|
+
"//guilds/:guild_id/auto-moderation/rules/:rule_id",
|
1163
|
+
:get
|
1164
|
+
)
|
1165
|
+
).wait
|
1166
|
+
AutoModRule.new(@client, data)
|
1167
|
+
end
|
1168
|
+
end
|
1169
|
+
|
1170
|
+
#
|
1171
|
+
# Create a new automod rule in the guild.
|
1172
|
+
# @async
|
1173
|
+
#
|
1174
|
+
# @param [String] name The name of the rule.
|
1175
|
+
# @param [Symbol] trigger_type The trigger type of the rule. See {Discorb::AutoModRule::TRIGGER_TYPES}.
|
1176
|
+
# @param [Array<Discorb::AutoModRule::Action>] actions The actions of the rule.
|
1177
|
+
# @param [Symbol] event_type The event type of the rule. See {Discorb::AutoModRule::EVENT_TYPES}.
|
1178
|
+
# @param [Boolean] enabled Whether the rule is enabled or not.
|
1179
|
+
# @param [Array<Discorb::Role>] exempt_roles The roles that are exempt from the rule.
|
1180
|
+
# @param [Array<Discorb::Channel>] exempt_channels The channels that are exempt from the rule.
|
1181
|
+
# @param [Array<String>] keyword_filter The keywords to filter.
|
1182
|
+
# @param [Symbol] presets The preset of the rule. See {Discorb::AutoModRule::PRESET_TYPES}.
|
1183
|
+
# @param [String] reason The reason for creating the rule.
|
1184
|
+
#
|
1185
|
+
# @return [Async::Task<Discorb::AutoModRule>] The automod rule.
|
1186
|
+
#
|
1187
|
+
def create_automod_rule(
|
1188
|
+
name,
|
1189
|
+
trigger_type,
|
1190
|
+
actions,
|
1191
|
+
event_type = :send_message,
|
1192
|
+
enabled: false,
|
1193
|
+
exempt_roles: [],
|
1194
|
+
exempt_channels: [],
|
1195
|
+
keyword_filter: nil,
|
1196
|
+
presets: nil,
|
1197
|
+
reason: nil
|
1198
|
+
)
|
1199
|
+
Async do
|
1200
|
+
payload = {
|
1201
|
+
name: name,
|
1202
|
+
event_type: Discorb::AutoModRule::EVENT_TYPES.key(event_type),
|
1203
|
+
trigger_type: Discorb::AutoModRule::TRIGGER_TYPES.key(trigger_type),
|
1204
|
+
metadata: {
|
1205
|
+
keyword_filter: keyword_filter,
|
1206
|
+
presets: Discorb::AutoModRule::PRESET_TYPES.key(presets),
|
1207
|
+
},
|
1208
|
+
actions: actions.map(&:to_hash),
|
1209
|
+
enabled: enabled,
|
1210
|
+
exempt_roles: exempt_roles.map(&:id),
|
1211
|
+
exempt_channels: exempt_channels.map(&:id),
|
1212
|
+
}
|
1213
|
+
|
1214
|
+
_resp, data = @client.http.request(
|
1215
|
+
Route.new(
|
1216
|
+
"/guilds/#{@id}/auto-moderation/rules",
|
1217
|
+
"//guilds/:guild_id/auto-moderation/rules",
|
1218
|
+
:post
|
1219
|
+
),
|
1220
|
+
payload,
|
1221
|
+
audit_log_reason: reason
|
1222
|
+
)
|
1223
|
+
Discorb::AutoModRule.new(@client, data)
|
1224
|
+
end
|
1225
|
+
end
|
1226
|
+
|
1012
1227
|
#
|
1013
1228
|
# Represents a vanity invite.
|
1014
1229
|
#
|
@@ -1098,7 +1313,8 @@ module Discorb
|
|
1098
1313
|
payload = {}
|
1099
1314
|
payload[:enabled] = enabled unless enabled.nil?
|
1100
1315
|
payload[:channel_id] = channel.id if channel_id
|
1101
|
-
@client.http.request(Route.new("/guilds/#{@guild_id}/widget", "//guilds/:guild_id/widget", :patch), payload,
|
1316
|
+
@client.http.request(Route.new("/guilds/#{@guild_id}/widget", "//guilds/:guild_id/widget", :patch), payload,
|
1317
|
+
audit_log_reason: reason).wait
|
1102
1318
|
end
|
1103
1319
|
end
|
1104
1320
|
|
@@ -1118,10 +1334,12 @@ module Discorb
|
|
1118
1334
|
# @return [String] The iframe HTML.
|
1119
1335
|
#
|
1120
1336
|
def iframe(theme: "dark", width: 350, height: 500)
|
1337
|
+
# rubocop:disable Layout/LineLength
|
1121
1338
|
[
|
1122
1339
|
%(<iframe src="https://canary.discord.com/widget?id=#{@guild_id}&theme=#{theme}" width="#{width}" height="#{height}"),
|
1123
1340
|
%(allowtransparency="true" frameborder="0" sandbox="allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"></iframe>),
|
1124
1341
|
].join
|
1342
|
+
# rubocop:enable Layout/LineLength
|
1125
1343
|
end
|
1126
1344
|
end
|
1127
1345
|
|
@@ -1148,6 +1366,10 @@ module Discorb
|
|
1148
1366
|
@reason = data[:reason]
|
1149
1367
|
@user = @client.users[data[:user][:id]] || User.new(@client, data[:user])
|
1150
1368
|
end
|
1369
|
+
|
1370
|
+
def inspect
|
1371
|
+
"<#{self.class.name} #{@user}>"
|
1372
|
+
end
|
1151
1373
|
end
|
1152
1374
|
|
1153
1375
|
class << self
|
@@ -1181,7 +1403,8 @@ module Discorb
|
|
1181
1403
|
Member.new(@client, @id, m[:user], m)
|
1182
1404
|
end
|
1183
1405
|
@splash = data[:splash] && Asset.new(self, data[:splash], path: "splashes/#{@id}")
|
1184
|
-
@discovery_splash = data[:discovery_splash] && Asset.new(self, data[:discovery_splash],
|
1406
|
+
@discovery_splash = data[:discovery_splash] && Asset.new(self, data[:discovery_splash],
|
1407
|
+
path: "discovery-splashes/#{@id}")
|
1185
1408
|
@owner_id = data[:owner_id]
|
1186
1409
|
@permissions = Permission.new(data[:permissions].to_i)
|
1187
1410
|
@afk_channel_id = data[:afk_channel_id]
|
@@ -1218,7 +1441,7 @@ module Discorb
|
|
1218
1441
|
@nsfw_level = NSFW_LEVELS[data[:nsfw_level]]
|
1219
1442
|
return unless is_create_event
|
1220
1443
|
|
1221
|
-
@stickers = data[:stickers].nil? ? [] : data[:stickers].map { |s| Sticker::GuildSticker.new(
|
1444
|
+
@stickers = data[:stickers].nil? ? [] : data[:stickers].map { |s| Sticker::GuildSticker.new(@client, s) }
|
1222
1445
|
@joined_at = Time.iso8601(data[:joined_at])
|
1223
1446
|
@large = data[:large]
|
1224
1447
|
@member_count = data[:member_count]
|
@@ -1226,12 +1449,20 @@ module Discorb
|
|
1226
1449
|
Channel.make_channel(@client, c.merge({ guild_id: @id }))
|
1227
1450
|
end
|
1228
1451
|
@channels = Dictionary.new(tmp_channels.to_h { |c| [c.id, c] }, sort: ->(c) { c[1].position })
|
1229
|
-
@voice_states = Dictionary.new(data[:voice_states].to_h
|
1452
|
+
@voice_states = Dictionary.new(data[:voice_states].to_h do |v|
|
1453
|
+
[Snowflake.new(v[:user_id]), VoiceState.new(@client, v.merge({ guild_id: @id }))]
|
1454
|
+
end)
|
1230
1455
|
@threads = data[:threads] ? data[:threads].map { |t| Channel.make_channel(@client, t) } : []
|
1231
|
-
@presences = Dictionary.new(data[:presences].to_h
|
1456
|
+
@presences = Dictionary.new(data[:presences].to_h do |pr|
|
1457
|
+
[Snowflake.new(pr[:user][:id]), Presence.new(@client, pr)]
|
1458
|
+
end)
|
1232
1459
|
@max_presences = data[:max_presences]
|
1233
|
-
@stage_instances = Dictionary.new(data[:stage_instances].to_h
|
1234
|
-
|
1460
|
+
@stage_instances = Dictionary.new(data[:stage_instances].to_h do |s|
|
1461
|
+
[Snowflake.new(s[:id]), StageInstance.new(@client, s)]
|
1462
|
+
end)
|
1463
|
+
@scheduled_events = Dictionary.new(data[:guild_scheduled_events].to_h do |s|
|
1464
|
+
[Snowflake.new(s[:id]), ScheduledEvent.new(@client, s)]
|
1465
|
+
end)
|
1235
1466
|
@data.update(data)
|
1236
1467
|
end
|
1237
1468
|
end
|
@@ -1278,7 +1509,24 @@ module Discorb
|
|
1278
1509
|
@client = client
|
1279
1510
|
@description = data[:description]
|
1280
1511
|
@guild = guild
|
1281
|
-
@channels = data[:channels].map
|
1512
|
+
@channels = data[:channels].map do |c|
|
1513
|
+
WelcomeScreen::Channel.new(
|
1514
|
+
client.channels[c[:channel_id]],
|
1515
|
+
c,
|
1516
|
+
c[:emoji_name] &&
|
1517
|
+
if c[:emoji_id]
|
1518
|
+
(client.emojis[c[:emoji_id]] ||
|
1519
|
+
Discorb::PartialEmoji.new(
|
1520
|
+
{
|
1521
|
+
name: c[:emoji_name],
|
1522
|
+
id: c[:emoji_id],
|
1523
|
+
}
|
1524
|
+
))
|
1525
|
+
else
|
1526
|
+
Discorb::UnicodeEmoji.new(c[:emoji_name])
|
1527
|
+
end
|
1528
|
+
)
|
1529
|
+
end
|
1282
1530
|
end
|
1283
1531
|
|
1284
1532
|
#
|
@@ -1367,7 +1615,10 @@ module Discorb
|
|
1367
1615
|
payload[:enabled] = enabled unless enabled == Discorb::Unset
|
1368
1616
|
payload[:welcome_channels] = channels.map(&:to_hash) unless channels == Discorb::Unset
|
1369
1617
|
payload[:description] = description unless description == Discorb::Unset
|
1370
|
-
@client.http.request(
|
1618
|
+
@client.http.request(
|
1619
|
+
Route.new("/guilds/#{@guild.id}/welcome-screen", "//guilds/:guild_id/welcome-screen",
|
1620
|
+
:patch), payload, audit_log_reason: reason,
|
1621
|
+
).wait
|
1371
1622
|
end
|
1372
1623
|
end
|
1373
1624
|
end
|