discordrb 3.4.3 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +13 -0
  3. data/.devcontainer/devcontainer.json +29 -0
  4. data/.devcontainer/postcreate.sh +4 -0
  5. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -1
  6. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -1
  7. data/.github/workflows/ci.yml +78 -0
  8. data/.github/workflows/codeql.yml +65 -0
  9. data/.github/workflows/deploy.yml +54 -0
  10. data/.github/workflows/release.yml +45 -0
  11. data/.markdownlint.json +4 -0
  12. data/.rubocop.yml +58 -2
  13. data/CHANGELOG.md +485 -225
  14. data/LICENSE.txt +1 -1
  15. data/README.md +38 -26
  16. data/discordrb-webhooks.gemspec +4 -1
  17. data/discordrb.gemspec +18 -10
  18. data/lib/discordrb/api/application.rb +278 -0
  19. data/lib/discordrb/api/channel.rb +222 -18
  20. data/lib/discordrb/api/interaction.rb +63 -0
  21. data/lib/discordrb/api/invite.rb +2 -2
  22. data/lib/discordrb/api/server.rb +123 -66
  23. data/lib/discordrb/api/user.rb +20 -5
  24. data/lib/discordrb/api/webhook.rb +72 -0
  25. data/lib/discordrb/api.rb +35 -25
  26. data/lib/discordrb/bot.rb +437 -66
  27. data/lib/discordrb/cache.rb +41 -22
  28. data/lib/discordrb/commands/command_bot.rb +13 -21
  29. data/lib/discordrb/commands/container.rb +1 -1
  30. data/lib/discordrb/commands/parser.rb +7 -7
  31. data/lib/discordrb/commands/rate_limiter.rb +1 -1
  32. data/lib/discordrb/container.rb +178 -3
  33. data/lib/discordrb/data/activity.rb +1 -1
  34. data/lib/discordrb/data/application.rb +1 -0
  35. data/lib/discordrb/data/attachment.rb +38 -3
  36. data/lib/discordrb/data/audit_logs.rb +3 -3
  37. data/lib/discordrb/data/avatar_decoration.rb +26 -0
  38. data/lib/discordrb/data/call.rb +22 -0
  39. data/lib/discordrb/data/channel.rb +299 -30
  40. data/lib/discordrb/data/collectibles.rb +45 -0
  41. data/lib/discordrb/data/component.rb +229 -0
  42. data/lib/discordrb/data/embed.rb +10 -3
  43. data/lib/discordrb/data/emoji.rb +20 -1
  44. data/lib/discordrb/data/integration.rb +45 -3
  45. data/lib/discordrb/data/interaction.rb +937 -0
  46. data/lib/discordrb/data/invite.rb +1 -1
  47. data/lib/discordrb/data/member.rb +236 -44
  48. data/lib/discordrb/data/message.rb +278 -51
  49. data/lib/discordrb/data/overwrite.rb +15 -7
  50. data/lib/discordrb/data/primary_server.rb +60 -0
  51. data/lib/discordrb/data/profile.rb +2 -7
  52. data/lib/discordrb/data/reaction.rb +2 -1
  53. data/lib/discordrb/data/recipient.rb +1 -1
  54. data/lib/discordrb/data/role.rb +204 -18
  55. data/lib/discordrb/data/server.rb +194 -118
  56. data/lib/discordrb/data/server_preview.rb +68 -0
  57. data/lib/discordrb/data/snapshot.rb +110 -0
  58. data/lib/discordrb/data/user.rb +132 -12
  59. data/lib/discordrb/data/voice_region.rb +1 -0
  60. data/lib/discordrb/data/webhook.rb +99 -9
  61. data/lib/discordrb/data.rb +9 -0
  62. data/lib/discordrb/errors.rb +47 -3
  63. data/lib/discordrb/events/await.rb +1 -1
  64. data/lib/discordrb/events/channels.rb +38 -1
  65. data/lib/discordrb/events/generic.rb +2 -0
  66. data/lib/discordrb/events/guilds.rb +6 -1
  67. data/lib/discordrb/events/interactions.rb +575 -0
  68. data/lib/discordrb/events/invites.rb +2 -0
  69. data/lib/discordrb/events/members.rb +19 -2
  70. data/lib/discordrb/events/message.rb +42 -8
  71. data/lib/discordrb/events/presence.rb +23 -14
  72. data/lib/discordrb/events/raw.rb +1 -0
  73. data/lib/discordrb/events/reactions.rb +2 -1
  74. data/lib/discordrb/events/roles.rb +2 -0
  75. data/lib/discordrb/events/threads.rb +100 -0
  76. data/lib/discordrb/events/typing.rb +1 -0
  77. data/lib/discordrb/events/voice_server_update.rb +1 -0
  78. data/lib/discordrb/events/voice_state_update.rb +1 -0
  79. data/lib/discordrb/events/webhooks.rb +1 -0
  80. data/lib/discordrb/gateway.rb +57 -28
  81. data/lib/discordrb/paginator.rb +3 -3
  82. data/lib/discordrb/permissions.rb +71 -35
  83. data/lib/discordrb/version.rb +1 -1
  84. data/lib/discordrb/voice/encoder.rb +2 -2
  85. data/lib/discordrb/voice/network.rb +18 -7
  86. data/lib/discordrb/voice/sodium.rb +3 -1
  87. data/lib/discordrb/voice/voice_bot.rb +3 -3
  88. data/lib/discordrb/webhooks.rb +2 -0
  89. data/lib/discordrb/websocket.rb +0 -10
  90. data/lib/discordrb.rb +54 -5
  91. metadata +87 -25
  92. data/.circleci/config.yml +0 -126
  93. data/.codeclimate.yml +0 -16
  94. data/.travis.yml +0 -32
  95. data/bin/travis_build_docs.sh +0 -17
@@ -18,8 +18,8 @@ module Discordrb::API::Channel
18
18
 
19
19
  # Update a channel's data
20
20
  # https://discord.com/developers/docs/resources/channel#modify-channel
21
- def update(token, channel_id, name, topic, position, bitrate, user_limit, nsfw, permission_overwrites = nil, parent_id = nil, rate_limit_per_user = nil, reason = nil)
22
- data = { name: name, position: position, topic: topic, bitrate: bitrate, user_limit: user_limit, nsfw: nsfw, parent_id: parent_id, rate_limit_per_user: rate_limit_per_user }
21
+ def update(token, channel_id, name, topic, position, bitrate, user_limit, nsfw, permission_overwrites = nil, parent_id = nil, rate_limit_per_user = nil, reason = nil, archived = nil, auto_archive_duration = nil, locked = nil, invitable = nil, flags = nil, applied_tags = nil)
22
+ data = { name: name, position: position, topic: topic, bitrate: bitrate, user_limit: user_limit, nsfw: nsfw, parent_id: parent_id, rate_limit_per_user: rate_limit_per_user, archived: archived, auto_archive_duration: auto_archive_duration, locked: locked, invitable: invitable, flags: flags, applied_tags: applied_tags }
23
23
  data[:permission_overwrites] = permission_overwrites unless permission_overwrites.nil?
24
24
  Discordrb::API.request(
25
25
  :channels_cid,
@@ -49,11 +49,12 @@ module Discordrb::API::Channel
49
49
  # Get a list of messages from a channel's history
50
50
  # https://discord.com/developers/docs/resources/channel#get-channel-messages
51
51
  def messages(token, channel_id, amount, before = nil, after = nil, around = nil)
52
+ query_string = URI.encode_www_form({ limit: amount, before: before, after: after, around: around }.compact)
52
53
  Discordrb::API.request(
53
54
  :channels_cid_messages,
54
55
  channel_id,
55
56
  :get,
56
- "#{Discordrb::API.api_base}/channels/#{channel_id}/messages?limit=#{amount}#{"&before=#{before}" if before}#{"&after=#{after}" if after}#{"&around=#{around}" if around}",
57
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/messages?#{query_string}",
57
58
  Authorization: token
58
59
  )
59
60
  end
@@ -71,11 +72,11 @@ module Discordrb::API::Channel
71
72
  end
72
73
 
73
74
  # Send a message to a channel
74
- # https://discordapp.com/developers/docs/resources/channel#create-message
75
+ # https://discord.com/developers/docs/resources/channel#create-message
75
76
  # @param attachments [Array<File>, nil] Attachments to use with `attachment://` in embeds. See
76
77
  # https://discord.com/developers/docs/resources/channel#create-message-using-attachments-within-embeds
77
- def create_message(token, channel_id, message, tts = false, embed = nil, nonce = nil, attachments = nil, allowed_mentions = nil, message_reference = nil)
78
- body = { content: message, tts: tts, embed: embed, nonce: nonce, allowed_mentions: allowed_mentions, message_reference: message_reference }
78
+ def create_message(token, channel_id, message, tts = false, embeds = nil, nonce = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = nil, enforce_nonce = false)
79
+ body = { content: message, tts: tts, embeds: embeds, nonce: nonce, allowed_mentions: allowed_mentions, message_reference: message_reference, components: components&.to_a, flags: flags, enforce_nonce: enforce_nonce }
79
80
  body = if attachments
80
81
  files = [*0...attachments.size].zip(attachments).to_h
81
82
  { **files, payload_json: body.to_json }
@@ -116,20 +117,20 @@ module Discordrb::API::Channel
116
117
 
117
118
  # Edit a message
118
119
  # https://discord.com/developers/docs/resources/channel#edit-message
119
- def edit_message(token, channel_id, message_id, message, mentions = [], embed = nil)
120
+ def edit_message(token, channel_id, message_id, message, mentions = [], embeds = nil, components = nil, flags = nil)
120
121
  Discordrb::API.request(
121
122
  :channels_cid_messages_mid,
122
123
  channel_id,
123
124
  :patch,
124
125
  "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}",
125
- { content: message, mentions: mentions, embed: embed }.to_json,
126
+ { content: message, allowed_mentions: mentions, embeds: embeds, components: components, flags: flags }.reject { |_, v| v == :undef }.to_json,
126
127
  Authorization: token,
127
128
  content_type: :json
128
129
  )
129
130
  end
130
131
 
131
132
  # Delete a message
132
- # https://discordapp.com/developers/docs/resources/channel#delete-message
133
+ # https://discord.com/developers/docs/resources/channel#delete-message
133
134
  def delete_message(token, channel_id, message_id, reason = nil)
134
135
  Discordrb::API.request(
135
136
  :channels_cid_messages_mid,
@@ -141,8 +142,20 @@ module Discordrb::API::Channel
141
142
  )
142
143
  end
143
144
 
145
+ # Crosspost a message
146
+ # https://discord.com/developers/docs/resources/message#crosspost-message
147
+ def crosspost_message(token, channel_id, message_id)
148
+ Discordrb::API.request(
149
+ :channels_cid_messages_mid,
150
+ channel_id,
151
+ :post,
152
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/crosspost",
153
+ Authorization: token
154
+ )
155
+ end
156
+
144
157
  # Delete messages in bulk
145
- # https://discordapp.com/developers/docs/resources/channel#bulk-delete-messages
158
+ # https://discord.com/developers/docs/resources/channel#bulk-delete-messages
146
159
  def bulk_delete_messages(token, channel_id, messages = [], reason = nil)
147
160
  Discordrb::API.request(
148
161
  :channels_cid_messages_bulk_delete,
@@ -201,7 +214,7 @@ module Discordrb::API::Channel
201
214
  # https://discord.com/developers/docs/resources/channel#get-reactions
202
215
  def get_reactions(token, channel_id, message_id, emoji, before_id, after_id, limit = 100)
203
216
  emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
204
- query_string = "limit=#{limit}#{"&before=#{before_id}" if before_id}#{"&after=#{after_id}" if after_id}"
217
+ query_string = URI.encode_www_form({ limit: limit || 100, before: before_id, after: after_id }.compact)
205
218
  Discordrb::API.request(
206
219
  :channels_cid_messages_mid_reactions_emoji,
207
220
  channel_id,
@@ -223,6 +236,20 @@ module Discordrb::API::Channel
223
236
  )
224
237
  end
225
238
 
239
+ # Deletes all the reactions for a given emoji on a message
240
+ # https://discord.com/developers/docs/resources/channel#delete-all-reactions-for-emoji
241
+ def delete_all_emoji_reactions(token, channel_id, message_id, emoji)
242
+ emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
243
+
244
+ Discordrb::API.request(
245
+ :channels_cid_messages_mid_reactions_emoji,
246
+ channel_id,
247
+ :delete,
248
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}",
249
+ Authorization: token
250
+ )
251
+ end
252
+
226
253
  # Update a channels permission for a role or member
227
254
  # https://discord.com/developers/docs/resources/channel#edit-channel-permissions
228
255
  def update_permission(token, channel_id, overwrite_id, allow, deny, type, reason = nil)
@@ -292,25 +319,26 @@ module Discordrb::API::Channel
292
319
  end
293
320
 
294
321
  # Get a list of pinned messages in a channel
295
- # https://discord.com/developers/docs/resources/channel#get-pinned-messages
296
- def pinned_messages(token, channel_id)
322
+ # https://discord.com/developers/docs/resources/message#get-channel-pins
323
+ def pinned_messages(token, channel_id, limit = 50, before = nil)
324
+ query = URI.encode_www_form({ limit: limit, before: before }.compact)
297
325
  Discordrb::API.request(
298
326
  :channels_cid_pins,
299
327
  channel_id,
300
328
  :get,
301
- "#{Discordrb::API.api_base}/channels/#{channel_id}/pins",
329
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/pins?#{query}",
302
330
  Authorization: token
303
331
  )
304
332
  end
305
333
 
306
334
  # Pin a message
307
- # https://discordapp.com/developers/docs/resources/channel#add-pinned-channel-message
335
+ # https://discord.com/developers/docs/resources/message#pin-message
308
336
  def pin_message(token, channel_id, message_id, reason = nil)
309
337
  Discordrb::API.request(
310
338
  :channels_cid_pins_mid,
311
339
  channel_id,
312
340
  :put,
313
- "#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{message_id}",
341
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/pins/#{message_id}",
314
342
  nil,
315
343
  Authorization: token,
316
344
  'X-Audit-Log-Reason': reason
@@ -318,19 +346,20 @@ module Discordrb::API::Channel
318
346
  end
319
347
 
320
348
  # Unpin a message
321
- # https://discordapp.com/developers/docs/resources/channel#delete-pinned-channel-message
349
+ # https://discord.com/developers/docs/resources/message#unpin-message
322
350
  def unpin_message(token, channel_id, message_id, reason = nil)
323
351
  Discordrb::API.request(
324
352
  :channels_cid_pins_mid,
325
353
  channel_id,
326
354
  :delete,
327
- "#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{message_id}",
355
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/pins/#{message_id}",
328
356
  Authorization: token,
329
357
  'X-Audit-Log-Reason': reason
330
358
  )
331
359
  end
332
360
 
333
361
  # Create an empty group channel.
362
+ # @deprecated Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.
334
363
  # https://discord.com/developers/docs/resources/user#create-group-dm
335
364
  def create_empty_group(token, bot_user_id)
336
365
  Discordrb::API.request(
@@ -345,6 +374,7 @@ module Discordrb::API::Channel
345
374
  end
346
375
 
347
376
  # Create a group channel.
377
+ # @deprecated Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.
348
378
  # https://discord.com/developers/docs/resources/channel#group-dm-add-recipient
349
379
  def create_group(token, pm_channel_id, user_id)
350
380
  Discordrb::API.request(
@@ -365,6 +395,7 @@ module Discordrb::API::Channel
365
395
  end
366
396
 
367
397
  # Add a user to a group channel.
398
+ # @deprecated Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.
368
399
  # https://discord.com/developers/docs/resources/channel#group-dm-add-recipient
369
400
  def add_group_user(token, group_channel_id, user_id)
370
401
  Discordrb::API.request(
@@ -379,6 +410,7 @@ module Discordrb::API::Channel
379
410
  end
380
411
 
381
412
  # Remove a user from a group channel.
413
+ # @deprecated Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.
382
414
  # https://discord.com/developers/docs/resources/channel#group-dm-remove-recipient
383
415
  def remove_group_user(token, group_channel_id, user_id)
384
416
  Discordrb::API.request(
@@ -392,6 +424,7 @@ module Discordrb::API::Channel
392
424
  end
393
425
 
394
426
  # Leave a group channel.
427
+ # @deprecated Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.
395
428
  # https://discord.com/developers/docs/resources/channel#deleteclose-channel
396
429
  def leave_group(token, group_channel_id)
397
430
  Discordrb::API.request(
@@ -430,4 +463,175 @@ module Discordrb::API::Channel
430
463
  Authorization: token
431
464
  )
432
465
  end
466
+
467
+ # Start a thread based off a channel message.
468
+ # https://discord.com/developers/docs/resources/channel#start-thread-with-message
469
+ def start_thread_with_message(token, channel_id, message_id, name, auto_archive_duration)
470
+ Discordrb::API.request(
471
+ :channels_cid_messages_mid_threads,
472
+ channel_id,
473
+ :post,
474
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/threads",
475
+ { name: name, auto_archive_duration: auto_archive_duration }.to_json,
476
+ Authorization: token,
477
+ content_type: :json
478
+ )
479
+ end
480
+
481
+ # Start a thread without an associated message.
482
+ # https://discord.com/developers/docs/resources/channel#start-thread-without-message
483
+ def start_thread_without_message(token, channel_id, name, auto_archive_duration, type = 11)
484
+ Discordrb::API.request(
485
+ :channels_cid_threads,
486
+ channel_id,
487
+ :post,
488
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/threads",
489
+ { name: name, auto_archive_duration: auto_archive_duration, type: type },
490
+ Authorization: token,
491
+ content_type: :json
492
+ )
493
+ end
494
+
495
+ # Add the current user to a thread.
496
+ # https://discord.com/developers/docs/resources/channel#join-thread
497
+ def join_thread(token, channel_id)
498
+ Discordrb::API.request(
499
+ :channels_cid_thread_members_me,
500
+ channel_id,
501
+ :put,
502
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/thread-members/@me",
503
+ nil,
504
+ Authorization: token
505
+ )
506
+ end
507
+
508
+ # Add a user to a thread.
509
+ # https://discord.com/developers/docs/resources/channel#add-thread-member
510
+ def add_thread_member(token, channel_id, user_id)
511
+ Discordrb::API.request(
512
+ :channels_cid_thread_members_uid,
513
+ channel_id,
514
+ :put,
515
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
516
+ nil,
517
+ Authorization: token
518
+ )
519
+ end
520
+
521
+ # Remove the current user from a thread.
522
+ # https://discord.com/developers/docs/resources/channel#leave-thread
523
+ def leave_thread(token, channel_id)
524
+ Discordrb::API.request(
525
+ :channels_cid_thread_members_me,
526
+ channel_id,
527
+ :delete,
528
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
529
+ Authorization: token
530
+ )
531
+ end
532
+
533
+ # Remove a user from a thread.
534
+ # https://discord.com/developers/docs/resources/channel#remove-thread-member
535
+ def remove_thread_member(token, channel_id, user_id)
536
+ Discordrb::API.request(
537
+ :channels_cid_thread_members_uid,
538
+ channel_id,
539
+ :delete,
540
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
541
+ Authorization: token
542
+ )
543
+ end
544
+
545
+ # Get the members of a thread.
546
+ # https://discord.com/developers/docs/resources/channel#list-thread-members
547
+ def list_thread_members(token, channel_id, before, limit)
548
+ query = URI.encode_www_form({ before: before, limit: limit }.compact)
549
+
550
+ Discordrb::API.request(
551
+ :channels_cid_thread_members,
552
+ channel_id,
553
+ :get,
554
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/thread-members?#{query}",
555
+ Authorization: token
556
+ )
557
+ end
558
+
559
+ # List active threads
560
+ # https://discord.com/developers/docs/resources/channel#list-active-threads
561
+ def list_active_threads(token, channel_id)
562
+ Discordrb::API.request(
563
+ :channels_cid_threads_active,
564
+ channel_id,
565
+ :get,
566
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/threads/active",
567
+ Authorization: token
568
+ )
569
+ end
570
+
571
+ # List public archived threads.
572
+ # https://discord.com/developers/docs/resources/channel#list-public-archived-threads
573
+ def list_public_archived_threads(token, channel_id, before = nil, limit = nil)
574
+ query = URI.encode_www_form({ before: before, limit: limit }.compact)
575
+
576
+ Discordrb::API.request(
577
+ :channels_cid_threads_archived_public,
578
+ channel_id,
579
+ :get,
580
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/threads/archived/public?#{query}",
581
+ Authorization: token
582
+ )
583
+ end
584
+
585
+ # List private archived threads.
586
+ # https://discord.com/developers/docs/resources/channel#list-private-archived-threads
587
+ def list_private_archived_threads(token, channel_id, before = nil, limit = nil)
588
+ query = URI.encode_www_form({ before: before, limit: limit }.compact)
589
+
590
+ Discordrb::API.request(
591
+ :channels_cid_threads_archived_private,
592
+ channel_id,
593
+ :get,
594
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/threads/archived/private?#{query}",
595
+ Authorization: token
596
+ )
597
+ end
598
+
599
+ # List joined private archived threads.
600
+ # https://discord.com/developers/docs/resources/channel#list-joined-private-archived-threads
601
+ def list_joined_private_archived_threads(token, channel_id, before = nil, limit = nil)
602
+ query = URI.encode_www_form({ before: before, limit: limit }.compact)
603
+
604
+ Discordrb::API.request(
605
+ :channels_cid_users_me_threads_archived_private,
606
+ channel_id,
607
+ :get,
608
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/users/@me/threads/archived/private?#{query}",
609
+ Authorization: token
610
+ )
611
+ end
612
+
613
+ # Start a thread in a forum or media channel.
614
+ # https://discord.com/developers/docs/resources/channel#start-thread-in-forum-or-media-channel
615
+ def start_thread_in_forum_or_media_channel(token, channel_id, name, message, attachments = nil, rate_limit_per_user = nil, auto_archive_duration = nil, applied_tags = [], reason = nil)
616
+ body = { name: name, message: message, rate_limit_per_user: rate_limit_per_user, auto_archive_duration: auto_archive_duration, applied_tags: applied_tags }.compact
617
+
618
+ body = if attachments
619
+ files = [*0...attachments.size].zip(attachments).to_h
620
+ { **files, payload_json: body.to_json }
621
+ else
622
+ body.to_json
623
+ end
624
+
625
+ headers = { Authorization: token, 'X-Audit-Log-Reason': reason }
626
+ headers[:content_type] = :json unless attachments
627
+
628
+ Discordrb::API.request(
629
+ :channels_cid_threads,
630
+ channel_id,
631
+ :post,
632
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/threads",
633
+ body,
634
+ headers
635
+ )
636
+ end
433
637
  end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ # API calls for interactions.
4
+ module Discordrb::API::Interaction
5
+ module_function
6
+
7
+ # Respond to an interaction.
8
+ # https://discord.com/developers/docs/interactions/slash-commands#create-interaction-response
9
+ def create_interaction_response(interaction_token, interaction_id, type, content = nil, tts = nil, embeds = nil, allowed_mentions = nil, flags = nil, components = nil, attachments = nil, choices = nil)
10
+ body = { tts: tts, content: content, embeds: embeds, allowed_mentions: allowed_mentions, flags: flags, components: components, choices: choices }.compact
11
+
12
+ body = if attachments
13
+ files = [*0...attachments.size].zip(attachments).to_h
14
+ { **files, payload_json: { type: type, data: body }.to_json }
15
+ else
16
+ { type: type, data: body }.to_json
17
+ end
18
+
19
+ headers = { content_type: :json } unless attachments
20
+
21
+ Discordrb::API.request(
22
+ :interactions_iid_token_callback,
23
+ interaction_id,
24
+ :post,
25
+ "#{Discordrb::API.api_base}/interactions/#{interaction_id}/#{interaction_token}/callback",
26
+ body,
27
+ headers
28
+ )
29
+ end
30
+
31
+ # Create a response that results in a modal.
32
+ # https://discord.com/developers/docs/interactions/slash-commands#create-interaction-response
33
+ def create_interaction_modal_response(interaction_token, interaction_id, custom_id, title, components)
34
+ data = { custom_id: custom_id, title: title, components: components.to_a }.compact
35
+
36
+ Discordrb::API.request(
37
+ :interactions_iid_token_callback,
38
+ interaction_id,
39
+ :post,
40
+ "#{Discordrb::API.api_base}/interactions/#{interaction_id}/#{interaction_token}/callback",
41
+ { type: 9, data: data }.to_json,
42
+ content_type: :json
43
+ )
44
+ end
45
+
46
+ # Get the original response to an interaction.
47
+ # https://discord.com/developers/docs/interactions/slash-commands#get-original-interaction-response
48
+ def get_original_interaction_response(interaction_token, application_id)
49
+ Discordrb::API::Webhook.token_get_message(interaction_token, application_id, '@original')
50
+ end
51
+
52
+ # Edit the original response to an interaction.
53
+ # https://discord.com/developers/docs/interactions/slash-commands#edit-original-interaction-response
54
+ def edit_original_interaction_response(interaction_token, application_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil, attachments = nil)
55
+ Discordrb::API::Webhook.token_edit_message(interaction_token, application_id, '@original', content, embeds, allowed_mentions, components, attachments)
56
+ end
57
+
58
+ # Delete the original response to an interaction.
59
+ # https://discord.com/developers/docs/interactions/slash-commands#delete-original-interaction-response
60
+ def delete_original_interaction_response(interaction_token, application_id)
61
+ Discordrb::API::Webhook.token_delete_message(interaction_token, application_id, '@original')
62
+ end
63
+ end
@@ -11,7 +11,7 @@ module Discordrb::API::Invite
11
11
  :invite_code,
12
12
  nil,
13
13
  :get,
14
- "#{Discordrb::API.api_base}/invite/#{invite_code}#{counts ? '?with_counts=true' : ''}",
14
+ "#{Discordrb::API.api_base}/invites/#{invite_code}#{'?with_counts=true' if counts}",
15
15
  Authorization: token
16
16
  )
17
17
  end
@@ -36,7 +36,7 @@ module Discordrb::API::Invite
36
36
  :invite_code,
37
37
  nil,
38
38
  :post,
39
- "#{Discordrb::API.api_base}/invite/#{invite_code}",
39
+ "#{Discordrb::API.api_base}/invites/#{invite_code}",
40
40
  nil,
41
41
  Authorization: token
42
42
  )