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.
- checksums.yaml +4 -4
- data/.github/workflows/build_version.yml +2 -2
- data/.rubocop.yml +12 -75
- data/Changelog.md +10 -0
- data/Rakefile +482 -454
- data/lib/discorb/allowed_mentions.rb +68 -72
- data/lib/discorb/app_command/command.rb +466 -398
- data/lib/discorb/app_command/common.rb +65 -25
- data/lib/discorb/app_command/handler.rb +304 -266
- data/lib/discorb/app_command.rb +5 -5
- data/lib/discorb/application.rb +198 -197
- data/lib/discorb/asset.rb +101 -101
- data/lib/discorb/attachment.rb +134 -119
- data/lib/discorb/audit_logs.rb +412 -385
- data/lib/discorb/automod.rb +279 -269
- data/lib/discorb/channel/base.rb +107 -108
- data/lib/discorb/channel/category.rb +32 -32
- data/lib/discorb/channel/container.rb +44 -44
- data/lib/discorb/channel/dm.rb +26 -28
- data/lib/discorb/channel/guild.rb +311 -246
- data/lib/discorb/channel/stage.rb +156 -140
- data/lib/discorb/channel/text.rb +430 -336
- data/lib/discorb/channel/thread.rb +374 -325
- data/lib/discorb/channel/voice.rb +85 -79
- data/lib/discorb/channel.rb +5 -5
- data/lib/discorb/client.rb +635 -621
- data/lib/discorb/color.rb +178 -182
- data/lib/discorb/common.rb +168 -164
- data/lib/discorb/components/button.rb +107 -106
- data/lib/discorb/components/select_menu.rb +157 -145
- data/lib/discorb/components/text_input.rb +103 -106
- data/lib/discorb/components.rb +68 -66
- data/lib/discorb/dictionary.rb +135 -135
- data/lib/discorb/embed.rb +404 -398
- data/lib/discorb/emoji.rb +309 -302
- data/lib/discorb/emoji_table.rb +16099 -8857
- data/lib/discorb/error.rb +131 -131
- data/lib/discorb/event.rb +360 -314
- data/lib/discorb/event_handler.rb +39 -39
- data/lib/discorb/exe/about.rb +17 -17
- data/lib/discorb/exe/irb.rb +72 -67
- data/lib/discorb/exe/new.rb +323 -315
- data/lib/discorb/exe/run.rb +69 -68
- data/lib/discorb/exe/setup.rb +57 -55
- data/lib/discorb/exe/show.rb +12 -12
- data/lib/discorb/extend.rb +25 -45
- data/lib/discorb/extension.rb +89 -83
- data/lib/discorb/flag.rb +126 -128
- data/lib/discorb/gateway.rb +984 -804
- data/lib/discorb/gateway_events.rb +670 -638
- data/lib/discorb/gateway_requests.rb +45 -48
- data/lib/discorb/guild.rb +2115 -1626
- data/lib/discorb/guild_template.rb +280 -241
- data/lib/discorb/http.rb +247 -232
- data/lib/discorb/image.rb +42 -42
- data/lib/discorb/integration.rb +169 -161
- data/lib/discorb/intents.rb +161 -163
- data/lib/discorb/interaction/autocomplete.rb +76 -62
- data/lib/discorb/interaction/command.rb +279 -224
- data/lib/discorb/interaction/components.rb +114 -104
- data/lib/discorb/interaction/modal.rb +36 -32
- data/lib/discorb/interaction/response.rb +379 -336
- data/lib/discorb/interaction/root.rb +271 -257
- data/lib/discorb/interaction.rb +5 -5
- data/lib/discorb/invite.rb +154 -153
- data/lib/discorb/member.rb +344 -311
- data/lib/discorb/message.rb +615 -544
- data/lib/discorb/message_meta.rb +197 -186
- data/lib/discorb/modules.rb +371 -290
- data/lib/discorb/permission.rb +305 -291
- data/lib/discorb/presence.rb +352 -346
- data/lib/discorb/rate_limit.rb +81 -76
- data/lib/discorb/reaction.rb +55 -54
- data/lib/discorb/role.rb +272 -240
- data/lib/discorb/shard.rb +76 -74
- data/lib/discorb/sticker.rb +193 -171
- data/lib/discorb/user.rb +205 -188
- data/lib/discorb/utils/colored_puts.rb +16 -16
- data/lib/discorb/utils.rb +12 -16
- data/lib/discorb/voice_state.rb +305 -281
- data/lib/discorb/webhook.rb +537 -507
- data/lib/discorb.rb +62 -56
- data/sig/discorb/application.rbs +2 -0
- data/sig/discorb/automod.rbs +10 -1
- data/sig/discorb/guild.rbs +2 -0
- data/sig/discorb/message.rbs +2 -0
- data/sig/discorb/user.rbs +22 -20
- 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
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
# @param [
|
47
|
-
# @param [
|
48
|
-
# @param [Discorb::Embed]
|
49
|
-
# @param [
|
50
|
-
# @param [Discorb::
|
51
|
-
# @param [Discorb::Attachment]
|
52
|
-
# @param [Array<Discorb::
|
53
|
-
# @param [
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
payload =
|
72
|
-
payload[:
|
73
|
-
payload[:
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
"/webhooks/#{@application_id}/#{@token}
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
)
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
#
|
151
|
-
#
|
152
|
-
# @
|
153
|
-
# @
|
154
|
-
#
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
#
|
163
|
-
#
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
#
|
216
|
-
|
217
|
-
#
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
#
|
243
|
-
|
244
|
-
#
|
245
|
-
#
|
246
|
-
#
|
247
|
-
#
|
248
|
-
# @param [Boolean]
|
249
|
-
#
|
250
|
-
# @
|
251
|
-
#
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
)
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
payload =
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
end
|
335
|
-
|
336
|
-
|
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
|