discorb 0.13.0 → 0.13.4
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.
- checksums.yaml +4 -4
- data/.github/workflows/build_main.yml +1 -0
- data/.github/workflows/build_version.yml +4 -3
- data/.github/workflows/crowdin.yml +32 -0
- data/.gitignore +3 -1
- data/.yardopts +2 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/Changelog.md +420 -388
- data/Gemfile +5 -1
- data/README.md +2 -2
- data/Rakefile +131 -1
- data/crowdin.yml +2 -0
- data/discorb.gemspec +12 -1
- data/docs/Examples.md +2 -0
- data/docs/application_command.md +7 -5
- data/docs/cli/irb.md +2 -0
- data/docs/cli/new.md +2 -0
- data/docs/cli/run.md +3 -1
- data/docs/cli/setup.md +4 -2
- data/docs/cli.md +2 -0
- data/docs/events.md +6 -4
- data/docs/extension.md +2 -2
- data/docs/faq.md +4 -2
- data/docs/license.md +2 -0
- data/docs/tutorial.md +4 -3
- data/docs/voice_events.md +2 -0
- data/lib/discorb/app_command.rb +32 -9
- data/lib/discorb/application.rb +1 -1
- data/lib/discorb/asset.rb +1 -1
- data/lib/discorb/channel.rb +170 -125
- data/lib/discorb/client.rb +20 -22
- data/lib/discorb/common.rb +32 -1
- data/lib/discorb/dictionary.rb +10 -2
- data/lib/discorb/emoji.rb +7 -9
- data/lib/discorb/emoji_table.rb +3891 -3891
- data/lib/discorb/event.rb +12 -11
- data/lib/discorb/exe/show.rb +2 -0
- data/lib/discorb/extension.rb +1 -1
- data/lib/discorb/flag.rb +1 -1
- data/lib/discorb/gateway.rb +63 -17
- data/lib/discorb/guild.rb +110 -156
- data/lib/discorb/guild_template.rb +15 -12
- data/lib/discorb/http.rb +41 -136
- data/lib/discorb/integration.rb +34 -2
- data/lib/discorb/interaction/autocomplete.rb +1 -1
- data/lib/discorb/interaction/response.rb +34 -32
- data/lib/discorb/interaction/root.rb +8 -0
- data/lib/discorb/invite.rb +4 -3
- data/lib/discorb/log.rb +3 -2
- data/lib/discorb/member.rb +44 -15
- data/lib/discorb/message.rb +33 -22
- data/lib/discorb/modules.rb +28 -35
- data/lib/discorb/presence.rb +2 -2
- data/lib/discorb/rate_limit.rb +14 -18
- data/lib/discorb/role.rb +18 -14
- data/lib/discorb/sticker.rb +10 -14
- data/lib/discorb/user.rb +10 -10
- data/lib/discorb/voice_state.rb +12 -7
- data/lib/discorb/webhook.rb +44 -50
- data/lib/discorb.rb +1 -1
- data/po/yard.pot +7772 -5154
- data/sig/discorb.rbs +3316 -3819
- data/template-replace/scripts/locale_ja.rb +62 -0
- metadata +18 -5
data/lib/discorb/guild.rb
CHANGED
@@ -28,7 +28,7 @@ module Discorb
|
|
28
28
|
attr_reader :features
|
29
29
|
# @return [:none, :elevated] The MFA level of the guild.
|
30
30
|
attr_reader :mfa_level
|
31
|
-
# @return [Discorb::
|
31
|
+
# @return [Discorb::SystemChannelFlag] The flag for the system channel.
|
32
32
|
attr_reader :system_channel_flags
|
33
33
|
# @return [Time] Time that representing when bot has joined the guild.
|
34
34
|
attr_reader :joined_at
|
@@ -162,20 +162,20 @@ module Discorb
|
|
162
162
|
|
163
163
|
#
|
164
164
|
# Leave the guild.
|
165
|
-
# @
|
166
|
-
#
|
165
|
+
# @async
|
166
|
+
#
|
167
|
+
# @return [Async::Task<void>] The task.
|
167
168
|
#
|
168
169
|
def leave!
|
169
170
|
Async do
|
170
|
-
@client.http.
|
171
|
+
@client.http.request(Route.new("/users/@me/guilds/#{@id}", "//users/@me/guilds/:guild_id", :delete)).wait
|
171
172
|
@client.guilds.delete(@id)
|
172
173
|
end
|
173
174
|
end
|
174
175
|
|
175
176
|
#
|
176
177
|
# Fetch scheduled events for the guild.
|
177
|
-
# @
|
178
|
-
# @macro http
|
178
|
+
# @async
|
179
179
|
#
|
180
180
|
# @param [Boolean] with_user_count Whether to include the user count in the events.
|
181
181
|
# Defaults to `true`.
|
@@ -184,24 +184,23 @@ module Discorb
|
|
184
184
|
#
|
185
185
|
def fetch_scheduled_events(with_user_count: true)
|
186
186
|
Async do
|
187
|
-
_resp, events = @client.http.
|
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
|
188
188
|
@scheduled_events = events.map { |e| ScheduledEvent.new(@client, e) }
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
192
192
|
#
|
193
193
|
# Fetch the scheduled event by ID.
|
194
|
-
# @
|
195
|
-
# @macro http
|
194
|
+
# @async
|
196
195
|
#
|
197
196
|
# @param [#to_s] id The ID of the scheduled event.
|
198
197
|
#
|
199
|
-
# @return [Discorb::ScheduledEvent] The event with the given ID.
|
200
|
-
# @return [nil] If no event with the given ID exists.
|
198
|
+
# @return [Async::Task<Discorb::ScheduledEvent>] The event with the given ID.
|
199
|
+
# @return [Async::Task<nil>] If no event with the given ID exists.
|
201
200
|
#
|
202
201
|
def fetch_scheduled_event(id)
|
203
202
|
Async do
|
204
|
-
_resp, event = @client.http.
|
203
|
+
_resp, event = @client.http.request(Route.new("/guilds/#{@id}/scheduled-events/#{id}", "//guilds/:guild_id/scheduled-events/:scheduled_event_id", :get)).wait
|
205
204
|
rescue Discorb::NotFoundError
|
206
205
|
return nil
|
207
206
|
else
|
@@ -211,6 +210,7 @@ module Discorb
|
|
211
210
|
|
212
211
|
#
|
213
212
|
# Create a scheduled event for the guild.
|
213
|
+
# @async
|
214
214
|
#
|
215
215
|
# @param [:stage_instance, :voice, :external] type The type of event to create.
|
216
216
|
# @param [String] name The name of the event.
|
@@ -221,7 +221,7 @@ module Discorb
|
|
221
221
|
# @param [String, nil] location The location of the event. Defaults to `nil`.
|
222
222
|
# @param [:guild_only] privacy_level The privacy level of the event. This must be `:guild_only`.
|
223
223
|
#
|
224
|
-
# @return [Discorb::ScheduledEvent] The created event.
|
224
|
+
# @return [Async::Task<Discorb::ScheduledEvent>] The created event.
|
225
225
|
#
|
226
226
|
def create_scheduled_event(
|
227
227
|
type,
|
@@ -274,22 +274,21 @@ module Discorb
|
|
274
274
|
else
|
275
275
|
raise ArgumentError, "Invalid scheduled event type: #{type}"
|
276
276
|
end
|
277
|
-
_resp, event = @client.http.
|
277
|
+
_resp, event = @client.http.request(Route.new("/guilds/#{@id}/scheduled-events", "//guilds/:guild_id/scheduled-events", :post), payload).wait
|
278
278
|
Discorb::ScheduledEvent.new(@client, event)
|
279
279
|
end
|
280
280
|
end
|
281
281
|
|
282
282
|
#
|
283
283
|
# Fetch emoji list of the guild.
|
284
|
-
# @
|
285
|
-
# @macro http
|
284
|
+
# @async
|
286
285
|
# @note This querys the API every time. We recommend using {#emojis} instead.
|
287
286
|
#
|
288
287
|
# @return [Async::Task<Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}>] A dictionary of emoji in the guild.
|
289
288
|
#
|
290
289
|
def fetch_emoji_list
|
291
290
|
Async do
|
292
|
-
_resp, data = @client.http.
|
291
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/emojis", "//guilds/:guild_id/emojis", :get)).wait
|
293
292
|
@emojis = Dictionary.new
|
294
293
|
ids = @emojis.map(&:id).map(&:to_s)
|
295
294
|
data.map do |e|
|
@@ -305,8 +304,7 @@ module Discorb
|
|
305
304
|
|
306
305
|
#
|
307
306
|
# Fetch emoji id of the guild.
|
308
|
-
# @
|
309
|
-
# @macro http
|
307
|
+
# @async
|
310
308
|
# @note This querys the API every time. We recommend using {#emojis} instead.
|
311
309
|
#
|
312
310
|
# @param [#to_s] id The emoji id.
|
@@ -314,14 +312,13 @@ module Discorb
|
|
314
312
|
# @return [Async::Task<Discorb::CustomEmoji>] The emoji with the given id.
|
315
313
|
#
|
316
314
|
def fetch_emoji(id)
|
317
|
-
_resp, data = @client.http.
|
315
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/emojis/#{id}", "//guilds/:guild_id/emojis/:emoji_id", :get)).wait
|
318
316
|
@emojis[e[:id]] = CustomEmoji.new(@client, self, data)
|
319
317
|
end
|
320
318
|
|
321
319
|
#
|
322
320
|
# Create a custom emoji.
|
323
|
-
# @
|
324
|
-
# @macro http
|
321
|
+
# @async
|
325
322
|
#
|
326
323
|
# @param [#to_s] name The name of the emoji.
|
327
324
|
# @param [Discorb::Image] image The image of the emoji.
|
@@ -330,63 +327,57 @@ module Discorb
|
|
330
327
|
# @return [Async::Task<Discorb::CustomEmoji>] The created emoji.
|
331
328
|
#
|
332
329
|
def create_emoji(name, image, roles: [])
|
333
|
-
_resp, data = @client.http.post
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
}
|
340
|
-
).wait
|
330
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/emojis", "//guilds/:guild_id/emojis", :post),
|
331
|
+
{
|
332
|
+
name: name,
|
333
|
+
image: image.to_s,
|
334
|
+
roles: roles.map { |r| Discorb::Utils.try(r, :id) },
|
335
|
+
}).wait
|
341
336
|
@emojis[data[:id]] = CustomEmoji.new(@client, self, data)
|
342
337
|
end
|
343
338
|
|
344
339
|
#
|
345
340
|
# Fetch webhooks of the guild.
|
346
|
-
# @
|
347
|
-
# @macro http
|
341
|
+
# @async
|
348
342
|
#
|
349
343
|
# @return [Async::Task<Array<Discorb::Webhook>>] A list of webhooks in the guild.
|
350
344
|
#
|
351
345
|
def fetch_webhooks
|
352
346
|
Async do
|
353
|
-
_resp, data = @client.http.
|
347
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/webhooks", "//guilds/:guild_id/webhooks", :get)).wait
|
354
348
|
data.map { |webhook| Webhook.new([@client, webhook]) }
|
355
349
|
end
|
356
350
|
end
|
357
351
|
|
358
352
|
#
|
359
353
|
# Fetch audit log of the guild.
|
360
|
-
# @
|
361
|
-
# @macro http
|
354
|
+
# @async
|
362
355
|
#
|
363
356
|
# @return [Async::Task<Discorb::AuditLog>] The audit log of the guild.
|
364
357
|
#
|
365
358
|
def fetch_audit_log
|
366
359
|
Async do
|
367
|
-
_resp, data = @client.http.
|
360
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/audit-logs", "//guilds/:guild_id/audit-logs", :get)).wait
|
368
361
|
AuditLog.new(@client, data, self)
|
369
362
|
end
|
370
363
|
end
|
371
364
|
|
372
365
|
#
|
373
366
|
# Fetch channels of the guild.
|
374
|
-
# @
|
375
|
-
# @macro http
|
367
|
+
# @async
|
376
368
|
#
|
377
369
|
# @return [Async::Task<Array<Discorb::Channel>>] A list of channels in the guild.
|
378
370
|
#
|
379
371
|
def fetch_channels
|
380
372
|
Async do
|
381
|
-
_resp, data = @client.http.
|
373
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :get)).wait
|
382
374
|
data.map { |c| Channel.make_channel(@client, c) }
|
383
375
|
end
|
384
376
|
end
|
385
377
|
|
386
378
|
#
|
387
379
|
# Create a new text channel.
|
388
|
-
# @
|
389
|
-
# @macro http
|
380
|
+
# @async
|
390
381
|
#
|
391
382
|
# @param [String] name The name of the channel.
|
392
383
|
# @param [String] topic The topic of the channel.
|
@@ -422,9 +413,7 @@ module Discorb
|
|
422
413
|
end
|
423
414
|
end
|
424
415
|
payload[:parent_id] = parent.id if parent
|
425
|
-
_resp, data = @client.http.post
|
426
|
-
"/guilds/#{@id}/channels", payload, audit_log_reason: reason,
|
427
|
-
).wait
|
416
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post), payload, audit_log_reason: reason).wait
|
428
417
|
payload[:parent_id] = parent&.id
|
429
418
|
Channel.make_channel(@client, data)
|
430
419
|
end
|
@@ -432,8 +421,7 @@ module Discorb
|
|
432
421
|
|
433
422
|
#
|
434
423
|
# Create a new voice channel.
|
435
|
-
# @
|
436
|
-
# @macro http
|
424
|
+
# @async
|
437
425
|
#
|
438
426
|
# @param [String] name The name of the channel.
|
439
427
|
# @param [Integer] bitrate The bitrate of the channel.
|
@@ -465,17 +453,14 @@ module Discorb
|
|
465
453
|
end
|
466
454
|
end
|
467
455
|
payload[:parent_id] = parent.id if parent
|
468
|
-
_resp, data = @client.http.post
|
469
|
-
"/guilds/#{@id}/channels", payload, audit_log_reason: reason,
|
470
|
-
).wait
|
456
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post), payload, audit_log_reason: reason).wait
|
471
457
|
payload[:parent_id] = parent&.id
|
472
458
|
Channel.make_channel(@client, data)
|
473
459
|
end
|
474
460
|
end
|
475
461
|
|
476
462
|
# Create a new category channel.
|
477
|
-
# @
|
478
|
-
# @macro http
|
463
|
+
# @async
|
479
464
|
#
|
480
465
|
# @param [String] name The name of the channel.
|
481
466
|
# @param [Integer] position The position of the channel.
|
@@ -501,9 +486,7 @@ module Discorb
|
|
501
486
|
end
|
502
487
|
end
|
503
488
|
payload[:parent_id] = parent&.id
|
504
|
-
_resp, data = @client.http.post
|
505
|
-
"/guilds/#{@id}/channels", payload, audit_log_reason: reason,
|
506
|
-
).wait
|
489
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post), payload, audit_log_reason: reason).wait
|
507
490
|
Channel.make_channel(@client, data)
|
508
491
|
end
|
509
492
|
end
|
@@ -512,8 +495,7 @@ module Discorb
|
|
512
495
|
|
513
496
|
#
|
514
497
|
# Create a new stage channel.
|
515
|
-
# @
|
516
|
-
# @macro http
|
498
|
+
# @async
|
517
499
|
#
|
518
500
|
# @param [String] name The name of the channel.
|
519
501
|
# @param [Integer] bitrate The bitrate of the channel.
|
@@ -541,17 +523,14 @@ module Discorb
|
|
541
523
|
end
|
542
524
|
end
|
543
525
|
payload[:parent_id] = parent&.id
|
544
|
-
_resp, data = @client.http.post
|
545
|
-
"/guilds/#{@id}/channels", payload, audit_log_reason: reason,
|
546
|
-
).wait
|
526
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post), payload, audit_log_reason: reason).wait
|
547
527
|
Channel.make_channel(@client, data)
|
548
528
|
end
|
549
529
|
end
|
550
530
|
|
551
531
|
#
|
552
532
|
# Create a new news channel.
|
553
|
-
# @
|
554
|
-
# @macro http
|
533
|
+
# @async
|
555
534
|
#
|
556
535
|
# @param [String] name The name of the channel.
|
557
536
|
# @param [String] topic The topic of the channel.
|
@@ -587,31 +566,27 @@ module Discorb
|
|
587
566
|
end
|
588
567
|
payload[:nsfw] = nsfw unless nsfw.nil?
|
589
568
|
payload[:parent_id] = parent&.id
|
590
|
-
_resp, data = @client.http.post
|
591
|
-
"/guilds/#{@id}/channels", payload, audit_log_reason: reason,
|
592
|
-
).wait
|
569
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/channels", "//guilds/:guild_id/channels", :post), payload, audit_log_reason: reason).wait
|
593
570
|
Channel.make_channel(@client, data)
|
594
571
|
end
|
595
572
|
end
|
596
573
|
|
597
574
|
#
|
598
575
|
# Fetch a list of active threads in the guild.
|
599
|
-
# @
|
600
|
-
# @macro http
|
576
|
+
# @async
|
601
577
|
#
|
602
578
|
# @return [Async::Task<Array<Discorb::ThreadChannel>>] The list of threads.
|
603
579
|
#
|
604
580
|
def fetch_active_threads
|
605
581
|
Async do
|
606
|
-
_resp, data = @client.http.
|
582
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/threads/active", "//guilds/:guild_id/threads/active", :get)).wait
|
607
583
|
data[:threads].map { |t| Channel.make_thread(@client, t) }
|
608
584
|
end
|
609
585
|
end
|
610
586
|
|
611
587
|
#
|
612
588
|
# Fetch a member in the guild.
|
613
|
-
# @
|
614
|
-
# @macro http
|
589
|
+
# @async
|
615
590
|
#
|
616
591
|
# @param [#to_s] id The ID of the member to fetch.
|
617
592
|
#
|
@@ -620,7 +595,7 @@ module Discorb
|
|
620
595
|
#
|
621
596
|
def fetch_member(id)
|
622
597
|
Async do
|
623
|
-
_resp, data = @client.http.
|
598
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/members/#{id}", "//guilds/:guild_id/members/:user_id", :get)).wait
|
624
599
|
rescue Discorb::NotFoundError
|
625
600
|
nil
|
626
601
|
else
|
@@ -629,8 +604,7 @@ module Discorb
|
|
629
604
|
end
|
630
605
|
|
631
606
|
# Fetch members in the guild.
|
632
|
-
# @
|
633
|
-
# @macro http
|
607
|
+
# @async
|
634
608
|
# @macro members_intent
|
635
609
|
#
|
636
610
|
# @param [Integer] limit The maximum number of members to fetch, 0 for all.
|
@@ -641,14 +615,14 @@ module Discorb
|
|
641
615
|
def fetch_members(limit: 0, after: nil)
|
642
616
|
Async do
|
643
617
|
unless limit == 0
|
644
|
-
_resp, data = @client.http.
|
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
|
645
619
|
next data[:members].map { |m| Member.new(@client, @id, m[:user], m) }
|
646
620
|
end
|
647
621
|
ret = []
|
648
622
|
after = 0
|
649
623
|
loop do
|
650
624
|
params = { after: after, limit: 100 }
|
651
|
-
_resp, data = @client.http.
|
625
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/members?#{URI.encode_www_form(params)}", "//guilds/:guild_id/members", :get)).wait
|
652
626
|
ret += data.map { |m| Member.new(@client, @id, m[:user], m) }
|
653
627
|
after = data.last[:user][:id]
|
654
628
|
if data.length != 1000
|
@@ -663,8 +637,7 @@ module Discorb
|
|
663
637
|
|
664
638
|
#
|
665
639
|
# Search for members by name in the guild.
|
666
|
-
# @
|
667
|
-
# @macro http
|
640
|
+
# @async
|
668
641
|
#
|
669
642
|
# @param [String] name The name of the member to search for.
|
670
643
|
# @param [Integer] limit The maximum number of members to return.
|
@@ -673,15 +646,14 @@ module Discorb
|
|
673
646
|
#
|
674
647
|
def fetch_members_named(name, limit: 1)
|
675
648
|
Async do
|
676
|
-
_resp, data = @client.http.
|
649
|
+
_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
|
677
650
|
data.map { |d| Member.new(@client, @id, d[:user], d) }
|
678
651
|
end
|
679
652
|
end
|
680
653
|
|
681
654
|
#
|
682
655
|
# Almost the same as {#fetch_members_named}, but returns a single member.
|
683
|
-
# @
|
684
|
-
# @macro http
|
656
|
+
# @async
|
685
657
|
#
|
686
658
|
# @return [Async::Task<Discorb::Member>] The member.
|
687
659
|
# @return [Async::Task<nil>] If the member is not found.
|
@@ -694,13 +666,16 @@ module Discorb
|
|
694
666
|
|
695
667
|
#
|
696
668
|
# Change nickname of client member.
|
669
|
+
# @async
|
697
670
|
#
|
698
671
|
# @param [String] nickname The nickname to set.
|
699
672
|
# @param [String] reason The reason for changing the nickname.
|
700
673
|
#
|
674
|
+
# @return [Async::Task<void>] The task.
|
675
|
+
#
|
701
676
|
def edit_nickname(nickname, reason: nil)
|
702
677
|
Async do
|
703
|
-
@client.http.
|
678
|
+
@client.http.request(Route.new("/guilds/#{@id}/members/@me/nick", "//guilds/:guild_id/members/@me/nick", :patch), { nick: nickname }, audit_log_reason: reason).wait
|
704
679
|
end
|
705
680
|
end
|
706
681
|
|
@@ -710,36 +685,35 @@ module Discorb
|
|
710
685
|
|
711
686
|
#
|
712
687
|
# Kick a member from the guild.
|
713
|
-
# @
|
714
|
-
# @macro http
|
688
|
+
# @async
|
715
689
|
#
|
716
690
|
# @param [Discorb::Member] member The member to kick.
|
717
691
|
# @param [String] reason The reason for kicking the member.
|
718
692
|
#
|
693
|
+
# @return [Async::Task<void>] The task.
|
694
|
+
#
|
719
695
|
def kick_member(member, reason: nil)
|
720
696
|
Async do
|
721
|
-
@client.http.
|
697
|
+
@client.http.request(Route.new("/guilds/#{@id}/members/#{member.id}", "//guilds/:guild_id/members/:user_id", :delete), audit_log_reason: reason).wait
|
722
698
|
end
|
723
699
|
end
|
724
700
|
|
725
701
|
#
|
726
702
|
# Fetch a list of bans in the guild.
|
727
|
-
# @
|
728
|
-
# @macro http
|
703
|
+
# @async
|
729
704
|
#
|
730
705
|
# @return [Async::Task<Array<Discorb::Guild::Ban>>] The list of bans.
|
731
706
|
#
|
732
707
|
def fetch_bans
|
733
708
|
Async do
|
734
|
-
_resp, data = @client.http.
|
709
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/bans", "//guilds/:guild_id/bans", :get)).wait
|
735
710
|
data.map { |d| Ban.new(@client, self, d) }
|
736
711
|
end
|
737
712
|
end
|
738
713
|
|
739
714
|
#
|
740
715
|
# Fetch a ban in the guild.
|
741
|
-
# @
|
742
|
-
# @macro http
|
716
|
+
# @async
|
743
717
|
#
|
744
718
|
# @param [Discorb::User] user The user to fetch.
|
745
719
|
#
|
@@ -748,7 +722,7 @@ module Discorb
|
|
748
722
|
#
|
749
723
|
def fetch_ban(user)
|
750
724
|
Async do
|
751
|
-
_resp, data = @client.http.
|
725
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/bans/#{user.id}", "//guilds/:guild_id/bans/:user_id", :get)).wait
|
752
726
|
rescue Discorb::NotFoundError
|
753
727
|
nil
|
754
728
|
else
|
@@ -758,8 +732,7 @@ module Discorb
|
|
758
732
|
|
759
733
|
#
|
760
734
|
# Checks the user was banned from the guild.
|
761
|
-
# @
|
762
|
-
# @macro http
|
735
|
+
# @async
|
763
736
|
#
|
764
737
|
# @param [Discorb::User] user The user to check.
|
765
738
|
#
|
@@ -773,8 +746,7 @@ module Discorb
|
|
773
746
|
|
774
747
|
#
|
775
748
|
# Ban a member from the guild.
|
776
|
-
# @
|
777
|
-
# @macro http
|
749
|
+
# @async
|
778
750
|
#
|
779
751
|
# @param [Discorb::Member] member The member to ban.
|
780
752
|
# @param [Integer] delete_message_days The number of days to delete messages.
|
@@ -784,45 +756,42 @@ module Discorb
|
|
784
756
|
#
|
785
757
|
def ban_member(member, delete_message_days: 0, reason: nil)
|
786
758
|
Async do
|
787
|
-
_resp, data = @client.http.post
|
788
|
-
"/guilds/#{@id}/bans", { user: member.id, delete_message_days: delete_message_days }, audit_log_reason: reason,
|
789
|
-
).wait
|
759
|
+
_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
|
790
760
|
Ban.new(@client, self, data)
|
791
761
|
end
|
792
762
|
end
|
793
763
|
|
794
764
|
#
|
795
765
|
# Unban a user from the guild.
|
796
|
-
# @
|
797
|
-
# @macro http
|
766
|
+
# @async
|
798
767
|
#
|
799
768
|
# @param [Discorb::User] user The user to unban.
|
800
769
|
# @param [String] reason The reason for unbanning the user.
|
801
770
|
#
|
771
|
+
# @return [Async::Task<void>] The task.
|
772
|
+
#
|
802
773
|
def unban_user(user, reason: nil)
|
803
774
|
Async do
|
804
|
-
@client.http.
|
775
|
+
@client.http.request(Route.new("/guilds/#{@id}/bans/#{user.id}", "//guilds/:guild_id/bans/:user_id", :delete), audit_log_reason: reason).wait
|
805
776
|
end
|
806
777
|
end
|
807
778
|
|
808
779
|
#
|
809
780
|
# Fetch a list of roles in the guild.
|
810
|
-
# @
|
811
|
-
# @macro http
|
781
|
+
# @async
|
812
782
|
#
|
813
783
|
# @return [Async::Task<Array<Discorb::Role>>] The list of roles.
|
814
784
|
#
|
815
785
|
def fetch_roles
|
816
786
|
Async do
|
817
|
-
_resp, data = @client.http.
|
787
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/roles", "//guilds/:guild_id/roles", :get)).wait
|
818
788
|
data.map { |d| Role.new(@client, self, d) }
|
819
789
|
end
|
820
790
|
end
|
821
791
|
|
822
792
|
#
|
823
793
|
# Create a role in the guild.
|
824
|
-
# @
|
825
|
-
# @macro http
|
794
|
+
# @async
|
826
795
|
#
|
827
796
|
# @param [String] name The name of the role.
|
828
797
|
# @param [Discorb::Color] color The color of the role.
|
@@ -839,17 +808,14 @@ module Discorb
|
|
839
808
|
payload[:color] = color.to_i if color
|
840
809
|
payload[:hoist] = hoist if hoist
|
841
810
|
payload[:mentionable] = mentionable if mentionable
|
842
|
-
_resp, data = @client.http.post
|
843
|
-
"/guilds/#{@id}/roles", payload, audit_log_reason: reason,
|
844
|
-
).wait
|
811
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/roles", "//guilds/:guild_id/roles", :post), payload, audit_log_reason: reason).wait
|
845
812
|
Role.new(@client, self, data)
|
846
813
|
end
|
847
814
|
end
|
848
815
|
|
849
816
|
#
|
850
817
|
# Fetch how many members will be pruned.
|
851
|
-
# @
|
852
|
-
# @macro http
|
818
|
+
# @async
|
853
819
|
#
|
854
820
|
# @param [Integer] days The number of days to prune.
|
855
821
|
# @param [Array<Discorb::Role>] roles The roles that include for pruning.
|
@@ -863,15 +829,14 @@ module Discorb
|
|
863
829
|
include_roles: @id.to_s,
|
864
830
|
}
|
865
831
|
param[:include_roles] = roles.map(&:id).map(&:to_s).join(";") if roles.any?
|
866
|
-
_resp, data = @client.http.
|
832
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/prune?#{URI.encode_www_form(params)}", "//guilds/:guild_id/prune", :get)).wait
|
867
833
|
data[:pruned]
|
868
834
|
end
|
869
835
|
end
|
870
836
|
|
871
837
|
#
|
872
838
|
# Prune members from the guild.
|
873
|
-
# @
|
874
|
-
# @macro http
|
839
|
+
# @async
|
875
840
|
#
|
876
841
|
# @param [Integer] days The number of days to prune.
|
877
842
|
# @param [Array<Discorb::Role>] roles The roles that include for pruning.
|
@@ -881,115 +846,105 @@ module Discorb
|
|
881
846
|
#
|
882
847
|
def prune(days = 7, roles: [], reason: nil)
|
883
848
|
Async do
|
884
|
-
_resp, data = @client.http.post(
|
885
|
-
"/guilds/#{@id}/prune", { days: days, roles: roles.map(&:id) }, audit_log_reason: reason,
|
886
|
-
).wait
|
849
|
+
_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
|
887
850
|
data[:pruned]
|
888
851
|
end
|
889
852
|
end
|
890
853
|
|
891
854
|
#
|
892
855
|
# Fetch voice regions that are available in the guild.
|
893
|
-
# @
|
894
|
-
# @macro http
|
856
|
+
# @async
|
895
857
|
#
|
896
858
|
# @return [Async::Task<Array<Discorb::VoiceRegion>>] The available voice regions.
|
897
859
|
#
|
898
860
|
def fetch_voice_regions
|
899
861
|
Async do
|
900
|
-
_resp, data = @client.http.
|
862
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/voice", "//guilds/:guild_id/voice", :get)).wait
|
901
863
|
data.map { |d| VoiceRegion.new(@client, d) }
|
902
864
|
end
|
903
865
|
end
|
904
866
|
|
905
867
|
#
|
906
868
|
# Fetch invites in the guild.
|
907
|
-
# @
|
908
|
-
# @macro http
|
869
|
+
# @async
|
909
870
|
#
|
910
871
|
# @return [Async::Task<Array<Invite>>] The invites.
|
911
872
|
#
|
912
873
|
def fetch_invites
|
913
874
|
Async do
|
914
|
-
_resp, data = @client.http.
|
875
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/invites", "//guilds/:guild_id/invites", :get)).wait
|
915
876
|
data.map { |d| Invite.new(@client, d) }
|
916
877
|
end
|
917
878
|
end
|
918
879
|
|
919
880
|
#
|
920
881
|
# Fetch integrations in the guild.
|
921
|
-
# @
|
922
|
-
# @macro http
|
882
|
+
# @async
|
923
883
|
#
|
924
884
|
# @return [Async::Task<Array<Discorb::Integration>>] The integrations.
|
925
885
|
#
|
926
886
|
def fetch_integrations
|
927
887
|
Async do
|
928
|
-
_resp, data = @client.http.
|
888
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/integrations", "//guilds/:guild_id/integrations", :get)).wait
|
929
889
|
data.map { |d| Integration.new(@client, d) }
|
930
890
|
end
|
931
891
|
end
|
932
892
|
|
933
893
|
#
|
934
894
|
# Fetch the widget of the guild.
|
935
|
-
# @
|
936
|
-
# @macro http
|
895
|
+
# @async
|
937
896
|
#
|
938
897
|
# @return [Async::Task<Discorb::Guild::Widget>] The widget.
|
939
898
|
#
|
940
899
|
def fetch_widget
|
941
900
|
Async do
|
942
|
-
_resp, data = @client.http.
|
901
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/widget", "//guilds/:guild_id/widget", :get)).wait
|
943
902
|
Widget.new(@client, @id, data)
|
944
903
|
end
|
945
904
|
end
|
946
905
|
|
947
906
|
#
|
948
907
|
# Fetch the vanity URL of the guild.
|
949
|
-
# @
|
950
|
-
# @macro http
|
908
|
+
# @async
|
951
909
|
#
|
952
910
|
# @return [Async::Task<Discorb::Guild::VanityInvite>] The vanity URL.
|
953
911
|
#
|
954
912
|
def fetch_vanity_invite
|
955
913
|
Async do
|
956
|
-
_resp, data = @client.http.
|
914
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/vanity-url", "//guilds/:guild_id/vanity-url", :get)).wait
|
957
915
|
VanityInvite.new(@client, self, data)
|
958
916
|
end
|
959
917
|
end
|
960
918
|
|
961
919
|
#
|
962
920
|
# Fetch the welcome screen of the guild.
|
963
|
-
# @
|
964
|
-
# @macro http
|
921
|
+
# @async
|
965
922
|
#
|
966
|
-
# @return [Async::Task<Discorb::
|
923
|
+
# @return [Async::Task<Discorb::WelcomeScreen>] The welcome screen.
|
967
924
|
#
|
968
925
|
def fetch_welcome_screen
|
969
926
|
Async do
|
970
|
-
_resp, data = @client.http.
|
927
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/welcome-screen", "//guilds/:guild_id/welcome-screen", :get)).wait
|
971
928
|
WelcomeScreen.new(@client, self, data)
|
972
929
|
end
|
973
930
|
end
|
974
931
|
|
975
932
|
#
|
976
933
|
# Fetch stickers in the guild.
|
977
|
-
# @
|
978
|
-
# @macro http
|
934
|
+
# @async
|
979
935
|
#
|
980
936
|
# @return [Async::Task<Array<Discorb::Sticker::GuildSticker>>] The stickers.
|
981
937
|
#
|
982
938
|
def fetch_stickers
|
983
939
|
Async do
|
984
|
-
_resp, data = @client.http.
|
940
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/stickers", "//guilds/:guild_id/stickers", :get)).wait
|
985
941
|
data.map { |d| Sticker::GuildSticker.new(@client, d) }
|
986
942
|
end
|
987
943
|
end
|
988
944
|
|
989
945
|
#
|
990
946
|
# Fetch the sticker by ID.
|
991
|
-
# @
|
992
|
-
# @macro http
|
947
|
+
# @async
|
993
948
|
#
|
994
949
|
# @param [#to_s] id The ID of the sticker.
|
995
950
|
#
|
@@ -998,7 +953,7 @@ module Discorb
|
|
998
953
|
#
|
999
954
|
def fetch_sticker(id)
|
1000
955
|
Async do
|
1001
|
-
_resp, data = @client.http.
|
956
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/stickers/#{id}", "//guilds/:guild_id/stickers/:sticker_id", :get)).wait
|
1002
957
|
rescue Discorb::NotFoundError
|
1003
958
|
nil
|
1004
959
|
else
|
@@ -1008,14 +963,13 @@ module Discorb
|
|
1008
963
|
|
1009
964
|
#
|
1010
965
|
# Fetch templates in the guild.
|
1011
|
-
# @
|
1012
|
-
# @macro http
|
966
|
+
# @async
|
1013
967
|
#
|
1014
968
|
# @return [Async::Task<Discorb::GuildTemplate>] The templates.
|
1015
969
|
#
|
1016
970
|
def fetch_templates
|
1017
971
|
Async do
|
1018
|
-
_resp, data = @client.http.
|
972
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/templates", "//guilds/:guild_id/templates", :get)).wait
|
1019
973
|
data.map { |d| GuildTemplate.new(@client, d) }
|
1020
974
|
end
|
1021
975
|
end
|
@@ -1043,9 +997,7 @@ module Discorb
|
|
1043
997
|
#
|
1044
998
|
def create_template(name, description = nil, reason: nil)
|
1045
999
|
Async do
|
1046
|
-
_resp, data = @client.http.post
|
1047
|
-
"/guilds/#{@id}/templates", { name: name, description: description }, audit_log_reason: reason,
|
1048
|
-
).wait
|
1000
|
+
_resp, data = @client.http.request(Route.new("/guilds/#{@id}/templates", "//guilds/:guild_id/templates", :post), { name: name, description: description }, audit_log_reason: reason).wait
|
1049
1001
|
GuildTemplate.new(@client, data)
|
1050
1002
|
end
|
1051
1003
|
end
|
@@ -1111,20 +1063,21 @@ module Discorb
|
|
1111
1063
|
|
1112
1064
|
#
|
1113
1065
|
# Edit the widget.
|
1114
|
-
# @
|
1115
|
-
# @macro http
|
1066
|
+
# @async
|
1116
1067
|
# @macro edit
|
1117
1068
|
#
|
1118
1069
|
# @param [Boolean] enabled Whether the widget is enabled.
|
1119
1070
|
# @param [Discorb::GuildChannel] channel The channel.
|
1120
1071
|
# @param [String] reason The reason for editing the widget.
|
1121
1072
|
#
|
1073
|
+
# @return [Async::Task<void>] The task.
|
1074
|
+
#
|
1122
1075
|
def edit(enabled: nil, channel: nil, reason: nil)
|
1123
1076
|
Async do
|
1124
1077
|
payload = {}
|
1125
1078
|
payload[:enabled] = enabled unless enabled.nil?
|
1126
1079
|
payload[:channel_id] = channel.id if channel_id
|
1127
|
-
@client.http.
|
1080
|
+
@client.http.request(Route.new("/guilds/#{@guild_id}/widget", "//guilds/:guild_id/widget", :patch), payload, audit_log_reason: reason).wait
|
1128
1081
|
end
|
1129
1082
|
end
|
1130
1083
|
|
@@ -1366,8 +1319,7 @@ module Discorb
|
|
1366
1319
|
|
1367
1320
|
#
|
1368
1321
|
# Edits the welcome screen.
|
1369
|
-
# @
|
1370
|
-
# @macro http
|
1322
|
+
# @async
|
1371
1323
|
# @macro edit
|
1372
1324
|
#
|
1373
1325
|
# @param [Boolean] enabled Whether the welcome screen is enabled.
|
@@ -1375,13 +1327,15 @@ module Discorb
|
|
1375
1327
|
# @param [String] description The description of the welcome screen.
|
1376
1328
|
# @param [String] reason The reason for editing the welcome screen.
|
1377
1329
|
#
|
1378
|
-
|
1330
|
+
# @return [Async::Task<void>] The task.
|
1331
|
+
#
|
1332
|
+
def edit(enabled: Discorb::Unset, channels: Discorb::Unset, description: Discorb::Unset, reason: nil)
|
1379
1333
|
Async do
|
1380
1334
|
payload = {}
|
1381
|
-
payload[:enabled] = enabled unless enabled ==
|
1382
|
-
payload[:welcome_channels] = channels.map(&:to_hash) unless channels ==
|
1383
|
-
payload[:description] = description unless description ==
|
1384
|
-
@client.http.
|
1335
|
+
payload[:enabled] = enabled unless enabled == Discorb::Unset
|
1336
|
+
payload[:welcome_channels] = channels.map(&:to_hash) unless channels == Discorb::Unset
|
1337
|
+
payload[:description] = description unless description == Discorb::Unset
|
1338
|
+
@client.http.request(Route.new("/guilds/#{@guild.id}/welcome-screen", "//guilds/:guild_id/welcome-screen", :patch), payload, audit_log_reason: reason).wait
|
1385
1339
|
end
|
1386
1340
|
end
|
1387
1341
|
end
|