discorb 0.19.0 → 0.20.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 (88) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build_version.yml +2 -2
  3. data/.rubocop.yml +12 -75
  4. data/Changelog.md +10 -0
  5. data/Rakefile +482 -454
  6. data/lib/discorb/allowed_mentions.rb +68 -72
  7. data/lib/discorb/app_command/command.rb +466 -398
  8. data/lib/discorb/app_command/common.rb +65 -25
  9. data/lib/discorb/app_command/handler.rb +304 -266
  10. data/lib/discorb/app_command.rb +5 -5
  11. data/lib/discorb/application.rb +198 -197
  12. data/lib/discorb/asset.rb +101 -101
  13. data/lib/discorb/attachment.rb +134 -119
  14. data/lib/discorb/audit_logs.rb +412 -385
  15. data/lib/discorb/automod.rb +279 -269
  16. data/lib/discorb/channel/base.rb +107 -108
  17. data/lib/discorb/channel/category.rb +32 -32
  18. data/lib/discorb/channel/container.rb +44 -44
  19. data/lib/discorb/channel/dm.rb +26 -28
  20. data/lib/discorb/channel/guild.rb +311 -246
  21. data/lib/discorb/channel/stage.rb +156 -140
  22. data/lib/discorb/channel/text.rb +430 -336
  23. data/lib/discorb/channel/thread.rb +374 -325
  24. data/lib/discorb/channel/voice.rb +85 -79
  25. data/lib/discorb/channel.rb +5 -5
  26. data/lib/discorb/client.rb +635 -621
  27. data/lib/discorb/color.rb +178 -182
  28. data/lib/discorb/common.rb +168 -164
  29. data/lib/discorb/components/button.rb +107 -106
  30. data/lib/discorb/components/select_menu.rb +157 -145
  31. data/lib/discorb/components/text_input.rb +103 -106
  32. data/lib/discorb/components.rb +68 -66
  33. data/lib/discorb/dictionary.rb +135 -135
  34. data/lib/discorb/embed.rb +404 -398
  35. data/lib/discorb/emoji.rb +309 -302
  36. data/lib/discorb/emoji_table.rb +16099 -8857
  37. data/lib/discorb/error.rb +131 -131
  38. data/lib/discorb/event.rb +360 -314
  39. data/lib/discorb/event_handler.rb +39 -39
  40. data/lib/discorb/exe/about.rb +17 -17
  41. data/lib/discorb/exe/irb.rb +72 -67
  42. data/lib/discorb/exe/new.rb +323 -315
  43. data/lib/discorb/exe/run.rb +69 -68
  44. data/lib/discorb/exe/setup.rb +57 -55
  45. data/lib/discorb/exe/show.rb +12 -12
  46. data/lib/discorb/extend.rb +25 -45
  47. data/lib/discorb/extension.rb +89 -83
  48. data/lib/discorb/flag.rb +126 -128
  49. data/lib/discorb/gateway.rb +984 -804
  50. data/lib/discorb/gateway_events.rb +670 -638
  51. data/lib/discorb/gateway_requests.rb +45 -48
  52. data/lib/discorb/guild.rb +2115 -1626
  53. data/lib/discorb/guild_template.rb +280 -241
  54. data/lib/discorb/http.rb +247 -232
  55. data/lib/discorb/image.rb +42 -42
  56. data/lib/discorb/integration.rb +169 -161
  57. data/lib/discorb/intents.rb +161 -163
  58. data/lib/discorb/interaction/autocomplete.rb +76 -62
  59. data/lib/discorb/interaction/command.rb +279 -224
  60. data/lib/discorb/interaction/components.rb +114 -104
  61. data/lib/discorb/interaction/modal.rb +36 -32
  62. data/lib/discorb/interaction/response.rb +379 -336
  63. data/lib/discorb/interaction/root.rb +271 -257
  64. data/lib/discorb/interaction.rb +5 -5
  65. data/lib/discorb/invite.rb +154 -153
  66. data/lib/discorb/member.rb +344 -311
  67. data/lib/discorb/message.rb +615 -544
  68. data/lib/discorb/message_meta.rb +197 -186
  69. data/lib/discorb/modules.rb +371 -290
  70. data/lib/discorb/permission.rb +305 -291
  71. data/lib/discorb/presence.rb +352 -346
  72. data/lib/discorb/rate_limit.rb +81 -76
  73. data/lib/discorb/reaction.rb +55 -54
  74. data/lib/discorb/role.rb +272 -240
  75. data/lib/discorb/shard.rb +76 -74
  76. data/lib/discorb/sticker.rb +193 -171
  77. data/lib/discorb/user.rb +205 -188
  78. data/lib/discorb/utils/colored_puts.rb +16 -16
  79. data/lib/discorb/utils.rb +12 -16
  80. data/lib/discorb/voice_state.rb +305 -281
  81. data/lib/discorb/webhook.rb +537 -507
  82. data/lib/discorb.rb +62 -56
  83. data/sig/discorb/application.rbs +2 -0
  84. data/sig/discorb/automod.rbs +10 -1
  85. data/sig/discorb/guild.rbs +2 -0
  86. data/sig/discorb/message.rbs +2 -0
  87. data/sig/discorb/user.rbs +22 -20
  88. metadata +2 -2
@@ -1,336 +1,379 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- #
5
- # Represents an interaction of Discord.
6
- #
7
- class Interaction
8
- #
9
- # A module for response with source.
10
- #
11
- module SourceResponder
12
- # @type instance: Discorb::Interaction
13
-
14
- #
15
- # Response with `DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE`(`5`).
16
- #
17
- # @async
18
- #
19
- # @param [Boolean] ephemeral Whether to make the response ephemeral.
20
- #
21
- # @return [Async::Task<void>] The task.
22
- #
23
- def defer_source(ephemeral: false)
24
- Async do
25
- @client.http.request(
26
- Route.new(
27
- "/interactions/#{@id}/#{@token}/callback",
28
- "//interactions/:interaction_id/:token/callback",
29
- :post
30
- ), {
31
- type: 5,
32
- data: {
33
- flags: (ephemeral ? 1 << 6 : 0),
34
- },
35
- }
36
- ).wait
37
- @defered = true
38
- end
39
- end
40
-
41
- #
42
- # Response with `CHANNEL_MESSAGE_WITH_SOURCE`(`4`).
43
- #
44
- # @async
45
- #
46
- # @param [String] content The content of the response.
47
- # @param [Boolean] tts Whether to send the message as text-to-speech.
48
- # @param [Discorb::Embed] embed The embed to send.
49
- # @param [Array<Discorb::Embed>] embeds The embeds to send. (max: 10)
50
- # @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions to send.
51
- # @param [Discorb::Attachment] attachment The attachment to send.
52
- # @param [Array<Discorb::Attachment>] attachments The attachments to send. (max: 10)
53
- # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
54
- # @param [Boolean] ephemeral Whether to make the response ephemeral.
55
- #
56
- # @return [Discorb::Interaction::SourceResponder::CallbackMessage, Discorb::Webhook::Message]
57
- # The callback message.
58
- #
59
- def post(
60
- content = nil,
61
- tts: false,
62
- embed: nil,
63
- embeds: nil,
64
- allowed_mentions: nil,
65
- attachment: nil,
66
- attachments: nil,
67
- components: nil,
68
- ephemeral: false
69
- )
70
- Async do
71
- payload = {}
72
- payload[:content] = content if content
73
- payload[:tts] = tts
74
- payload[:embeds] = (embeds || [embed]).map { |e| e&.to_hash }.filter { _1 }
75
- payload[:allowed_mentions] =
76
- allowed_mentions&.to_hash(@client.allowed_mentions) || @client.allowed_mentions.to_hash
77
- payload[:components] = Component.to_payload(components) if components
78
- payload[:flags] = (ephemeral ? 1 << 6 : 0)
79
- attachments ||= attachment ? [attachment] : []
80
-
81
- payload[:attachments] = attachments.map.with_index do |a, i|
82
- {
83
- id: i,
84
- filename: a.filename,
85
- description: a.description,
86
- }
87
- end
88
-
89
- ret = if @responded
90
- _resp, data = @client.http.multipart_request(
91
- Route.new(
92
- "/webhooks/#{@application_id}/#{@token}",
93
- "//webhooks/:webhook_id/:token",
94
- :post
95
- ),
96
- payload,
97
- attachments
98
- ).wait
99
- webhook = Webhook::URLWebhook.new("/webhooks/#{@application_id}/#{@token}")
100
- Webhook::Message.new(webhook, data, @client)
101
- elsif @defered
102
- @client.http.multipart_request(
103
- Route.new(
104
- "/webhooks/#{@application_id}/#{@token}/messages/@original",
105
- "//webhooks/:webhook_id/:token/messages/@original",
106
- :patch
107
- ),
108
- payload,
109
- attachments
110
- ).wait
111
- CallbackMessage.new(@client, payload, @application_id, @token)
112
- else
113
- @client.http.multipart_request(
114
- Route.new(
115
- "/interactions/#{@id}/#{@token}/callback",
116
- "//interactions/:interaction_id/:token/callback",
117
- :post
118
- ),
119
- { type: 4, data: payload },
120
- attachments
121
- ).wait
122
- CallbackMessage.new(@client, payload, @application_id, @token)
123
- end
124
- @responded = true
125
- ret
126
- end
127
- end
128
- end
129
-
130
- #
131
- # Represents of a callback message of interaction.
132
- #
133
- class CallbackMessage
134
- #
135
- # Initializes a new instance of CallbackMessage.
136
- # @private
137
- #
138
- # @param [Client] client The client.
139
- # @param [Hash] data The payload.
140
- # @param [String] application_id The application ID.
141
- # @param [String] token The token.
142
- #
143
- def initialize(client, data, application_id, token)
144
- @client = client
145
- @data = data
146
- @application_id = application_id
147
- @token = token
148
- end
149
-
150
- #
151
- # Edits the callback message.
152
- # @async
153
- # @macro edit
154
- #
155
- # @param [String] content The new content of the message.
156
- # @param [Discorb::Embed] embed The new embed of the message.
157
- # @param [Array<Discorb::Embed>] embeds The new embeds of the message.
158
- # @param [Array<Discorb::Attachment>] attachments The attachments to remain.
159
- # @param [Discorb::Attachment] file The file to send.
160
- # @param [Array<Discorb::Attachment>] files The files to send.
161
- #
162
- # @return [Async::Task<void>] The task.
163
- #
164
- def edit(
165
- content = Discorb::Unset,
166
- embed: Discorb::Unset, embeds: Discorb::Unset,
167
- file: Discorb::Unset, files: Discorb::Unset,
168
- attachments: Discorb::Unset
169
- )
170
- Async do
171
- payload = {}
172
- payload[:content] = content if content != Discorb::Unset
173
- payload[:embeds] = embed ? [embed.to_hash] : [] if embed != Discorb::Unset
174
- payload[:embeds] = embeds.map(&:to_hash) if embeds != Discorb::Unset
175
- payload[:attachments] = attachments.map(&:to_hash) if attachments != Discorb::Unset
176
- files = [file] if file != Discorb::Unset
177
- files = [] if files == Discorb::Unset
178
- @client.http.multipart_request(
179
- Route.new(
180
- "/webhooks/#{@application_id}/#{@token}/messages/@original",
181
- "//webhooks/:webhook_id/:token/messages/@original",
182
- :patch
183
- ),
184
- payload,
185
- files,
186
- ).wait
187
- end
188
- end
189
-
190
- alias modify edit
191
-
192
- #
193
- # Deletes the callback message.
194
- # @async
195
- # @note This will fail if the message is ephemeral.
196
- #
197
- # @return [Async::Task<void>] The task.
198
- #
199
- def delete
200
- Async do
201
- @client.http.request(Route.new("/webhooks/#{@application_id}/#{@token}/messages/@original",
202
- "//webhooks/:webhook_id/:token/messages/@original", :delete)).wait
203
- end
204
- end
205
-
206
- def inspect
207
- "#<#{self.class.name} application_id=#{@application_id}"
208
- end
209
- end
210
-
211
- #
212
- # A module for response with update.
213
- #
214
- module UpdateResponder
215
- # @type instance: Discorb::Interaction
216
-
217
- #
218
- # Response with `DEFERRED_UPDATE_MESSAGE`(`6`).
219
- # @async
220
- #
221
- # @param [Boolean] ephemeral Whether to make the response ephemeral.
222
- #
223
- # @return [Async::Task<void>] The task.
224
- #
225
- def defer_update(ephemeral: false)
226
- Async do
227
- @client.http.request(
228
- Route.new(
229
- "/interactions/#{@id}/#{@token}/callback",
230
- "//interactions/:interaction_id/:token/callback",
231
- :post
232
- ), {
233
- type: 6,
234
- data: {
235
- flags: (ephemeral ? 1 << 6 : 0),
236
- },
237
- }
238
- ).wait
239
- end
240
- end
241
-
242
- #
243
- # Response with `UPDATE_MESSAGE`(`7`).
244
- #
245
- # @async
246
- #
247
- # @param [String] content The content of the response.
248
- # @param [Boolean] tts Whether to send the message as text-to-speech.
249
- # @param [Discorb::Embed] embed The embed to send.
250
- # @param [Array<Discorb::Embed>] embeds The embeds to send. (max: 10)
251
- # @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions to send.
252
- # @param [Discorb::Attachment] attachment The attachment to send.
253
- # @param [Array<Discorb::Attachment>] attachments The attachments to send. (max: 10)
254
- # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
255
- # @param [Boolean] ephemeral Whether to make the response ephemeral.
256
- #
257
- # @return [Async::Task<void>] The task.
258
- #
259
- def edit(
260
- content,
261
- tts: false,
262
- embed: nil,
263
- embeds: nil,
264
- allowed_mentions: nil,
265
- attachment: nil,
266
- attachments: nil,
267
- components: nil,
268
- ephemeral: false
269
- )
270
- Async do
271
- payload = {}
272
- payload[:content] = content if content
273
- payload[:tts] = tts
274
- tmp_embed = if embed
275
- [embed]
276
- elsif embeds
277
- embeds
278
- end
279
- payload[:embeds] = tmp_embed.map(&:to_hash) if tmp_embed
280
- payload[:allowed_mentions] =
281
- allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
282
- payload[:components] = Component.to_payload(components) if components
283
- payload[:flags] = (ephemeral ? 1 << 6 : 0)
284
- attachments ||= [attachment] if attachment
285
- payload[:attachments] = attachments.map.with_index do |a, i|
286
- {
287
- id: i,
288
- filename: a.filename,
289
- description: a.description,
290
- }
291
- end
292
- @client.http.multipart_request(
293
- Route.new("/interactions/#{@id}/#{@token}/callback", "//interactions/:interaction_id/:token/callback",
294
- :post), { type: 7, data: payload }, attachments
295
- ).wait
296
- end
297
- end
298
- end
299
-
300
- #
301
- # A module for response with modal.
302
- #
303
- module ModalResponder
304
- # @type instance: Discorb::Interaction
305
-
306
- #
307
- # Response with `MODAL`(`9`).
308
- #
309
- # @param [String] title The title of the modal.
310
- # @param [String] custom_id The custom id of the modal.
311
- # @param [Array<Discorb::TextInput>] components The text inputs to send.
312
- #
313
- # @return [Async::Task<void>] The task.
314
- #
315
- def show_modal(title, custom_id, components)
316
- Async do
317
- payload = { title: title, custom_id: custom_id, components: Component.to_payload(components) }
318
- @client.http.request(
319
- Route.new(
320
- "/interactions/#{@id}/#{@token}/callback",
321
- "//interactions/:interaction_id/:token/callback",
322
- :post
323
- ),
324
- { type: 9, data: payload }
325
- ).wait
326
- end
327
- end
328
- end
329
-
330
- private
331
-
332
- def _set_data(_)
333
- nil
334
- end
335
- end
336
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Represents an interaction of Discord.
6
+ #
7
+ class Interaction
8
+ #
9
+ # A module for response with source.
10
+ #
11
+ module SourceResponder
12
+ # @type instance: Discorb::Interaction
13
+
14
+ #
15
+ # Response with `DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE`(`5`).
16
+ #
17
+ # @async
18
+ #
19
+ # @param [Boolean] ephemeral Whether to make the response ephemeral.
20
+ #
21
+ # @return [Async::Task<void>] The task.
22
+ #
23
+ def defer_source(ephemeral: false)
24
+ Async do
25
+ @client
26
+ .http
27
+ .request(
28
+ Route.new(
29
+ "/interactions/#{@id}/#{@token}/callback",
30
+ "//interactions/:interaction_id/:token/callback",
31
+ :post
32
+ ),
33
+ { type: 5, data: { flags: (ephemeral ? 1 << 6 : 0) } }
34
+ )
35
+ .wait
36
+ @defered = true
37
+ end
38
+ end
39
+
40
+ #
41
+ # Response with `CHANNEL_MESSAGE_WITH_SOURCE`(`4`).
42
+ #
43
+ # @async
44
+ #
45
+ # @param [String] content The content of the response.
46
+ # @param [Boolean] tts Whether to send the message as text-to-speech.
47
+ # @param [Discorb::Embed] embed The embed to send.
48
+ # @param [Array<Discorb::Embed>] embeds The embeds to send. (max: 10)
49
+ # @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions to send.
50
+ # @param [Discorb::Attachment] attachment The attachment to send.
51
+ # @param [Array<Discorb::Attachment>] attachments The attachments to send. (max: 10)
52
+ # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
53
+ # @param [Boolean] ephemeral Whether to make the response ephemeral.
54
+ #
55
+ # @return [Discorb::Interaction::SourceResponder::CallbackMessage, Discorb::Webhook::Message]
56
+ # The callback message.
57
+ #
58
+ def post(
59
+ content = nil,
60
+ tts: false,
61
+ embed: nil,
62
+ embeds: nil,
63
+ allowed_mentions: nil,
64
+ attachment: nil,
65
+ attachments: nil,
66
+ components: nil,
67
+ ephemeral: false
68
+ )
69
+ Async do
70
+ payload = {}
71
+ payload[:content] = content if content
72
+ payload[:tts] = tts
73
+ payload[:embeds] = (embeds || [embed])
74
+ .map { |e| e&.to_hash }
75
+ .filter { _1 }
76
+ payload[:allowed_mentions] = allowed_mentions&.to_hash(
77
+ @client.allowed_mentions
78
+ ) || @client.allowed_mentions.to_hash
79
+ payload[:components] = Component.to_payload(components) if components
80
+ payload[:flags] = (ephemeral ? 1 << 6 : 0)
81
+ attachments ||= attachment ? [attachment] : []
82
+
83
+ payload[:attachments] = attachments.map.with_index do |a, i|
84
+ { id: i, filename: a.filename, description: a.description }
85
+ end
86
+
87
+ ret =
88
+ if @responded
89
+ _resp, data =
90
+ @client
91
+ .http
92
+ .multipart_request(
93
+ Route.new(
94
+ "/webhooks/#{@application_id}/#{@token}",
95
+ "//webhooks/:webhook_id/:token",
96
+ :post
97
+ ),
98
+ payload,
99
+ attachments
100
+ )
101
+ .wait
102
+ webhook =
103
+ Webhook::URLWebhook.new(
104
+ "/webhooks/#{@application_id}/#{@token}"
105
+ )
106
+ Webhook::Message.new(webhook, data, @client)
107
+ elsif @defered
108
+ @client
109
+ .http
110
+ .multipart_request(
111
+ Route.new(
112
+ "/webhooks/#{@application_id}/#{@token}/messages/@original",
113
+ "//webhooks/:webhook_id/:token/messages/@original",
114
+ :patch
115
+ ),
116
+ payload,
117
+ attachments
118
+ )
119
+ .wait
120
+ CallbackMessage.new(@client, payload, @application_id, @token)
121
+ else
122
+ @client
123
+ .http
124
+ .multipart_request(
125
+ Route.new(
126
+ "/interactions/#{@id}/#{@token}/callback",
127
+ "//interactions/:interaction_id/:token/callback",
128
+ :post
129
+ ),
130
+ { type: 4, data: payload },
131
+ attachments
132
+ )
133
+ .wait
134
+ CallbackMessage.new(@client, payload, @application_id, @token)
135
+ end
136
+ @responded = true
137
+ ret
138
+ end
139
+ end
140
+ end
141
+
142
+ #
143
+ # Represents of a callback message of interaction.
144
+ #
145
+ class CallbackMessage
146
+ #
147
+ # Initializes a new instance of CallbackMessage.
148
+ # @private
149
+ #
150
+ # @param [Client] client The client.
151
+ # @param [Hash] data The payload.
152
+ # @param [String] application_id The application ID.
153
+ # @param [String] token The token.
154
+ #
155
+ def initialize(client, data, application_id, token)
156
+ @client = client
157
+ @data = data
158
+ @application_id = application_id
159
+ @token = token
160
+ end
161
+
162
+ #
163
+ # Edits the callback message.
164
+ # @async
165
+ # @macro edit
166
+ #
167
+ # @param [String] content The new content of the message.
168
+ # @param [Discorb::Embed] embed The new embed of the message.
169
+ # @param [Array<Discorb::Embed>] embeds The new embeds of the message.
170
+ # @param [Array<Discorb::Attachment>] attachments The attachments to remain.
171
+ # @param [Discorb::Attachment] file The file to send.
172
+ # @param [Array<Discorb::Attachment>] files The files to send.
173
+ #
174
+ # @return [Async::Task<void>] The task.
175
+ #
176
+ def edit(
177
+ content = Discorb::Unset,
178
+ embed: Discorb::Unset,
179
+ embeds: Discorb::Unset,
180
+ file: Discorb::Unset,
181
+ files: Discorb::Unset,
182
+ attachments: Discorb::Unset
183
+ )
184
+ Async do
185
+ payload = {}
186
+ payload[:content] = content if content != Discorb::Unset
187
+ payload[:embeds] = embed ? [embed.to_hash] : [] if embed !=
188
+ Discorb::Unset
189
+ payload[:embeds] = embeds.map(&:to_hash) if embeds != Discorb::Unset
190
+ payload[:attachments] = attachments.map(&:to_hash) if attachments !=
191
+ Discorb::Unset
192
+ files = [file] if file != Discorb::Unset
193
+ files = [] if files == Discorb::Unset
194
+ @client
195
+ .http
196
+ .multipart_request(
197
+ Route.new(
198
+ "/webhooks/#{@application_id}/#{@token}/messages/@original",
199
+ "//webhooks/:webhook_id/:token/messages/@original",
200
+ :patch
201
+ ),
202
+ payload,
203
+ files
204
+ )
205
+ .wait
206
+ end
207
+ end
208
+
209
+ alias modify edit
210
+
211
+ #
212
+ # Deletes the callback message.
213
+ # @async
214
+ # @note This will fail if the message is ephemeral.
215
+ #
216
+ # @return [Async::Task<void>] The task.
217
+ #
218
+ def delete
219
+ Async do
220
+ @client
221
+ .http
222
+ .request(
223
+ Route.new(
224
+ "/webhooks/#{@application_id}/#{@token}/messages/@original",
225
+ "//webhooks/:webhook_id/:token/messages/@original",
226
+ :delete
227
+ )
228
+ )
229
+ .wait
230
+ end
231
+ end
232
+
233
+ def inspect
234
+ "#<#{self.class.name} application_id=#{@application_id}"
235
+ end
236
+ end
237
+
238
+ #
239
+ # A module for response with update.
240
+ #
241
+ module UpdateResponder
242
+ # @type instance: Discorb::Interaction
243
+
244
+ #
245
+ # Response with `DEFERRED_UPDATE_MESSAGE`(`6`).
246
+ # @async
247
+ #
248
+ # @param [Boolean] ephemeral Whether to make the response ephemeral.
249
+ #
250
+ # @return [Async::Task<void>] The task.
251
+ #
252
+ def defer_update(ephemeral: false)
253
+ Async do
254
+ @client
255
+ .http
256
+ .request(
257
+ Route.new(
258
+ "/interactions/#{@id}/#{@token}/callback",
259
+ "//interactions/:interaction_id/:token/callback",
260
+ :post
261
+ ),
262
+ { type: 6, data: { flags: (ephemeral ? 1 << 6 : 0) } }
263
+ )
264
+ .wait
265
+ end
266
+ end
267
+
268
+ #
269
+ # Response with `UPDATE_MESSAGE`(`7`).
270
+ #
271
+ # @async
272
+ #
273
+ # @param [String] content The content of the response.
274
+ # @param [Boolean] tts Whether to send the message as text-to-speech.
275
+ # @param [Discorb::Embed] embed The embed to send.
276
+ # @param [Array<Discorb::Embed>] embeds The embeds to send. (max: 10)
277
+ # @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions to send.
278
+ # @param [Discorb::Attachment] attachment The attachment to send.
279
+ # @param [Array<Discorb::Attachment>] attachments The attachments to send. (max: 10)
280
+ # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
281
+ # @param [Boolean] ephemeral Whether to make the response ephemeral.
282
+ #
283
+ # @return [Async::Task<void>] The task.
284
+ #
285
+ def edit(
286
+ content,
287
+ tts: false,
288
+ embed: nil,
289
+ embeds: nil,
290
+ allowed_mentions: nil,
291
+ attachment: nil,
292
+ attachments: nil,
293
+ components: nil,
294
+ ephemeral: false
295
+ )
296
+ Async do
297
+ payload = {}
298
+ payload[:content] = content if content
299
+ payload[:tts] = tts
300
+ tmp_embed =
301
+ if embed
302
+ [embed]
303
+ elsif embeds
304
+ embeds
305
+ end
306
+ payload[:embeds] = tmp_embed.map(&:to_hash) if tmp_embed
307
+ payload[:allowed_mentions] = (
308
+ if allowed_mentions
309
+ allowed_mentions.to_hash(@client.allowed_mentions)
310
+ else
311
+ @client.allowed_mentions.to_hash
312
+ end
313
+ )
314
+ payload[:components] = Component.to_payload(components) if components
315
+ payload[:flags] = (ephemeral ? 1 << 6 : 0)
316
+ attachments ||= [attachment] if attachment
317
+ payload[:attachments] = attachments.map.with_index do |a, i|
318
+ { id: i, filename: a.filename, description: a.description }
319
+ end
320
+ @client
321
+ .http
322
+ .multipart_request(
323
+ Route.new(
324
+ "/interactions/#{@id}/#{@token}/callback",
325
+ "//interactions/:interaction_id/:token/callback",
326
+ :post
327
+ ),
328
+ { type: 7, data: payload },
329
+ attachments
330
+ )
331
+ .wait
332
+ end
333
+ end
334
+ end
335
+
336
+ #
337
+ # A module for response with modal.
338
+ #
339
+ module ModalResponder
340
+ # @type instance: Discorb::Interaction
341
+
342
+ #
343
+ # Response with `MODAL`(`9`).
344
+ #
345
+ # @param [String] title The title of the modal.
346
+ # @param [String] custom_id The custom id of the modal.
347
+ # @param [Array<Discorb::TextInput>] components The text inputs to send.
348
+ #
349
+ # @return [Async::Task<void>] The task.
350
+ #
351
+ def show_modal(title, custom_id, components)
352
+ Async do
353
+ payload = {
354
+ title: title,
355
+ custom_id: custom_id,
356
+ components: Component.to_payload(components)
357
+ }
358
+ @client
359
+ .http
360
+ .request(
361
+ Route.new(
362
+ "/interactions/#{@id}/#{@token}/callback",
363
+ "//interactions/:interaction_id/:token/callback",
364
+ :post
365
+ ),
366
+ { type: 9, data: payload }
367
+ )
368
+ .wait
369
+ end
370
+ end
371
+ end
372
+
373
+ private
374
+
375
+ def _set_data(_)
376
+ nil
377
+ end
378
+ end
379
+ end