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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build_main.yml +1 -0
  3. data/.github/workflows/build_version.yml +4 -3
  4. data/.github/workflows/crowdin.yml +32 -0
  5. data/.gitignore +3 -1
  6. data/.yardopts +2 -0
  7. data/CODE_OF_CONDUCT.md +128 -0
  8. data/Changelog.md +420 -388
  9. data/Gemfile +5 -1
  10. data/README.md +2 -2
  11. data/Rakefile +131 -1
  12. data/crowdin.yml +2 -0
  13. data/discorb.gemspec +12 -1
  14. data/docs/Examples.md +2 -0
  15. data/docs/application_command.md +7 -5
  16. data/docs/cli/irb.md +2 -0
  17. data/docs/cli/new.md +2 -0
  18. data/docs/cli/run.md +3 -1
  19. data/docs/cli/setup.md +4 -2
  20. data/docs/cli.md +2 -0
  21. data/docs/events.md +6 -4
  22. data/docs/extension.md +2 -2
  23. data/docs/faq.md +4 -2
  24. data/docs/license.md +2 -0
  25. data/docs/tutorial.md +4 -3
  26. data/docs/voice_events.md +2 -0
  27. data/lib/discorb/app_command.rb +32 -9
  28. data/lib/discorb/application.rb +1 -1
  29. data/lib/discorb/asset.rb +1 -1
  30. data/lib/discorb/channel.rb +170 -125
  31. data/lib/discorb/client.rb +20 -22
  32. data/lib/discorb/common.rb +32 -1
  33. data/lib/discorb/dictionary.rb +10 -2
  34. data/lib/discorb/emoji.rb +7 -9
  35. data/lib/discorb/emoji_table.rb +3891 -3891
  36. data/lib/discorb/event.rb +12 -11
  37. data/lib/discorb/exe/show.rb +2 -0
  38. data/lib/discorb/extension.rb +1 -1
  39. data/lib/discorb/flag.rb +1 -1
  40. data/lib/discorb/gateway.rb +63 -17
  41. data/lib/discorb/guild.rb +110 -156
  42. data/lib/discorb/guild_template.rb +15 -12
  43. data/lib/discorb/http.rb +41 -136
  44. data/lib/discorb/integration.rb +34 -2
  45. data/lib/discorb/interaction/autocomplete.rb +1 -1
  46. data/lib/discorb/interaction/response.rb +34 -32
  47. data/lib/discorb/interaction/root.rb +8 -0
  48. data/lib/discorb/invite.rb +4 -3
  49. data/lib/discorb/log.rb +3 -2
  50. data/lib/discorb/member.rb +44 -15
  51. data/lib/discorb/message.rb +33 -22
  52. data/lib/discorb/modules.rb +28 -35
  53. data/lib/discorb/presence.rb +2 -2
  54. data/lib/discorb/rate_limit.rb +14 -18
  55. data/lib/discorb/role.rb +18 -14
  56. data/lib/discorb/sticker.rb +10 -14
  57. data/lib/discorb/user.rb +10 -10
  58. data/lib/discorb/voice_state.rb +12 -7
  59. data/lib/discorb/webhook.rb +44 -50
  60. data/lib/discorb.rb +1 -1
  61. data/po/yard.pot +7772 -5154
  62. data/sig/discorb.rbs +3316 -3819
  63. data/template-replace/scripts/locale_ja.rb +62 -0
  64. metadata +18 -5
@@ -166,8 +166,7 @@ module Discorb
166
166
 
167
167
  #
168
168
  # Deletes the channel.
169
- # @macro async
170
- # @macro http
169
+ # @async
171
170
  #
172
171
  # @param [String] reason The reason of deleting the channel.
173
172
  #
@@ -175,7 +174,7 @@ module Discorb
175
174
  #
176
175
  def delete!(reason: nil)
177
176
  Async do
178
- @client.http.delete(base_url.wait.to_s, audit_log_reason: reason).wait
177
+ @client.http.request(Route.new(base_url.wait.to_s, "//webhooks/:webhook_id/:token", :delete), audit_log_reason: reason).wait
179
178
  @deleted = true
180
179
  self
181
180
  end
@@ -186,8 +185,7 @@ module Discorb
186
185
 
187
186
  #
188
187
  # Moves the channel to another position.
189
- # @macro async
190
- # @macro http
188
+ # @async
191
189
  #
192
190
  # @param [Integer] position The position to move the channel.
193
191
  # @param [Boolean] lock_permissions Whether to lock the permissions of the channel.
@@ -196,14 +194,14 @@ module Discorb
196
194
  #
197
195
  # @return [Async::Task<self>] The moved channel.
198
196
  #
199
- def move(position, lock_permissions: false, parent: :unset, reason: nil)
197
+ def move(position, lock_permissions: false, parent: Discorb::Unset, reason: nil)
200
198
  Async do
201
199
  payload = {
202
200
  position: position,
203
201
  }
204
202
  payload[:lock_permissions] = lock_permissions
205
- payload[:parent_id] = parent&.id if parent != :unset
206
- @client.http.patch("/guilds/#{@guild_id}/channels", payload, audit_log_reason: reason).wait
203
+ payload[:parent_id] = parent&.id if parent != Discorb::Unset
204
+ @client.http.request(Route.new("/guilds/#{@guild_id}/channels", "//guilds/:guild_id/channels", :patch), payload, audit_log_reason: reason).wait
207
205
  end
208
206
  end
209
207
 
@@ -256,8 +254,7 @@ module Discorb
256
254
 
257
255
  #
258
256
  # Edits the channel.
259
- # @macro async
260
- # @macro http
257
+ # @async
261
258
  # @macro edit
262
259
  #
263
260
  # @param [String] name The name of the channel.
@@ -275,27 +272,27 @@ module Discorb
275
272
  #
276
273
  # @return [Async::Task<self>] The edited channel.
277
274
  #
278
- def edit(name: :unset, position: :unset, category: :unset, parent: :unset,
279
- topic: :unset, nsfw: :unset, announce: :unset,
280
- rate_limit_per_user: :unset, slowmode: :unset, default_auto_archive_duration: :unset,
281
- archive_in: :unset, reason: nil)
275
+ def edit(name: Discorb::Unset, position: Discorb::Unset, category: Discorb::Unset, parent: Discorb::Unset,
276
+ topic: Discorb::Unset, nsfw: Discorb::Unset, announce: Discorb::Unset,
277
+ rate_limit_per_user: Discorb::Unset, slowmode: Discorb::Unset, default_auto_archive_duration: Discorb::Unset,
278
+ archive_in: Discorb::Unset, reason: nil)
282
279
  Async do
283
280
  payload = {}
284
- payload[:name] = name if name != :unset
285
- payload[:announce] = announce ? 5 : 0 if announce != :unset
286
- payload[:position] = position if position != :unset
287
- payload[:topic] = topic || "" if topic != :unset
288
- payload[:nsfw] = nsfw if nsfw != :unset
281
+ payload[:name] = name if name != Discorb::Unset
282
+ payload[:announce] = announce ? 5 : 0 if announce != Discorb::Unset
283
+ payload[:position] = position if position != Discorb::Unset
284
+ payload[:topic] = topic || "" if topic != Discorb::Unset
285
+ payload[:nsfw] = nsfw if nsfw != Discorb::Unset
289
286
 
290
- slowmode = rate_limit_per_user if slowmode == :unset
291
- payload[:rate_limit_per_user] = slowmode || 0 if slowmode != :unset
292
- parent = category if parent == :unset
293
- payload[:parent_id] = parent&.id if parent != :unset
287
+ slowmode = rate_limit_per_user if slowmode == Discorb::Unset
288
+ payload[:rate_limit_per_user] = slowmode || 0 if slowmode != Discorb::Unset
289
+ parent = category if parent == Discorb::Unset
290
+ payload[:parent_id] = parent&.id if parent != Discorb::Unset
294
291
 
295
292
  default_auto_archive_duration ||= archive_in
296
- payload[:default_auto_archive_duration] = default_auto_archive_duration if default_auto_archive_duration != :unset
293
+ payload[:default_auto_archive_duration] = default_auto_archive_duration if default_auto_archive_duration != Discorb::Unset
297
294
 
298
- @client.http.patch("/channels/#{@id}", payload, audit_log_reason: reason).wait
295
+ @client.http.request(Route.new("/channels/#{@id}", "//channels/:channel_id", :patch), payload, audit_log_reason: reason).wait
299
296
  self
300
297
  end
301
298
  end
@@ -304,8 +301,7 @@ module Discorb
304
301
 
305
302
  #
306
303
  # Create webhook in the channel.
307
- # @macro async
308
- # @macro http
304
+ # @async
309
305
  #
310
306
  # @param [String] name The name of the webhook.
311
307
  # @param [Discorb::Image] avatar The avatar of the webhook.
@@ -317,33 +313,33 @@ module Discorb
317
313
  payload = {}
318
314
  payload[:name] = name
319
315
  payload[:avatar] = avatar.to_s if avatar
320
- _resp, data = @client.http.post("/channels/#{@id}/webhooks", payload).wait
316
+ _resp, data = @client.http.request(Route.new("/channels/#{@id}/webhooks", "//channels/:channel_id/webhooks", :post), payload).wait
321
317
  Webhook.new([@client, data])
322
318
  end
323
319
  end
324
320
 
325
321
  #
326
322
  # Fetch webhooks in the channel.
327
- # @macro async
328
- # @macro http
323
+ # @async
329
324
  #
330
325
  # @return [Async::Task<Array<Discorb::Webhook>>] The webhooks in the channel.
331
326
  #
332
327
  def fetch_webhooks
333
328
  Async do
334
- _resp, data = @client.http.get("/channels/#{@id}/webhooks").wait
329
+ _resp, data = @client.http.request(Route.new("/channels/#{@id}/webhooks", "//channels/:channel_id/webhooks", :get)).wait
335
330
  data.map { |webhook| Webhook.new([@client, webhook]) }
336
331
  end
337
332
  end
338
333
 
339
334
  #
340
335
  # Bulk delete messages in the channel.
341
- # @macro async
342
- # @macro http
336
+ # @async
343
337
  #
344
338
  # @param [Discorb::Message] messages The messages to delete.
345
339
  # @param [Boolean] force Whether to ignore the validation for message (14 days limit).
346
340
  #
341
+ # @return [Async::Task<void>] The task.
342
+ #
347
343
  def delete_messages!(*messages, force: false)
348
344
  Async do
349
345
  messages = messages.first if messages.length == 1 && messages.first.is_a?(Array)
@@ -358,7 +354,7 @@ module Discorb
358
354
 
359
355
  message_ids = messages.map { |m| Discorb::Utils.try(m, :id).to_s }
360
356
 
361
- @client.http.post("/channels/#{@id}/messages/bulk-delete", { messages: message_ids }).wait
357
+ @client.http.request(Route.new("/channels/#{@id}/messages/bulk-delete", "//channels/:channel_id/messages/bulk-delete", :post), { messages: message_ids }).wait
362
358
  end
363
359
  end
364
360
 
@@ -367,12 +363,13 @@ module Discorb
367
363
 
368
364
  #
369
365
  # Set the channel's permission overwrite.
370
- # @macro async
371
- # @macro http
366
+ # @async
372
367
  #
373
368
  # @param [Discorb::Role, Discorb::Member] target The target of the overwrite.
374
369
  # @param [String] reason The reason of setting the overwrite.
375
- # @param [Symbol => Boolean] perms The permission overwrites to replace.
370
+ # @param [{Symbol => Boolean}] perms The permission overwrites to replace.
371
+ #
372
+ # @return [Async::Task<void>] The task.
376
373
  #
377
374
  def set_permissions(target, reason: nil, **perms)
378
375
  Async do
@@ -387,7 +384,7 @@ module Discorb
387
384
  deny: deny_value,
388
385
  type: target.is_a?(Member) ? 1 : 0,
389
386
  }
390
- @client.http.put("/channels/#{@id}/permissions/#{target.id}", payload, audit_log_reason: reason).wait
387
+ @client.http.request(Route.new("/channels/#{@id}/permissions/#{target.id}", "//channels/:channel_id/permissions/:target_id", :put), payload, audit_log_reason: reason).wait
391
388
  end
392
389
  end
393
390
 
@@ -398,15 +395,16 @@ module Discorb
398
395
 
399
396
  #
400
397
  # Delete the channel's permission overwrite.
401
- # @macro async
402
- # @macro http
398
+ # @async
403
399
  #
404
400
  # @param [Discorb::Role, Discorb::Member] target The target of the overwrite.
405
401
  # @param [String] reason The reason of deleting the overwrite.
406
402
  #
403
+ # @return [Async::Task<void>] The task.
404
+ #
407
405
  def delete_permissions(target, reason: nil)
408
406
  Async do
409
- @client.http.delete("/channels/#{@id}/permissions/#{target.id}", audit_log_reason: reason).wait
407
+ @client.http.request(Route.new("/channels/#{@id}/permissions/#{target.id}", "//channels/:channel_id/permissions/:target_id", :delete), audit_log_reason: reason).wait
410
408
  end
411
409
  end
412
410
 
@@ -416,22 +414,20 @@ module Discorb
416
414
 
417
415
  #
418
416
  # Fetch the channel's invites.
419
- # @macro async
420
- # @macro http
417
+ # @async
421
418
  #
422
419
  # @return [Async::Task<Array<Discorb::Invite>>] The invites in the channel.
423
420
  #
424
421
  def fetch_invites
425
422
  Async do
426
- _resp, data = @client.http.get("/channels/#{@id}/invites").wait
423
+ _resp, data = @client.http.request(Route.new("/channels/#{@id}/invites", "//channels/:channel_id/invites", :get)).wait
427
424
  data.map { |invite| Invite.new(@client, invite) }
428
425
  end
429
426
  end
430
427
 
431
428
  #
432
429
  # Create an invite in the channel.
433
- # @macro async
434
- # @macro http
430
+ # @async
435
431
  #
436
432
  # @param [Integer] max_age The max age of the invite.
437
433
  # @param [Integer] max_uses The max uses of the invite.
@@ -444,7 +440,7 @@ module Discorb
444
440
  #
445
441
  def create_invite(max_age: nil, max_uses: nil, temporary: false, unique: false, reason: nil)
446
442
  Async do
447
- _resp, data = @client.http.post("/channels/#{@id}/invites", {
443
+ _resp, data = @client.http.request(Route.new("/channels/#{@id}/invites", "//channels/:channel_id/invites", :post), {
448
444
  max_age: max_age,
449
445
  max_uses: max_uses,
450
446
  temporary: temporary,
@@ -456,36 +452,37 @@ module Discorb
456
452
 
457
453
  #
458
454
  # Follow the existing announcement channel.
459
- # @macro async
460
- # @macro http
455
+ # @async
461
456
  #
462
457
  # @param [Discorb::NewsChannel] target The channel to follow.
463
458
  # @param [String] reason The reason of following the channel.
464
459
  #
460
+ # @return [Async::Task<void>] The task.
461
+ #
465
462
  def follow_from(target, reason: nil)
466
463
  Async do
467
- @client.http.post("/channels/#{target.id}/followers", { webhook_channel_id: @id }, audit_log_reason: reason).wait
464
+ @client.http.request(Route.new("/channels/#{target.id}/followers", "//channels/:channel_id/followers", :post), { webhook_channel_id: @id }, audit_log_reason: reason).wait
468
465
  end
469
466
  end
470
467
 
471
468
  #
472
469
  # Follow the existing announcement channel from self.
473
- # @macro async
474
- # @macro http
470
+ # @async
475
471
  #
476
472
  # @param [Discorb::TextChannel] target The channel to follow to.
477
473
  # @param [String] reason The reason of following the channel.
478
474
  #
475
+ # @return [Async::Task<void>] The task.
476
+ #
479
477
  def follow_to(target, reason: nil)
480
478
  Async do
481
- @client.http.post("/channels/#{@id}/followers", { webhook_channel_id: target.id }, audit_log_reason: reason).wait
479
+ @client.http.request(Route.new("/channels/#{@id}/followers", "//channels/:channel_id/followers", :post), { webhook_channel_id: target.id }, audit_log_reason: reason).wait
482
480
  end
483
481
  end
484
482
 
485
483
  #
486
484
  # Start thread in the channel.
487
- # @macro async
488
- # @macro http
485
+ # @async
489
486
  #
490
487
  # @param [String] name The name of the thread.
491
488
  # @param [Discorb::Message] message The message to start the thread.
@@ -500,17 +497,15 @@ module Discorb
500
497
  def start_thread(name, message: nil, auto_archive_duration: 1440, public: true, rate_limit_per_user: nil, slowmode: nil, reason: nil)
501
498
  Async do
502
499
  _resp, data = if message.nil?
503
- @client.http.post(
504
- "/channels/#{@id}/threads", {
505
- name: name,
506
- auto_archive_duration: auto_archive_duration,
507
- type: public ? 11 : 10,
508
- rate_limit_per_user: rate_limit_per_user || slowmode,
509
- },
510
- audit_log_reason: reason,
511
- ).wait
500
+ @client.http.request(Route.new("/channels/#{@id}/threads", "//channels/:channel_id/threads", :post), {
501
+ name: name,
502
+ auto_archive_duration: auto_archive_duration,
503
+ type: public ? 11 : 10,
504
+ rate_limit_per_user: rate_limit_per_user || slowmode,
505
+ },
506
+ audit_log_reason: reason).wait
512
507
  else
513
- @client.http.post("/channels/#{@id}/messages/#{Utils.try(message, :id)}/threads", {
508
+ @client.http.request(Route.new("/channels/#{@id}/messages/#{Utils.try(message, :id)}/threads", "//channels/:channel_id/messages/:message_id/threads", :post), {
514
509
  name: name, auto_archive_duration: auto_archive_duration,
515
510
  }, audit_log_reason: reason).wait
516
511
  end
@@ -522,36 +517,33 @@ module Discorb
522
517
 
523
518
  #
524
519
  # Fetch archived threads in the channel.
525
- # @macro async
526
- # @macro http
520
+ # @async
527
521
  #
528
522
  # @return [Async::Task<Array<Discorb::ThreadChannel>>] The archived threads in the channel.
529
523
  #
530
524
  def fetch_archived_public_threads
531
525
  Async do
532
- _resp, data = @client.http.get("/channels/#{@id}/threads/archived/public").wait
526
+ _resp, data = @client.http.request(Route.new("/channels/#{@id}/threads/archived/public", "//channels/:channel_id/threads/archived/public", :get)).wait
533
527
  data.map { |thread| Channel.make_channel(@client, thread) }
534
528
  end
535
529
  end
536
530
 
537
531
  #
538
532
  # Fetch archived private threads in the channel.
539
- # @macro async
540
- # @macro http
533
+ # @async
541
534
  #
542
535
  # @return [Async::Task<Array<Discorb::ThreadChannel>>] The archived private threads in the channel.
543
536
  #
544
537
  def fetch_archived_private_threads
545
538
  Async do
546
- _resp, data = @client.http.get("/channels/#{@id}/threads/archived/private").wait
539
+ _resp, data = @client.http.request(Route.new("/channels/#{@id}/threads/archived/private", "//channels/:channel_id/threads/archived/private", :get)).wait
547
540
  data.map { |thread| Channel.make_channel(@client, thread) }
548
541
  end
549
542
  end
550
543
 
551
544
  #
552
545
  # Fetch joined archived private threads in the channel.
553
- # @macro async
554
- # @macro http
546
+ # @async
555
547
  #
556
548
  # @param [Integer] limit The limit of threads to fetch.
557
549
  # @param [Time] before <description>
@@ -564,7 +556,7 @@ module Discorb
564
556
  before = 0
565
557
  threads = []
566
558
  loop do
567
- _resp, data = @client.http.get("/channels/#{@id}/users/@me/threads/archived/private?before=#{before}").wait
559
+ _resp, data = @client.http.request(Route.new("/channels/#{@id}/users/@me/threads/archived/private?before=#{before}", "//channels/:channel_id/users/@me/threads/archived/private", :get)).wait
568
560
  threads += data[:threads].map { |thread| Channel.make_channel(@client, thread) }
569
561
  before = data[:threads][-1][:id]
570
562
 
@@ -572,7 +564,7 @@ module Discorb
572
564
  end
573
565
  threads
574
566
  else
575
- _resp, data = @client.http.get("/channels/#{@id}/users/@me/threads/archived/private?limit=#{limit}&before=#{before}").wait
567
+ _resp, data = @client.http.request(Route.new("/channels/#{@id}/users/@me/threads/archived/private?limit=#{limit}&before=#{before}", "//channels/:channel_id/users/@me/threads/archived/private", :get)).wait
576
568
  data.map { |thread| Channel.make_channel(@client, thread) }
577
569
  end
578
570
  end
@@ -609,13 +601,17 @@ module Discorb
609
601
  # @return [nil] If the user limit is not set.
610
602
  attr_reader :user_limit
611
603
 
604
+ # @!attribute [r] members
605
+ # @return [Array<Discorb::Member>] The members in the voice channel.
606
+ # @!attribute [r] voice_states
607
+ # @return [Array<Discorb::VoiceState>] The voice states associated with the voice channel.
608
+
612
609
  include Connectable
613
610
 
614
611
  @channel_type = 2
615
612
  #
616
613
  # Edit the voice channel.
617
- # @macro async
618
- # @macro http
614
+ # @async
619
615
  # @macro edit
620
616
  #
621
617
  # @param [String] name The name of the voice channel.
@@ -627,22 +623,30 @@ module Discorb
627
623
  #
628
624
  # @return [Async::Task<self>] The edited voice channel.
629
625
  #
630
- def edit(name: :unset, position: :unset, bitrate: :unset, user_limit: :unset, rtc_region: :unset, reason: nil)
626
+ def edit(name: Discorb::Unset, position: Discorb::Unset, bitrate: Discorb::Unset, user_limit: Discorb::Unset, rtc_region: Discorb::Unset, reason: nil)
631
627
  Async do
632
628
  payload = {}
633
- payload[:name] = name if name != :unset
634
- payload[:position] = position if position != :unset
635
- payload[:bitrate] = bitrate if bitrate != :unset
636
- payload[:user_limit] = user_limit if user_limit != :unset
637
- payload[:rtc_region] = rtc_region if rtc_region != :unset
629
+ payload[:name] = name if name != Discorb::Unset
630
+ payload[:position] = position if position != Discorb::Unset
631
+ payload[:bitrate] = bitrate if bitrate != Discorb::Unset
632
+ payload[:user_limit] = user_limit if user_limit != Discorb::Unset
633
+ payload[:rtc_region] = rtc_region if rtc_region != Discorb::Unset
638
634
 
639
- @client.http.patch("/channels/#{@id}", payload, audit_log_reason: reason).wait
635
+ @client.http.request(Route.new("/channels/#{@id}", "//channels/:channel_id", :patch), payload, audit_log_reason: reason).wait
640
636
  self
641
637
  end
642
638
  end
643
639
 
644
640
  alias modify edit
645
641
 
642
+ def voice_states
643
+ guild.voice_states.select { |state| state.channel&.id == @id }
644
+ end
645
+
646
+ def members
647
+ voice_states.map(&:member)
648
+ end
649
+
646
650
  private
647
651
 
648
652
  def _set_data(data)
@@ -683,8 +687,7 @@ module Discorb
683
687
 
684
688
  #
685
689
  # Edit the stage channel.
686
- # @macro async
687
- # @macro http
690
+ # @async
688
691
  # @macro edit
689
692
  #
690
693
  # @param [String] name The name of the stage channel.
@@ -695,14 +698,14 @@ module Discorb
695
698
  #
696
699
  # @return [Async::Task<self>] The edited stage channel.
697
700
  #
698
- def edit(name: :unset, position: :unset, bitrate: :unset, rtc_region: :unset, reason: nil)
701
+ def edit(name: Discorb::Unset, position: Discorb::Unset, bitrate: Discorb::Unset, rtc_region: Discorb::Unset, reason: nil)
699
702
  Async do
700
703
  payload = {}
701
- payload[:name] = name if name != :unset
702
- payload[:position] = position if position != :unset
703
- payload[:bitrate] = bitrate if bitrate != :unset
704
- payload[:rtc_region] = rtc_region if rtc_region != :unset
705
- @client.http.patch("/channels/#{@id}", payload, audit_log_reason: reason).wait
704
+ payload[:name] = name if name != Discorb::Unset
705
+ payload[:position] = position if position != Discorb::Unset
706
+ payload[:bitrate] = bitrate if bitrate != Discorb::Unset
707
+ payload[:rtc_region] = rtc_region if rtc_region != Discorb::Unset
708
+ @client.http.request(Route.new("/channels/#{@id}", "//channels/:channel_id", :patch), payload, audit_log_reason: reason).wait
706
709
  self
707
710
  end
708
711
  end
@@ -711,8 +714,7 @@ module Discorb
711
714
 
712
715
  #
713
716
  # Start a stage instance.
714
- # @macro async
715
- # @macro http
717
+ # @async
716
718
  #
717
719
  # @param [String] topic The topic of the stage instance.
718
720
  # @param [Boolean] public Whether the stage instance is public or not.
@@ -722,22 +724,21 @@ module Discorb
722
724
  #
723
725
  def start(topic, public: false, reason: nil)
724
726
  Async do
725
- _resp, data = @client.http.post("/stage-instances", { channel_id: @id, topic: topic, public: public ? 2 : 1 }, audit_log_reason: reason).wait
727
+ _resp, data = @client.http.request(Route.new("/stage-instances", "//stage-instances", :post), { channel_id: @id, topic: topic, public: public ? 2 : 1 }, audit_log_reason: reason).wait
726
728
  StageInstance.new(@client, data)
727
729
  end
728
730
  end
729
731
 
730
732
  #
731
733
  # Fetch a current stage instance.
732
- # @macro async
733
- # @macro http
734
+ # @async
734
735
  #
735
736
  # @return [Async::Task<StageInstance>] The current stage instance.
736
737
  # @return [Async::Task<nil>] If there is no current stage instance.
737
738
  #
738
739
  def fetch_stage_instance
739
740
  Async do
740
- _resp, data = @client.http.get("/stage-instances/#{@id}").wait
741
+ _resp, data = @client.http.request(Route.new("/stage-instances/#{@id}", "//stage-instances/:stage_instance_id", :get)).wait
741
742
  rescue Discorb::NotFoundError
742
743
  nil
743
744
  else
@@ -745,6 +746,22 @@ module Discorb
745
746
  end
746
747
  end
747
748
 
749
+ def voice_states
750
+ guild.voice_states.select { |state| state.channel&.id == @id }
751
+ end
752
+
753
+ def members
754
+ voice_states.map(&:member)
755
+ end
756
+
757
+ def speakers
758
+ voice_states.filter { |state| !state.suppress? }.map(&:member)
759
+ end
760
+
761
+ def audiences
762
+ voice_states.filter { |state| state.suppress? }.map(&:member)
763
+ end
764
+
748
765
  private
749
766
 
750
767
  def _set_data(data)
@@ -792,6 +809,18 @@ module Discorb
792
809
  # @!attribute [r] parent
793
810
  # @macro client_cache
794
811
  # @return [Discorb::GuildChannel] The parent channel of the thread.
812
+ # @!attribute [r] me
813
+ # @return [Discorb::ThreadChannel::Member] The bot's member in the thread.
814
+ # @return [nil] If the bot is not in the thread.
815
+ # @!attribute [r] joined?
816
+ # @return [Boolean] Whether the bot is in the thread or not.
817
+ # @!attribute [r] guild
818
+ # @macro client_cache
819
+ # @return [Discorb::Guild] The guild of the thread.
820
+ # @!attribute [r] owner
821
+ # @macro client_cache
822
+ # @macro members_intent
823
+ # @return [Discorb::Member] The owner of the thread.
795
824
 
796
825
  include Messageable
797
826
  @channel_type = nil
@@ -807,8 +836,7 @@ module Discorb
807
836
 
808
837
  #
809
838
  # Edit the thread.
810
- # @macro async
811
- # @macro http
839
+ # @async
812
840
  # @macro edit
813
841
  #
814
842
  # @param [String] name The name of the thread.
@@ -825,15 +853,15 @@ module Discorb
825
853
  # @see #unarchive
826
854
  # @see #unlock
827
855
  #
828
- def edit(name: :unset, archived: :unset, auto_archive_duration: :unset, archive_in: :unset, locked: :unset, reason: nil)
856
+ def edit(name: Discorb::Unset, archived: Discorb::Unset, auto_archive_duration: Discorb::Unset, archive_in: Discorb::Unset, locked: Discorb::Unset, reason: nil)
829
857
  Async do
830
858
  payload = {}
831
- payload[:name] = name if name != :unset
832
- payload[:archived] = archived if archived != :unset
859
+ payload[:name] = name if name != Discorb::Unset
860
+ payload[:archived] = archived if archived != Discorb::Unset
833
861
  auto_archive_duration ||= archive_in
834
- payload[:auto_archive_duration] = auto_archive_duration if auto_archive_duration != :unset
835
- payload[:locked] = locked if locked != :unset
836
- @client.http.patch("/channels/#{@id}", payload, audit_log_reason: reason).wait
862
+ payload[:auto_archive_duration] = auto_archive_duration if auto_archive_duration != Discorb::Unset
863
+ payload[:locked] = locked if locked != Discorb::Unset
864
+ @client.http.request(Route.new("/channels/#{@id}", "//channels/:channel_id", :patch), payload, audit_log_reason: reason).wait
837
865
  self
838
866
  end
839
867
  end
@@ -897,7 +925,7 @@ module Discorb
897
925
  end
898
926
 
899
927
  def joined?
900
- @members[@client.user.id]
928
+ !!me
901
929
  end
902
930
 
903
931
  def guild
@@ -912,33 +940,52 @@ module Discorb
912
940
  "#<#{self.class} \"##{@name}\" id=#{@id}>"
913
941
  end
914
942
 
943
+ #
944
+ # Add a member to the thread.
945
+ #
946
+ # @param [Discorb::Member, :me] member The member to add. If `:me` is given, the bot will be added.
947
+ #
948
+ # @return [Async::Task<void>] The task.
949
+ #
915
950
  def add_member(member = :me)
916
951
  Async do
917
952
  if member == :me
918
- @client.http.post("/channels/#{@id}/thread-members/@me").wait
953
+ @client.http.request(Route.new("/channels/#{@id}/thread-members/@me", "//channels/:channel_id/thread-members/@me", :post)).wait
919
954
  else
920
- @client.http.post("/channels/#{@id}/thread-members/#{Utils.try(member, :id)}").wait
955
+ @client.http.request(Route.new("/channels/#{@id}/thread-members/#{Utils.try(member, :id)}", "//channels/:channel_id/thread-members/:user_id", :post)).wait
921
956
  end
922
957
  end
923
958
  end
924
959
 
925
960
  alias join add_member
926
961
 
962
+ #
963
+ # Remove a member from the thread.
964
+ #
965
+ # @param [Discorb::Member, :me] member The member to remove. If `:me` is given, the bot will be removed.
966
+ #
967
+ # @return [Async::Task<void>] The task.
968
+ #
927
969
  def remove_member(member = :me)
928
970
  Async do
929
971
  if member == :me
930
- @client.http.delete("/channels/#{@id}/thread-members/@me").wait
972
+ @client.http.request(Route.new("/channels/#{@id}/thread-members/@me", "//channels/:channel_id/thread-members/@me", :delete)).wait
931
973
  else
932
- @client.http.delete("/channels/#{@id}/thread-members/#{Utils.try(member, :id)}").wait
974
+ @client.http.request(Route.new("/channels/#{@id}/thread-members/#{Utils.try(member, :id)}", "//channels/:channel_id/thread-members/:user_id", :delete)).wait
933
975
  end
934
976
  end
935
977
  end
936
978
 
937
979
  alias leave remove_member
938
980
 
981
+ #
982
+ # Fetch members in the thread.
983
+ #
984
+ # @return [Array<Discorb::ThreadChannel::Member>] The members in the thread.
985
+ #
939
986
  def fetch_members
940
987
  Async do
941
- _resp, data = @client.http.get("/channels/#{@id}/thread-members").wait
988
+ _resp, data = @client.http.request(Route.new("/channels/#{@id}/thread-members", "//channels/:channel_id/thread-members", :get)).wait
942
989
  data.map { |d| @members[d[:id]] = Member.new(@client, d) }
943
990
  end
944
991
  end
@@ -959,6 +1006,9 @@ module Discorb
959
1006
  attr_reader :channel_type
960
1007
  end
961
1008
 
1009
+ #
1010
+ # Repre
1011
+ #
962
1012
  class Member < DiscordModel
963
1013
  attr_reader :joined_at
964
1014
 
@@ -1010,24 +1060,26 @@ module Discorb
1010
1060
  end
1011
1061
 
1012
1062
  class CategoryChannel < GuildChannel
1013
- attr_reader :channels
1014
-
1015
1063
  @channel_type = 4
1016
1064
 
1065
+ def channels
1066
+ @client.channels.values.filter { |channel| channel.parent == self }
1067
+ end
1068
+
1017
1069
  def text_channels
1018
- @channels.filter { |c| c.is_a? TextChannel }
1070
+ channels.filter { |c| c.is_a? TextChannel }
1019
1071
  end
1020
1072
 
1021
1073
  def voice_channels
1022
- @channels.filter { |c| c.is_a? VoiceChannel }
1074
+ channels.filter { |c| c.is_a? VoiceChannel }
1023
1075
  end
1024
1076
 
1025
1077
  def news_channel
1026
- @channels.filter { |c| c.is_a? NewsChannel }
1078
+ channels.filter { |c| c.is_a? NewsChannel }
1027
1079
  end
1028
1080
 
1029
1081
  def stage_channels
1030
- @channels.filter { |c| c.is_a? StageChannel }
1082
+ channels.filter { |c| c.is_a? StageChannel }
1031
1083
  end
1032
1084
 
1033
1085
  def create_text_channel(*args, **kwargs)
@@ -1045,13 +1097,6 @@ module Discorb
1045
1097
  def create_stage_channel(*args, **kwargs)
1046
1098
  guild.create_stage_channel(*args, parent: self, **kwargs)
1047
1099
  end
1048
-
1049
- private
1050
-
1051
- def _set_data(data)
1052
- @channels = @client.channels.values.filter { |channel| channel.parent == self }
1053
- super
1054
- end
1055
1100
  end
1056
1101
 
1057
1102
  class DMChannel < Channel