discorb 0.16.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +1 -0
- data/.github/workflows/build_main.yml +2 -2
- data/.github/workflows/build_version.yml +1 -1
- data/.github/workflows/codeql-analysis.yml +1 -1
- data/.github/workflows/lint-push.yml +3 -5
- data/.github/workflows/lint.yml +2 -4
- data/.github/workflows/spec.yml +33 -0
- data/.github/workflows/validate.yml +21 -0
- data/.gitignore +2 -0
- data/.lefthook/commit-msg/validator.rb +5 -0
- data/.rspec +2 -0
- data/.rspec_parallel +2 -0
- data/.rubocop.yml +43 -6
- data/Changelog.md +30 -1
- data/Gemfile +20 -8
- data/Rakefile +226 -98
- data/Steepfile +28 -0
- data/bin/console +3 -3
- data/docs/Examples.md +1 -1
- data/docs/application_command.md +156 -47
- data/docs/cli/irb.md +2 -2
- data/docs/cli/new.md +14 -9
- data/docs/cli/run.md +7 -11
- data/docs/cli.md +17 -10
- data/docs/events.md +247 -213
- data/docs/extension.md +1 -2
- data/docs/faq.md +0 -1
- data/docs/tutorial.md +18 -18
- data/docs/voice_events.md +106 -106
- data/examples/commands/message.rb +68 -0
- data/examples/commands/permission.rb +19 -0
- data/examples/commands/slash.rb +48 -0
- data/examples/commands/user.rb +54 -0
- data/examples/components/authorization_button.rb +4 -3
- data/examples/components/select_menu.rb +6 -3
- data/examples/extension/main.rb +2 -1
- data/examples/extension/message_expander.rb +6 -2
- data/examples/sig/commands/message.rbs +5 -0
- data/examples/simple/eval.rb +3 -2
- data/examples/simple/ping_pong.rb +2 -1
- data/examples/simple/rolepanel.rb +17 -6
- data/examples/simple/shard.rb +3 -2
- data/examples/simple/wait_for_message.rb +4 -1
- data/exe/discorb +33 -18
- data/lefthook.yml +45 -0
- data/lib/discorb/allowed_mentions.rb +2 -1
- data/lib/discorb/app_command/command.rb +130 -72
- data/lib/discorb/app_command/common.rb +25 -0
- data/lib/discorb/app_command/handler.rb +130 -33
- data/lib/discorb/app_command.rb +2 -1
- data/lib/discorb/application.rb +1 -0
- data/lib/discorb/asset.rb +1 -2
- data/lib/discorb/attachment.rb +1 -1
- data/lib/discorb/audit_logs.rb +19 -10
- data/lib/discorb/automod.rb +269 -0
- data/lib/discorb/channel/base.rb +108 -0
- data/lib/discorb/channel/category.rb +32 -0
- data/lib/discorb/channel/container.rb +44 -0
- data/lib/discorb/channel/dm.rb +28 -0
- data/lib/discorb/channel/guild.rb +246 -0
- data/lib/discorb/channel/stage.rb +140 -0
- data/lib/discorb/channel/text.rb +336 -0
- data/lib/discorb/channel/thread.rb +325 -0
- data/lib/discorb/channel/voice.rb +79 -0
- data/lib/discorb/channel.rb +2 -1165
- data/lib/discorb/client.rb +50 -36
- data/lib/discorb/color.rb +37 -60
- data/lib/discorb/common.rb +2 -1
- data/lib/discorb/components/button.rb +2 -1
- data/lib/discorb/components/select_menu.rb +4 -2
- data/lib/discorb/components/text_input.rb +12 -2
- data/lib/discorb/components.rb +1 -1
- data/lib/discorb/dictionary.rb +1 -1
- data/lib/discorb/embed.rb +26 -10
- data/lib/discorb/emoji.rb +31 -4
- data/lib/discorb/emoji_table.rb +4969 -3
- data/lib/discorb/event.rb +29 -4
- data/lib/discorb/exe/about.rb +2 -1
- data/lib/discorb/exe/irb.rb +2 -4
- data/lib/discorb/exe/new.rb +89 -26
- data/lib/discorb/exe/run.rb +8 -22
- data/lib/discorb/exe/setup.rb +25 -12
- data/lib/discorb/exe/show.rb +4 -3
- data/lib/discorb/extend.rb +1 -0
- data/lib/discorb/extension.rb +6 -7
- data/lib/discorb/flag.rb +13 -2
- data/lib/discorb/gateway.rb +79 -589
- data/lib/discorb/gateway_events.rb +638 -0
- data/lib/discorb/guild.rb +318 -67
- data/lib/discorb/guild_template.rb +11 -5
- data/lib/discorb/http.rb +53 -24
- data/lib/discorb/integration.rb +4 -1
- data/lib/discorb/intents.rb +28 -19
- data/lib/discorb/interaction/autocomplete.rb +28 -16
- data/lib/discorb/interaction/command.rb +42 -14
- data/lib/discorb/interaction/components.rb +5 -2
- data/lib/discorb/interaction/modal.rb +0 -1
- data/lib/discorb/interaction/response.rb +125 -26
- data/lib/discorb/interaction/root.rb +13 -13
- data/lib/discorb/interaction.rb +1 -0
- data/lib/discorb/invite.rb +5 -2
- data/lib/discorb/member.rb +28 -8
- data/lib/discorb/message.rb +60 -25
- data/lib/discorb/message_meta.rb +3 -3
- data/lib/discorb/modules.rb +59 -16
- data/lib/discorb/presence.rb +2 -0
- data/lib/discorb/rate_limit.rb +7 -2
- data/lib/discorb/reaction.rb +2 -2
- data/lib/discorb/role.rb +20 -5
- data/lib/discorb/shard.rb +1 -1
- data/lib/discorb/sticker.rb +9 -8
- data/lib/discorb/user.rb +4 -3
- data/lib/discorb/utils/colored_puts.rb +1 -0
- data/lib/discorb/voice_state.rb +6 -2
- data/lib/discorb/webhook.rb +64 -31
- data/lib/discorb.rb +7 -5
- data/po/yard.pot +20 -20
- data/rbs_collection.lock.yaml +88 -0
- data/rbs_collection.yaml +21 -0
- data/sig/async.rbs +11 -0
- data/sig/discorb/activity.rbs +23 -0
- data/sig/discorb/allowed_mentions.rbs +44 -0
- data/sig/discorb/app_command/base.rbs +282 -0
- data/sig/discorb/app_command/handler.rbs +171 -0
- data/sig/discorb/application.rbs +142 -0
- data/sig/discorb/asset.rbs +32 -0
- data/sig/discorb/attachment.rbs +91 -0
- data/sig/discorb/audit_log.rbs +231 -0
- data/sig/discorb/automod.rbs +128 -0
- data/sig/discorb/avatar.rbs +26 -0
- data/sig/discorb/channel/base.rbs +179 -0
- data/sig/discorb/channel/category.rbs +56 -0
- data/sig/discorb/channel/container.rbs +29 -0
- data/sig/discorb/channel/dm.rbs +14 -0
- data/sig/discorb/channel/news.rbs +20 -0
- data/sig/discorb/channel/stage.rbs +77 -0
- data/sig/discorb/channel/text.rbs +158 -0
- data/sig/discorb/channel/thread.rbs +185 -0
- data/sig/discorb/channel/voice.rbs +41 -0
- data/sig/discorb/client.rbs +2495 -0
- data/sig/discorb/color.rbs +142 -0
- data/sig/discorb/component/base.rbs +28 -0
- data/sig/discorb/component/button.rbs +65 -0
- data/sig/discorb/component/select_menu.rbs +107 -0
- data/sig/discorb/component/text_input.rbs +69 -0
- data/sig/discorb/connectable.rbs +8 -0
- data/sig/discorb/custom_emoji.rbs +90 -0
- data/sig/discorb/dictionary.rbs +85 -0
- data/sig/discorb/discord_model.rbs +15 -0
- data/sig/discorb/embed.rbs +279 -0
- data/sig/discorb/emoji.rbs +13 -0
- data/sig/discorb/error.rbs +73 -0
- data/sig/discorb/event_handler.rbs +27 -0
- data/sig/discorb/extension.rbs +1734 -0
- data/sig/discorb/flag.rbs +72 -0
- data/sig/discorb/gateway.rbs +481 -0
- data/sig/discorb/guild.rbs +870 -0
- data/sig/discorb/guild_template.rbs +174 -0
- data/sig/discorb/http.rbs +147 -0
- data/sig/discorb/image.rbs +20 -0
- data/sig/discorb/integration.rbs +118 -0
- data/sig/discorb/intents.rbs +97 -0
- data/sig/discorb/interaction/autocomplete.rbs +9 -0
- data/sig/discorb/interaction/base.rbs +66 -0
- data/sig/discorb/interaction/command.rbs +66 -0
- data/sig/discorb/interaction/message_component.rbs +140 -0
- data/sig/discorb/interaction/modal.rbs +50 -0
- data/sig/discorb/interaction/responder.rbs +157 -0
- data/sig/discorb/invite.rbs +86 -0
- data/sig/discorb/member.rbs +187 -0
- data/sig/discorb/message.rbs +469 -0
- data/sig/discorb/messageable.rbs +153 -0
- data/sig/discorb/partial_emoji.rbs +35 -0
- data/sig/discorb/permissions.rbs +149 -0
- data/sig/discorb/presence.rbs +237 -0
- data/sig/discorb/reaction.rbs +33 -0
- data/sig/discorb/role.rbs +145 -0
- data/sig/discorb/scheduled_event.rbs +148 -0
- data/sig/discorb/shard.rbs +62 -0
- data/sig/discorb/snowflake.rbs +56 -0
- data/sig/discorb/stage_instance.rbs +63 -0
- data/sig/discorb/sticker.rbs +116 -0
- data/sig/discorb/system_channel_flag.rbs +17 -0
- data/sig/discorb/unicode_emoji.rbs +49 -0
- data/sig/discorb/user.rbs +93 -0
- data/sig/discorb/utils.rbs +8 -0
- data/sig/discorb/voice_region.rbs +30 -0
- data/sig/discorb/voice_state.rbs +71 -0
- data/sig/discorb/webhook.rbs +327 -0
- data/sig/discorb/welcome_screen.rbs +78 -0
- data/sig/discorb.rbs +6 -7230
- data/sig/manifest.yaml +3 -0
- data/sig/override.rbs +19 -0
- data/template-replace/files/css/common.css +4 -0
- metadata +102 -6
- data/examples/commands/bookmarker.rb +0 -42
- data/examples/commands/hello.rb +0 -10
- data/examples/commands/inspect.rb +0 -25
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Discorb
|
3
4
|
#
|
4
5
|
# Represents an interaction of Discord.
|
@@ -8,6 +9,8 @@ module Discorb
|
|
8
9
|
# A module for response with source.
|
9
10
|
#
|
10
11
|
module SourceResponder
|
12
|
+
# @type instance: Discorb::Interaction
|
13
|
+
|
11
14
|
#
|
12
15
|
# Response with `DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE`(`5`).
|
13
16
|
#
|
@@ -19,12 +22,18 @@ module Discorb
|
|
19
22
|
#
|
20
23
|
def defer_source(ephemeral: false)
|
21
24
|
Async do
|
22
|
-
@client.http.request(
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
28
37
|
@defered = true
|
29
38
|
end
|
30
39
|
end
|
@@ -39,30 +48,77 @@ module Discorb
|
|
39
48
|
# @param [Discorb::Embed] embed The embed to send.
|
40
49
|
# @param [Array<Discorb::Embed>] embeds The embeds to send. (max: 10)
|
41
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)
|
42
53
|
# @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
|
43
54
|
# @param [Boolean] ephemeral Whether to make the response ephemeral.
|
44
55
|
#
|
45
|
-
# @return [Discorb::Interaction::SourceResponder::CallbackMessage, Discorb::Webhook::Message]
|
56
|
+
# @return [Discorb::Interaction::SourceResponder::CallbackMessage, Discorb::Webhook::Message]
|
57
|
+
# The callback message.
|
46
58
|
#
|
47
|
-
def post(
|
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
|
+
)
|
48
70
|
Async do
|
49
71
|
payload = {}
|
50
72
|
payload[:content] = content if content
|
51
73
|
payload[:tts] = tts
|
52
74
|
payload[:embeds] = (embeds || [embed]).map { |e| e&.to_hash }.filter { _1 }
|
53
|
-
payload[:allowed_mentions] =
|
75
|
+
payload[:allowed_mentions] =
|
76
|
+
allowed_mentions&.to_hash(@client.allowed_mentions) || @client.allowed_mentions.to_hash
|
54
77
|
payload[:components] = Component.to_payload(components) if components
|
55
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
|
56
88
|
|
57
89
|
ret = if @responded
|
58
|
-
_resp, data = @client.http.
|
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
|
59
99
|
webhook = Webhook::URLWebhook.new("/webhooks/#{@application_id}/#{@token}")
|
60
100
|
Webhook::Message.new(webhook, data, @client)
|
61
101
|
elsif @defered
|
62
|
-
@client.http.
|
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
|
63
111
|
CallbackMessage.new(@client, payload, @application_id, @token)
|
64
112
|
else
|
65
|
-
@client.http.
|
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
|
66
122
|
CallbackMessage.new(@client, payload, @application_id, @token)
|
67
123
|
end
|
68
124
|
@responded = true
|
@@ -99,8 +155,8 @@ module Discorb
|
|
99
155
|
# @param [Discorb::Embed] embed The new embed of the message.
|
100
156
|
# @param [Array<Discorb::Embed>] embeds The new embeds of the message.
|
101
157
|
# @param [Array<Discorb::Attachment>] attachments The attachments to remain.
|
102
|
-
# @param [Discorb::
|
103
|
-
# @param [Array<Discorb::
|
158
|
+
# @param [Discorb::Attachment] file The file to send.
|
159
|
+
# @param [Array<Discorb::Attachment>] files The files to send.
|
104
160
|
#
|
105
161
|
# @return [Async::Task<void>] The task.
|
106
162
|
#
|
@@ -118,7 +174,15 @@ module Discorb
|
|
118
174
|
payload[:attachments] = attachments.map(&:to_hash) if attachments != Discorb::Unset
|
119
175
|
files = [file] if file != Discorb::Unset
|
120
176
|
files = [] if files == Discorb::Unset
|
121
|
-
@client.http.multipart_request(
|
177
|
+
@client.http.multipart_request(
|
178
|
+
Route.new(
|
179
|
+
"/webhooks/#{@application_id}/#{@token}/messages/@original",
|
180
|
+
"//webhooks/:webhook_id/:token/messages/@original",
|
181
|
+
:patch
|
182
|
+
),
|
183
|
+
payload,
|
184
|
+
files,
|
185
|
+
).wait
|
122
186
|
end
|
123
187
|
end
|
124
188
|
|
@@ -133,7 +197,8 @@ module Discorb
|
|
133
197
|
#
|
134
198
|
def delete!
|
135
199
|
Async do
|
136
|
-
@client.http.request(Route.new("/webhooks/#{@application_id}/#{@token}/messages/@original",
|
200
|
+
@client.http.request(Route.new("/webhooks/#{@application_id}/#{@token}/messages/@original",
|
201
|
+
"//webhooks/:webhook_id/:token/messages/@original", :delete)).wait
|
137
202
|
end
|
138
203
|
end
|
139
204
|
|
@@ -147,6 +212,8 @@ module Discorb
|
|
147
212
|
# A module for response with update.
|
148
213
|
#
|
149
214
|
module UpdateResponder
|
215
|
+
# @type instance: Discorb::Interaction
|
216
|
+
|
150
217
|
#
|
151
218
|
# Response with `DEFERRED_UPDATE_MESSAGE`(`6`).
|
152
219
|
# @async
|
@@ -157,12 +224,18 @@ module Discorb
|
|
157
224
|
#
|
158
225
|
def defer_update(ephemeral: false)
|
159
226
|
Async do
|
160
|
-
@client.http.request(
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
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
|
166
239
|
end
|
167
240
|
end
|
168
241
|
|
@@ -176,12 +249,24 @@ module Discorb
|
|
176
249
|
# @param [Discorb::Embed] embed The embed to send.
|
177
250
|
# @param [Array<Discorb::Embed>] embeds The embeds to send. (max: 10)
|
178
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)
|
179
254
|
# @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
|
180
255
|
# @param [Boolean] ephemeral Whether to make the response ephemeral.
|
181
256
|
#
|
182
257
|
# @return [Async::Task<void>] The task.
|
183
258
|
#
|
184
|
-
def edit(
|
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
|
+
)
|
185
270
|
Async do
|
186
271
|
payload = {}
|
187
272
|
payload[:content] = content if content
|
@@ -192,10 +277,22 @@ module Discorb
|
|
192
277
|
embeds
|
193
278
|
end
|
194
279
|
payload[:embeds] = tmp_embed.map(&:to_hash) if tmp_embed
|
195
|
-
payload[:allowed_mentions] =
|
280
|
+
payload[:allowed_mentions] =
|
281
|
+
allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
|
196
282
|
payload[:components] = Component.to_payload(components) if components
|
197
283
|
payload[:flags] = (ephemeral ? 1 << 6 : 0)
|
198
|
-
|
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
|
199
296
|
end
|
200
297
|
end
|
201
298
|
end
|
@@ -204,6 +301,8 @@ module Discorb
|
|
204
301
|
# A module for response with modal.
|
205
302
|
#
|
206
303
|
module ModalResponder
|
304
|
+
# @type instance: Discorb::Interaction
|
305
|
+
|
207
306
|
#
|
208
307
|
# Response with `MODAL`(`9`).
|
209
308
|
#
|
@@ -224,7 +323,7 @@ module Discorb
|
|
224
323
|
|
225
324
|
private
|
226
325
|
|
227
|
-
def _set_data(
|
326
|
+
def _set_data(_)
|
228
327
|
nil
|
229
328
|
end
|
230
329
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Discorb
|
3
4
|
#
|
4
5
|
# Represents a user interaction with the bot.
|
@@ -10,10 +11,9 @@ module Discorb
|
|
10
11
|
attr_reader :application_id
|
11
12
|
# @return [Symbol] The type of interaction.
|
12
13
|
attr_reader :type
|
13
|
-
# @return [Discorb::Member] The member that created the interaction.
|
14
|
-
attr_reader :member
|
15
|
-
# @return [Discorb::User] The user that created the interaction.
|
14
|
+
# @return [Discorb::User, Discorb::Member] The user or member that created the interaction.
|
16
15
|
attr_reader :user
|
16
|
+
alias member user
|
17
17
|
# @return [Integer] The type of interaction.
|
18
18
|
# @note This is always `1` for now.
|
19
19
|
attr_reader :version
|
@@ -53,8 +53,12 @@ module Discorb
|
|
53
53
|
@type_id = self.class.interaction_type
|
54
54
|
@guild_id = data[:guild_id] && Snowflake.new(data[:guild_id])
|
55
55
|
@channel_id = data[:channel_id] && Snowflake.new(data[:channel_id])
|
56
|
-
|
57
|
-
|
56
|
+
if data[:member]
|
57
|
+
@user = guild.members[data[:member][:id]] || Member.new(@client, @guild_id, data[:member][:user],
|
58
|
+
data[:member])
|
59
|
+
elsif data[:user]
|
60
|
+
@user = @client.users[data[:user][:id]] || User.new(@client, data[:user])
|
61
|
+
end
|
58
62
|
@token = data[:token]
|
59
63
|
@locale = data[:locale].to_s.gsub("-", "_").to_sym
|
60
64
|
@guild_locale = data[:guild_locale].to_s.gsub("-", "_").to_sym
|
@@ -72,13 +76,6 @@ module Discorb
|
|
72
76
|
@client.channels[@channel_id]
|
73
77
|
end
|
74
78
|
|
75
|
-
def target
|
76
|
-
@member || @user
|
77
|
-
end
|
78
|
-
|
79
|
-
alias fired_by target
|
80
|
-
alias from target
|
81
|
-
|
82
79
|
def inspect
|
83
80
|
"#<#{self.class} id=#{@id}>"
|
84
81
|
end
|
@@ -97,7 +94,10 @@ module Discorb
|
|
97
94
|
def make_interaction(client, data)
|
98
95
|
interaction = nil
|
99
96
|
descendants.each do |klass|
|
100
|
-
|
97
|
+
if !klass.interaction_type.nil? && klass.interaction_type == data[:type]
|
98
|
+
interaction = klass.make_interaction(client,
|
99
|
+
data)
|
100
|
+
end
|
101
101
|
end
|
102
102
|
if interaction.nil?
|
103
103
|
client.logger.warn("Unknown interaction type #{data[:type]}, initialized Interaction")
|
data/lib/discorb/interaction.rb
CHANGED
data/lib/discorb/invite.rb
CHANGED
@@ -114,7 +114,7 @@ module Discorb
|
|
114
114
|
#
|
115
115
|
def delete!(reason: nil)
|
116
116
|
Async do
|
117
|
-
@client.http.request(Route.new("/invites/#{@code}", "//invites/:code", :delete), audit_log_reason: reason)
|
117
|
+
@client.http.request(Route.new("/invites/#{@code}", "//invites/:code", :delete), {}, audit_log_reason: reason)
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
@@ -134,7 +134,10 @@ module Discorb
|
|
134
134
|
end
|
135
135
|
@inviter_data = data[:inviter]
|
136
136
|
@target_type = TARGET_TYPES[data[:target_type]]
|
137
|
-
|
137
|
+
if data[:target_user]
|
138
|
+
@target_user = @client.users[data[:target_user][:id]] || User.new(@client,
|
139
|
+
data[:target_user])
|
140
|
+
end
|
138
141
|
# @target_application = nil
|
139
142
|
|
140
143
|
# @stage_instance = data[:stage_instance] && Invite::StageInstance.new(self, data[:stage_instance])
|
data/lib/discorb/member.rb
CHANGED
@@ -52,10 +52,10 @@ module Discorb
|
|
52
52
|
# @return [Discorb::Presence] The presence of the member.
|
53
53
|
# @!attribute [r] activity
|
54
54
|
# @macro client_cache
|
55
|
-
# @return [Discorb::Activity] The activity of the member. It's from the {#presence}.
|
55
|
+
# @return [Discorb::Presence::Activity] The activity of the member. It's from the {#presence}.
|
56
56
|
# @!attribute [r] activities
|
57
57
|
# @macro client_cache
|
58
|
-
# @return [Array<Discorb::Activity>] The activities of the member. It's from the {#presence}.
|
58
|
+
# @return [Array<Discorb::Presence::Activity>] The activities of the member. It's from the {#presence}.
|
59
59
|
# @!attribute [r] status
|
60
60
|
# @macro client_cache
|
61
61
|
# @return [Symbol] The status of the member. It's from the {#presence}.
|
@@ -114,6 +114,7 @@ module Discorb
|
|
114
114
|
|
115
115
|
def permissions
|
116
116
|
return Permission.new((1 << 38) - 1) if owner?
|
117
|
+
|
117
118
|
roles.map(&:permissions).sum(Permission.new(0))
|
118
119
|
end
|
119
120
|
|
@@ -158,7 +159,10 @@ module Discorb
|
|
158
159
|
#
|
159
160
|
def add_role(role, reason: nil)
|
160
161
|
Async do
|
161
|
-
@client.http.request(
|
162
|
+
@client.http.request(
|
163
|
+
Route.new("/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}",
|
164
|
+
"//guilds/:guild_id/members/:user_id/roles/:role_id", :put), nil, audit_log_reason: reason,
|
165
|
+
).wait
|
162
166
|
end
|
163
167
|
end
|
164
168
|
|
@@ -173,7 +177,10 @@ module Discorb
|
|
173
177
|
#
|
174
178
|
def remove_role(role, reason: nil)
|
175
179
|
Async do
|
176
|
-
@client.http.request(
|
180
|
+
@client.http.request(
|
181
|
+
Route.new("/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}",
|
182
|
+
"//guilds/:guild_id/members/:user_id/roles/:role_id", :delete), {}, audit_log_reason: reason,
|
183
|
+
).wait
|
177
184
|
end
|
178
185
|
end
|
179
186
|
|
@@ -194,7 +201,13 @@ module Discorb
|
|
194
201
|
# @return [Async::Task<void>] The task.
|
195
202
|
#
|
196
203
|
def edit(
|
197
|
-
nick: Discorb::Unset,
|
204
|
+
nick: Discorb::Unset,
|
205
|
+
role: Discorb::Unset,
|
206
|
+
mute: Discorb::Unset,
|
207
|
+
deaf: Discorb::Unset,
|
208
|
+
channel: Discorb::Unset,
|
209
|
+
communication_disabled_until: Discorb::Unset,
|
210
|
+
timeout_until: Discorb::Unset,
|
198
211
|
reason: nil
|
199
212
|
)
|
200
213
|
Async do
|
@@ -204,9 +217,15 @@ module Discorb
|
|
204
217
|
payload[:mute] = mute if mute != Discorb::Unset
|
205
218
|
payload[:deaf] = deaf if deaf != Discorb::Unset
|
206
219
|
communication_disabled_until = timeout_until if timeout_until != Discorb::Unset
|
207
|
-
|
220
|
+
if communication_disabled_until != Discorb::Unset
|
221
|
+
payload[:communication_disabled_until] =
|
222
|
+
communication_disabled_until&.iso8601
|
223
|
+
end
|
208
224
|
payload[:channel_id] = channel&.id if channel != Discorb::Unset
|
209
|
-
@client.http.request(
|
225
|
+
@client.http.request(
|
226
|
+
Route.new("/guilds/#{@guild_id}/members/#{@id}", "//guilds/:guild_id/members/:user_id",
|
227
|
+
:patch), payload, audit_log_reason: reason,
|
228
|
+
).wait
|
210
229
|
end
|
211
230
|
end
|
212
231
|
|
@@ -265,6 +284,7 @@ module Discorb
|
|
265
284
|
#
|
266
285
|
def can_manage?(role)
|
267
286
|
return true if owner?
|
287
|
+
|
268
288
|
top_role = roles.max_by(&:position)
|
269
289
|
top_role.position > role.position
|
270
290
|
end
|
@@ -283,7 +303,7 @@ module Discorb
|
|
283
303
|
@deaf = member_data[:deaf]
|
284
304
|
@custom_avatar = member_data[:avatar] && Asset.new(self, member_data[:avatar])
|
285
305
|
super(user_data)
|
286
|
-
@display_avatar = @
|
306
|
+
@display_avatar = @custom_avatar || @avatar
|
287
307
|
@client.guilds[@guild_id].members[@id] = self unless @guild_id.nil? || @client.guilds[@guild_id].nil?
|
288
308
|
@_member_data.update(member_data)
|
289
309
|
end
|
data/lib/discorb/message.rb
CHANGED
@@ -7,7 +7,7 @@ module Discorb
|
|
7
7
|
class Message < DiscordModel
|
8
8
|
# @return [Discorb::Snowflake] The ID of the message.
|
9
9
|
attr_reader :id
|
10
|
-
# @return [Discorb::User, Discorb::Member] The user that sent the message.
|
10
|
+
# @return [Discorb::User, Discorb::Member, Webhook::Message::Author] The user that sent the message.
|
11
11
|
attr_reader :author
|
12
12
|
# @return [String] The content of the message.
|
13
13
|
attr_reader :content
|
@@ -85,7 +85,9 @@ module Discorb
|
|
85
85
|
# @return [Boolean] Whether the message is pinned.
|
86
86
|
attr_reader :pinned
|
87
87
|
alias pinned? pinned
|
88
|
-
@
|
88
|
+
# @private
|
89
|
+
# @return [{Integer => Symbol}] The mapping of message type.
|
90
|
+
MESSAGE_TYPE = {
|
89
91
|
0 => :default,
|
90
92
|
1 => :recipient_add,
|
91
93
|
2 => :recipient_remove,
|
@@ -215,8 +217,8 @@ module Discorb
|
|
215
217
|
end
|
216
218
|
if role
|
217
219
|
ret.gsub!(/<@&(\d+)>/) do |_match|
|
218
|
-
|
219
|
-
|
220
|
+
r = guild&.roles&.[]($1)
|
221
|
+
r ? "@#{r.name}" : "@Unknown Role"
|
220
222
|
end
|
221
223
|
end
|
222
224
|
if emoji
|
@@ -257,8 +259,15 @@ module Discorb
|
|
257
259
|
#
|
258
260
|
# @return [Async::Task<void>] The task.
|
259
261
|
#
|
260
|
-
def edit(
|
261
|
-
|
262
|
+
def edit(
|
263
|
+
content = Discorb::Unset,
|
264
|
+
embed: Discorb::Unset,
|
265
|
+
embeds: Discorb::Unset,
|
266
|
+
allowed_mentions: Discorb::Unset,
|
267
|
+
attachments: Discorb::Unset,
|
268
|
+
components: Discorb::Unset,
|
269
|
+
supress: Discorb::Unset
|
270
|
+
)
|
262
271
|
Async do
|
263
272
|
channel.edit_message(@id, content, embed: embed, embeds: embeds, allowed_mentions: allowed_mentions,
|
264
273
|
attachments: attachments, components: components, supress: supress).wait
|
@@ -284,15 +293,17 @@ module Discorb
|
|
284
293
|
#
|
285
294
|
# @param [Boolean] fail_if_not_exists Whether to raise an error if the message does not exist.
|
286
295
|
#
|
287
|
-
# @return [
|
296
|
+
# @return [Discorb::Message::Reference] The reference object.
|
288
297
|
#
|
289
298
|
def to_reference(fail_if_not_exists: true)
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
299
|
+
Reference.from_hash(
|
300
|
+
{
|
301
|
+
message_id: @id,
|
302
|
+
channel_id: @channel_id,
|
303
|
+
guild_id: @guild_id,
|
304
|
+
fail_if_not_exists: fail_if_not_exists,
|
305
|
+
}
|
306
|
+
)
|
296
307
|
end
|
297
308
|
|
298
309
|
def embed
|
@@ -331,7 +342,10 @@ module Discorb
|
|
331
342
|
#
|
332
343
|
def add_reaction(emoji)
|
333
344
|
Async do
|
334
|
-
@client.http.request(
|
345
|
+
@client.http.request(
|
346
|
+
Route.new("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me",
|
347
|
+
"//channels/:channel_id/messages/:message_id/reactions/:emoji/@me", :put), nil
|
348
|
+
).wait
|
335
349
|
end
|
336
350
|
end
|
337
351
|
|
@@ -347,7 +361,11 @@ module Discorb
|
|
347
361
|
#
|
348
362
|
def remove_reaction(emoji)
|
349
363
|
Async do
|
350
|
-
@client.http.request(
|
364
|
+
@client.http.request(
|
365
|
+
Route.new("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me",
|
366
|
+
"//channels/:channel_id/messages/:message_id/reactions/:emoji/@me",
|
367
|
+
:delete)
|
368
|
+
).wait
|
351
369
|
end
|
352
370
|
end
|
353
371
|
|
@@ -364,7 +382,17 @@ module Discorb
|
|
364
382
|
#
|
365
383
|
def remove_reaction_of(emoji, member)
|
366
384
|
Async do
|
367
|
-
@client.http.request(
|
385
|
+
@client.http.request(
|
386
|
+
Route.new(
|
387
|
+
"/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/#{if member.is_a?(Member)
|
388
|
+
member.id
|
389
|
+
else
|
390
|
+
member
|
391
|
+
end}",
|
392
|
+
"//channels/:channel_id/messages/:message_id/reactions/:emoji/:user_id",
|
393
|
+
:delete
|
394
|
+
)
|
395
|
+
).wait
|
368
396
|
end
|
369
397
|
end
|
370
398
|
|
@@ -374,7 +402,7 @@ module Discorb
|
|
374
402
|
# Fetch reacted users of reaction.
|
375
403
|
# @async
|
376
404
|
#
|
377
|
-
# @param [Discorb::Emoji] emoji The emoji to fetch.
|
405
|
+
# @param [Discorb::Emoji, Discorb::PartialEmoji] emoji The emoji to fetch.
|
378
406
|
# @param [Integer, nil] limit The maximum number of users to fetch. `nil` for no limit.
|
379
407
|
# @param [Discorb::Snowflake, nil] after The ID of the user to start fetching from.
|
380
408
|
#
|
@@ -386,7 +414,13 @@ module Discorb
|
|
386
414
|
after = 0
|
387
415
|
users = []
|
388
416
|
loop do
|
389
|
-
_resp, data = @client.http.request(
|
417
|
+
_resp, data = @client.http.request(
|
418
|
+
Route.new(
|
419
|
+
"/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=100&after=#{after}",
|
420
|
+
"//channels/:channel_id/messages/:message_id/reactions/:emoji",
|
421
|
+
:get
|
422
|
+
)
|
423
|
+
).wait
|
390
424
|
break if data.empty?
|
391
425
|
|
392
426
|
users += data.map { |r| guild&.members&.[](r[:id]) || @client.users[r[:id]] || User.new(@client, r) }
|
@@ -397,7 +431,13 @@ module Discorb
|
|
397
431
|
end
|
398
432
|
next users
|
399
433
|
else
|
400
|
-
_resp, data = @client.http.request(
|
434
|
+
_resp, data = @client.http.request(
|
435
|
+
Route.new(
|
436
|
+
"/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=#{limit}&after=#{after}",
|
437
|
+
"//channels/:channel_id/messages/:message_id/reactions/:emoji",
|
438
|
+
:get
|
439
|
+
)
|
440
|
+
).wait
|
401
441
|
next data.map { |r| guild&.members&.[](r[:id]) || @client.users[r[:id]] || User.new(@client, r) }
|
402
442
|
end
|
403
443
|
end
|
@@ -487,7 +527,7 @@ module Discorb
|
|
487
527
|
@embeds = data[:embeds] ? data[:embeds].map { |e| Embed.from_hash(e) } : []
|
488
528
|
@reactions = data[:reactions] ? data[:reactions].map { |r| Reaction.new(self, r) } : []
|
489
529
|
@pinned = data[:pinned]
|
490
|
-
@type =
|
530
|
+
@type = MESSAGE_TYPE[data[:type]]
|
491
531
|
@activity = data[:activity] && Activity.new(data[:activity])
|
492
532
|
@application_id = data[:application_id]
|
493
533
|
@message_reference = data[:message_reference] && Reference.from_hash(data[:message_reference])
|
@@ -500,10 +540,5 @@ module Discorb
|
|
500
540
|
@data.update(data)
|
501
541
|
@deleted = false
|
502
542
|
end
|
503
|
-
|
504
|
-
class << self
|
505
|
-
# @private
|
506
|
-
attr_reader :message_type
|
507
|
-
end
|
508
543
|
end
|
509
544
|
end
|
data/lib/discorb/message_meta.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Discorb
|
3
4
|
#
|
4
5
|
# Represents a message in Discord.
|
@@ -75,8 +76,6 @@ module Discorb
|
|
75
76
|
}
|
76
77
|
end
|
77
78
|
|
78
|
-
alias to_reference to_hash
|
79
|
-
|
80
79
|
#
|
81
80
|
# Initialize a new reference from a hash.
|
82
81
|
#
|
@@ -140,7 +139,8 @@ module Discorb
|
|
140
139
|
def initialize(client, data)
|
141
140
|
@id = Snowflake.new(data[:id])
|
142
141
|
@name = data[:name]
|
143
|
-
@type = Discorb::Interaction.descendants.find { |c| c.interaction_type == data[:type] }
|
142
|
+
@type = (Discorb::Interaction.descendants.find { |c| c.interaction_type == data[:type] } or
|
143
|
+
raise "Unknown interaction type: #{data[:type]}")
|
144
144
|
@user = client.users[data[:user][:id]] || User.new(client, data[:user])
|
145
145
|
end
|
146
146
|
|