discordrb 3.5.0 → 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.
- checksums.yaml +4 -4
- data/.devcontainer/Dockerfile +13 -0
- data/.devcontainer/devcontainer.json +29 -0
- data/.devcontainer/postcreate.sh +4 -0
- data/.github/workflows/ci.yml +78 -0
- data/.github/workflows/codeql.yml +3 -3
- data/.github/workflows/deploy.yml +54 -0
- data/.github/workflows/release.yml +45 -0
- data/.rubocop.yml +52 -2
- data/CHANGELOG.md +95 -0
- data/README.md +5 -5
- data/discordrb-webhooks.gemspec +1 -1
- data/discordrb.gemspec +16 -11
- data/lib/discordrb/api/application.rb +84 -8
- data/lib/discordrb/api/channel.rb +51 -13
- data/lib/discordrb/api/interaction.rb +15 -6
- data/lib/discordrb/api/invite.rb +1 -1
- data/lib/discordrb/api/server.rb +96 -60
- data/lib/discordrb/api/user.rb +12 -2
- data/lib/discordrb/api/webhook.rb +20 -5
- data/lib/discordrb/api.rb +16 -20
- data/lib/discordrb/bot.rb +139 -53
- data/lib/discordrb/cache.rb +15 -1
- data/lib/discordrb/commands/command_bot.rb +7 -17
- data/lib/discordrb/commands/parser.rb +7 -7
- data/lib/discordrb/container.rb +46 -0
- data/lib/discordrb/data/activity.rb +1 -1
- data/lib/discordrb/data/application.rb +1 -0
- data/lib/discordrb/data/attachment.rb +23 -3
- data/lib/discordrb/data/avatar_decoration.rb +26 -0
- data/lib/discordrb/data/call.rb +22 -0
- data/lib/discordrb/data/channel.rb +140 -15
- data/lib/discordrb/data/collectibles.rb +45 -0
- data/lib/discordrb/data/embed.rb +10 -3
- data/lib/discordrb/data/emoji.rb +20 -1
- data/lib/discordrb/data/integration.rb +3 -0
- data/lib/discordrb/data/interaction.rb +164 -27
- data/lib/discordrb/data/member.rb +145 -28
- data/lib/discordrb/data/message.rb +198 -51
- data/lib/discordrb/data/overwrite.rb +2 -0
- data/lib/discordrb/data/primary_server.rb +60 -0
- data/lib/discordrb/data/profile.rb +2 -7
- data/lib/discordrb/data/reaction.rb +2 -1
- data/lib/discordrb/data/recipient.rb +1 -1
- data/lib/discordrb/data/role.rb +151 -22
- data/lib/discordrb/data/server.rb +115 -41
- data/lib/discordrb/data/server_preview.rb +68 -0
- data/lib/discordrb/data/snapshot.rb +110 -0
- data/lib/discordrb/data/user.rb +68 -8
- data/lib/discordrb/data/voice_region.rb +1 -0
- data/lib/discordrb/data/webhook.rb +2 -5
- data/lib/discordrb/data.rb +6 -0
- data/lib/discordrb/errors.rb +5 -2
- data/lib/discordrb/events/await.rb +1 -1
- data/lib/discordrb/events/channels.rb +37 -0
- data/lib/discordrb/events/generic.rb +2 -0
- data/lib/discordrb/events/guilds.rb +6 -1
- data/lib/discordrb/events/interactions.rb +135 -42
- data/lib/discordrb/events/invites.rb +2 -0
- data/lib/discordrb/events/members.rb +19 -2
- data/lib/discordrb/events/message.rb +39 -8
- data/lib/discordrb/events/presence.rb +2 -0
- data/lib/discordrb/events/raw.rb +1 -0
- data/lib/discordrb/events/reactions.rb +2 -0
- data/lib/discordrb/events/roles.rb +2 -0
- data/lib/discordrb/events/threads.rb +10 -6
- data/lib/discordrb/events/typing.rb +1 -0
- data/lib/discordrb/events/voice_server_update.rb +1 -0
- data/lib/discordrb/events/voice_state_update.rb +1 -0
- data/lib/discordrb/events/webhooks.rb +1 -0
- data/lib/discordrb/gateway.rb +29 -13
- data/lib/discordrb/paginator.rb +3 -3
- data/lib/discordrb/permissions.rb +54 -43
- data/lib/discordrb/version.rb +1 -1
- data/lib/discordrb/websocket.rb +0 -10
- data/lib/discordrb.rb +17 -1
- metadata +53 -25
- data/.circleci/config.yml +0 -152
|
@@ -30,13 +30,13 @@ module Discordrb::API::Application
|
|
|
30
30
|
|
|
31
31
|
# Create a global application command.
|
|
32
32
|
# https://discord.com/developers/docs/interactions/slash-commands#create-global-application-command
|
|
33
|
-
def create_global_command(token, application_id, name, description, options = [], default_permission = nil, type = 1)
|
|
33
|
+
def create_global_command(token, application_id, name, description, options = [], default_permission = nil, type = 1, default_member_permissions = nil, contexts = nil, nsfw = false)
|
|
34
34
|
Discordrb::API.request(
|
|
35
35
|
:applications_aid_commands,
|
|
36
36
|
nil,
|
|
37
37
|
:post,
|
|
38
38
|
"#{Discordrb::API.api_base}/applications/#{application_id}/commands",
|
|
39
|
-
{ name: name, description: description, options: options, default_permission: default_permission, type: type }.to_json,
|
|
39
|
+
{ name: name, description: description, options: options, default_permission: default_permission, type: type, default_member_permissions: default_member_permissions, contexts: contexts, nsfw: nsfw }.to_json,
|
|
40
40
|
Authorization: token,
|
|
41
41
|
content_type: :json
|
|
42
42
|
)
|
|
@@ -44,13 +44,13 @@ module Discordrb::API::Application
|
|
|
44
44
|
|
|
45
45
|
# Edit a global application command.
|
|
46
46
|
# https://discord.com/developers/docs/interactions/slash-commands#edit-global-application-command
|
|
47
|
-
def edit_global_command(token, application_id, command_id, name = nil, description = nil, options = nil, default_permission = nil, type = 1)
|
|
47
|
+
def edit_global_command(token, application_id, command_id, name = nil, description = nil, options = nil, default_permission = nil, type = 1, default_member_permissions = nil, contexts = nil, nsfw = nil)
|
|
48
48
|
Discordrb::API.request(
|
|
49
49
|
:applications_aid_commands_cid,
|
|
50
50
|
nil,
|
|
51
51
|
:patch,
|
|
52
52
|
"#{Discordrb::API.api_base}/applications/#{application_id}/commands/#{command_id}",
|
|
53
|
-
{ name: name, description: description, options: options, default_permission: default_permission, type: type }.compact.to_json,
|
|
53
|
+
{ name: name, description: description, options: options, default_permission: default_permission, type: type, default_member_permissions: default_member_permissions, contexts: contexts, nsfw: nsfw }.compact.to_json,
|
|
54
54
|
Authorization: token,
|
|
55
55
|
content_type: :json
|
|
56
56
|
)
|
|
@@ -108,13 +108,13 @@ module Discordrb::API::Application
|
|
|
108
108
|
|
|
109
109
|
# Create an application command for a guild.
|
|
110
110
|
# https://discord.com/developers/docs/interactions/slash-commands#create-guild-application-command
|
|
111
|
-
def create_guild_command(token, application_id, guild_id, name, description, options = nil, default_permission = nil, type = 1)
|
|
111
|
+
def create_guild_command(token, application_id, guild_id, name, description, options = nil, default_permission = nil, type = 1, default_member_permissions = nil, contexts = nil, nsfw = false)
|
|
112
112
|
Discordrb::API.request(
|
|
113
113
|
:applications_aid_guilds_gid_commands,
|
|
114
114
|
guild_id,
|
|
115
115
|
:post,
|
|
116
116
|
"#{Discordrb::API.api_base}/applications/#{application_id}/guilds/#{guild_id}/commands",
|
|
117
|
-
{ name: name, description: description, options: options, default_permission: default_permission, type: type }.to_json,
|
|
117
|
+
{ name: name, description: description, options: options, default_permission: default_permission, type: type, default_member_permissions: default_member_permissions, contexts: contexts, nsfw: nsfw }.to_json,
|
|
118
118
|
Authorization: token,
|
|
119
119
|
content_type: :json
|
|
120
120
|
)
|
|
@@ -122,13 +122,13 @@ module Discordrb::API::Application
|
|
|
122
122
|
|
|
123
123
|
# Edit an application command for a guild.
|
|
124
124
|
# https://discord.com/developers/docs/interactions/slash-commands#edit-guild-application-command
|
|
125
|
-
def edit_guild_command(token, application_id, guild_id, command_id, name = nil, description = nil, options = nil, default_permission = nil, type = 1)
|
|
125
|
+
def edit_guild_command(token, application_id, guild_id, command_id, name = nil, description = nil, options = nil, default_permission = nil, type = 1, default_member_permissions = nil, contexts = nil, nsfw = nil)
|
|
126
126
|
Discordrb::API.request(
|
|
127
127
|
:applications_aid_guilds_gid_commands_cid,
|
|
128
128
|
guild_id,
|
|
129
129
|
:patch,
|
|
130
130
|
"#{Discordrb::API.api_base}/applications/#{application_id}/guilds/#{guild_id}/commands/#{command_id}",
|
|
131
|
-
{ name: name, description: description, options: options, default_permission: default_permission, type: type }.compact.to_json,
|
|
131
|
+
{ name: name, description: description, options: options, default_permission: default_permission, type: type, default_member_permissions: default_member_permissions, contexts: contexts, nsfw: nsfw }.compact.to_json,
|
|
132
132
|
Authorization: token,
|
|
133
133
|
content_type: :json
|
|
134
134
|
)
|
|
@@ -199,4 +199,80 @@ module Discordrb::API::Application
|
|
|
199
199
|
content_type: :json
|
|
200
200
|
)
|
|
201
201
|
end
|
|
202
|
+
|
|
203
|
+
# Get the permissions for a specific command in a guild.
|
|
204
|
+
# https://discord.com/developers/docs/interactions/application-commands#get-application-command-permissions
|
|
205
|
+
def get_application_command_permissions(token, application_id, guild_id, command_id)
|
|
206
|
+
Discordrb::API.request(
|
|
207
|
+
:applications_aid_guilds_gid_commands_cid_permissions,
|
|
208
|
+
guild_id,
|
|
209
|
+
:get,
|
|
210
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/guilds/#{guild_id}/commands/#{command_id}/permissions",
|
|
211
|
+
Authorization: token
|
|
212
|
+
)
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
# Get a list of application emojis.
|
|
216
|
+
# https://discord.com/developers/docs/resources/emoji#list-application-emojis
|
|
217
|
+
def list_application_emojis(token, application_id)
|
|
218
|
+
Discordrb::API.request(
|
|
219
|
+
:applications_aid_emojis,
|
|
220
|
+
application_id,
|
|
221
|
+
:get,
|
|
222
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/emojis",
|
|
223
|
+
Authorization: token
|
|
224
|
+
)
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
# Get an application emoji by ID.
|
|
228
|
+
# https://discord.com/developers/docs/resources/emoji#get-application-emoji
|
|
229
|
+
def get_application_emoji(token, application_id, emoji_id)
|
|
230
|
+
Discordrb::API.request(
|
|
231
|
+
:applications_aid_emojis_eid,
|
|
232
|
+
application_id,
|
|
233
|
+
:get,
|
|
234
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/emojis/#{emoji_id}",
|
|
235
|
+
Authorization: token
|
|
236
|
+
)
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
# Create an application emoji.
|
|
240
|
+
# https://discord.com/developers/docs/resources/emoji#create-application-emoji
|
|
241
|
+
def create_application_emoji(token, application_id, name, image)
|
|
242
|
+
Discordrb::API.request(
|
|
243
|
+
:applications_aid_emojis,
|
|
244
|
+
application_id,
|
|
245
|
+
:post,
|
|
246
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/emojis",
|
|
247
|
+
{ name: name, image: image }.to_json,
|
|
248
|
+
Authorization: token,
|
|
249
|
+
content_type: :json
|
|
250
|
+
)
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
# Edit an application emoji.
|
|
254
|
+
# https://discord.com/developers/docs/resources/emoji#modify-application-emoji
|
|
255
|
+
def edit_application_emoji(token, application_id, emoji_id, name)
|
|
256
|
+
Discordrb::API.request(
|
|
257
|
+
:applications_aid_emojis_eid,
|
|
258
|
+
application_id,
|
|
259
|
+
:patch,
|
|
260
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/emojis/#{emoji_id}",
|
|
261
|
+
{ name: name }.to_json,
|
|
262
|
+
Authorization: token,
|
|
263
|
+
content_type: :json
|
|
264
|
+
)
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
# Delete an application emoji.
|
|
268
|
+
# https://discord.com/developers/docs/resources/emoji#delete-application-emoji
|
|
269
|
+
def delete_application_emoji(token, application_id, emoji_id)
|
|
270
|
+
Discordrb::API.request(
|
|
271
|
+
:applications_aid_emojis_eid,
|
|
272
|
+
application_id,
|
|
273
|
+
:delete,
|
|
274
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/emojis/#{emoji_id}",
|
|
275
|
+
Authorization: token
|
|
276
|
+
)
|
|
277
|
+
end
|
|
202
278
|
end
|
|
@@ -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,
|
|
@@ -75,8 +75,8 @@ module Discordrb::API::Channel
|
|
|
75
75
|
# https://discord.com/developers/docs/resources/channel#create-message
|
|
76
76
|
# @param attachments [Array<File>, nil] Attachments to use with `attachment://` in embeds. See
|
|
77
77
|
# https://discord.com/developers/docs/resources/channel#create-message-using-attachments-within-embeds
|
|
78
|
-
def create_message(token, channel_id, message, tts = false, embeds = nil, nonce = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil)
|
|
79
|
-
body = { content: message, tts: tts, embeds: embeds, nonce: nonce, allowed_mentions: allowed_mentions, message_reference: message_reference, components: components&.to_a }
|
|
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 }
|
|
80
80
|
body = if attachments
|
|
81
81
|
files = [*0...attachments.size].zip(attachments).to_h
|
|
82
82
|
{ **files, payload_json: body.to_json }
|
|
@@ -117,13 +117,13 @@ module Discordrb::API::Channel
|
|
|
117
117
|
|
|
118
118
|
# Edit a message
|
|
119
119
|
# https://discord.com/developers/docs/resources/channel#edit-message
|
|
120
|
-
def edit_message(token, channel_id, message_id, message, mentions = [], embeds = nil, components = nil)
|
|
120
|
+
def edit_message(token, channel_id, message_id, message, mentions = [], embeds = nil, components = nil, flags = nil)
|
|
121
121
|
Discordrb::API.request(
|
|
122
122
|
:channels_cid_messages_mid,
|
|
123
123
|
channel_id,
|
|
124
124
|
:patch,
|
|
125
125
|
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}",
|
|
126
|
-
{ content: message,
|
|
126
|
+
{ content: message, allowed_mentions: mentions, embeds: embeds, components: components, flags: flags }.reject { |_, v| v == :undef }.to_json,
|
|
127
127
|
Authorization: token,
|
|
128
128
|
content_type: :json
|
|
129
129
|
)
|
|
@@ -142,6 +142,18 @@ module Discordrb::API::Channel
|
|
|
142
142
|
)
|
|
143
143
|
end
|
|
144
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
|
+
|
|
145
157
|
# Delete messages in bulk
|
|
146
158
|
# https://discord.com/developers/docs/resources/channel#bulk-delete-messages
|
|
147
159
|
def bulk_delete_messages(token, channel_id, messages = [], reason = nil)
|
|
@@ -307,25 +319,26 @@ module Discordrb::API::Channel
|
|
|
307
319
|
end
|
|
308
320
|
|
|
309
321
|
# Get a list of pinned messages in a channel
|
|
310
|
-
# https://discord.com/developers/docs/resources/
|
|
311
|
-
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)
|
|
312
325
|
Discordrb::API.request(
|
|
313
326
|
:channels_cid_pins,
|
|
314
327
|
channel_id,
|
|
315
328
|
:get,
|
|
316
|
-
"#{Discordrb::API.api_base}/channels/#{channel_id}/pins",
|
|
329
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/pins?#{query}",
|
|
317
330
|
Authorization: token
|
|
318
331
|
)
|
|
319
332
|
end
|
|
320
333
|
|
|
321
334
|
# Pin a message
|
|
322
|
-
# https://discord.com/developers/docs/resources/
|
|
335
|
+
# https://discord.com/developers/docs/resources/message#pin-message
|
|
323
336
|
def pin_message(token, channel_id, message_id, reason = nil)
|
|
324
337
|
Discordrb::API.request(
|
|
325
338
|
:channels_cid_pins_mid,
|
|
326
339
|
channel_id,
|
|
327
340
|
:put,
|
|
328
|
-
"#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{message_id}",
|
|
341
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/pins/#{message_id}",
|
|
329
342
|
nil,
|
|
330
343
|
Authorization: token,
|
|
331
344
|
'X-Audit-Log-Reason': reason
|
|
@@ -333,13 +346,13 @@ module Discordrb::API::Channel
|
|
|
333
346
|
end
|
|
334
347
|
|
|
335
348
|
# Unpin a message
|
|
336
|
-
# https://discord.com/developers/docs/resources/
|
|
349
|
+
# https://discord.com/developers/docs/resources/message#unpin-message
|
|
337
350
|
def unpin_message(token, channel_id, message_id, reason = nil)
|
|
338
351
|
Discordrb::API.request(
|
|
339
352
|
:channels_cid_pins_mid,
|
|
340
353
|
channel_id,
|
|
341
354
|
:delete,
|
|
342
|
-
"#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{message_id}",
|
|
355
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/pins/#{message_id}",
|
|
343
356
|
Authorization: token,
|
|
344
357
|
'X-Audit-Log-Reason': reason
|
|
345
358
|
)
|
|
@@ -596,4 +609,29 @@ module Discordrb::API::Channel
|
|
|
596
609
|
Authorization: token
|
|
597
610
|
)
|
|
598
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
|
|
599
637
|
end
|
|
@@ -6,16 +6,25 @@ module Discordrb::API::Interaction
|
|
|
6
6
|
|
|
7
7
|
# Respond to an interaction.
|
|
8
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)
|
|
10
|
-
|
|
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
|
|
11
20
|
|
|
12
21
|
Discordrb::API.request(
|
|
13
22
|
:interactions_iid_token_callback,
|
|
14
23
|
interaction_id,
|
|
15
24
|
:post,
|
|
16
25
|
"#{Discordrb::API.api_base}/interactions/#{interaction_id}/#{interaction_token}/callback",
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
body,
|
|
27
|
+
headers
|
|
19
28
|
)
|
|
20
29
|
end
|
|
21
30
|
|
|
@@ -42,8 +51,8 @@ module Discordrb::API::Interaction
|
|
|
42
51
|
|
|
43
52
|
# Edit the original response to an interaction.
|
|
44
53
|
# https://discord.com/developers/docs/interactions/slash-commands#edit-original-interaction-response
|
|
45
|
-
def edit_original_interaction_response(interaction_token, application_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil)
|
|
46
|
-
Discordrb::API::Webhook.token_edit_message(interaction_token, application_id, '@original', content, embeds, allowed_mentions, components)
|
|
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)
|
|
47
56
|
end
|
|
48
57
|
|
|
49
58
|
# Delete the original response to an interaction.
|
data/lib/discordrb/api/invite.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Discordrb::API::Invite
|
|
|
11
11
|
:invite_code,
|
|
12
12
|
nil,
|
|
13
13
|
:get,
|
|
14
|
-
"#{Discordrb::API.api_base}/invites/#{invite_code}#{
|
|
14
|
+
"#{Discordrb::API.api_base}/invites/#{invite_code}#{'?with_counts=true' if counts}",
|
|
15
15
|
Authorization: token
|
|
16
16
|
)
|
|
17
17
|
end
|
data/lib/discordrb/api/server.rb
CHANGED
|
@@ -4,20 +4,6 @@
|
|
|
4
4
|
module Discordrb::API::Server
|
|
5
5
|
module_function
|
|
6
6
|
|
|
7
|
-
# Create a server
|
|
8
|
-
# https://discord.com/developers/docs/resources/guild#create-guild
|
|
9
|
-
def create(token, name, region = :'eu-central')
|
|
10
|
-
Discordrb::API.request(
|
|
11
|
-
:guilds,
|
|
12
|
-
nil,
|
|
13
|
-
:post,
|
|
14
|
-
"#{Discordrb::API.api_base}/guilds",
|
|
15
|
-
{ name: name, region: region.to_s }.to_json,
|
|
16
|
-
Authorization: token,
|
|
17
|
-
content_type: :json
|
|
18
|
-
)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
7
|
# Get a server's data
|
|
22
8
|
# https://discord.com/developers/docs/resources/guild#get-guild
|
|
23
9
|
def resolve(token, server_id, with_counts = nil)
|
|
@@ -45,33 +31,6 @@ module Discordrb::API::Server
|
|
|
45
31
|
)
|
|
46
32
|
end
|
|
47
33
|
|
|
48
|
-
# Transfer server ownership
|
|
49
|
-
# https://discord.com/developers/docs/resources/guild#modify-guild
|
|
50
|
-
def transfer_ownership(token, server_id, user_id, reason = nil)
|
|
51
|
-
Discordrb::API.request(
|
|
52
|
-
:guilds_sid,
|
|
53
|
-
server_id,
|
|
54
|
-
:patch,
|
|
55
|
-
"#{Discordrb::API.api_base}/guilds/#{server_id}",
|
|
56
|
-
{ owner_id: user_id }.to_json,
|
|
57
|
-
Authorization: token,
|
|
58
|
-
content_type: :json,
|
|
59
|
-
'X-Audit-Log-Reason': reason
|
|
60
|
-
)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
# Delete a server
|
|
64
|
-
# https://discord.com/developers/docs/resources/guild#delete-guild
|
|
65
|
-
def delete(token, server_id)
|
|
66
|
-
Discordrb::API.request(
|
|
67
|
-
:guilds_sid,
|
|
68
|
-
server_id,
|
|
69
|
-
:delete,
|
|
70
|
-
"#{Discordrb::API.api_base}/guilds/#{server_id}",
|
|
71
|
-
Authorization: token
|
|
72
|
-
)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
34
|
# Get a server's channels list
|
|
76
35
|
# https://discord.com/developers/docs/resources/guild#get-guild-channels
|
|
77
36
|
def channels(token, server_id)
|
|
@@ -99,6 +58,18 @@ module Discordrb::API::Server
|
|
|
99
58
|
)
|
|
100
59
|
end
|
|
101
60
|
|
|
61
|
+
# Get the preview of a server.
|
|
62
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-preview
|
|
63
|
+
def preview(token, server_id)
|
|
64
|
+
Discordrb::API.request(
|
|
65
|
+
:guilds_sid_preview,
|
|
66
|
+
server_id,
|
|
67
|
+
:get,
|
|
68
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/preview",
|
|
69
|
+
Authorization: token
|
|
70
|
+
)
|
|
71
|
+
end
|
|
72
|
+
|
|
102
73
|
# Update a channels position
|
|
103
74
|
# https://discord.com/developers/docs/resources/guild#modify-guild-channel-positions
|
|
104
75
|
def update_channel_positions(token, server_id, positions)
|
|
@@ -138,10 +109,23 @@ module Discordrb::API::Server
|
|
|
138
109
|
)
|
|
139
110
|
end
|
|
140
111
|
|
|
112
|
+
# Search for a guild member
|
|
113
|
+
# https://discord.com/developers/docs/resources/guild#search-guild-members
|
|
114
|
+
def search_guild_members(token, server_id, query, limit)
|
|
115
|
+
query_string = URI.encode_www_form({ query: query, limit: limit }.compact)
|
|
116
|
+
Discordrb::API.request(
|
|
117
|
+
:guilds_sid_members,
|
|
118
|
+
server_id,
|
|
119
|
+
:get,
|
|
120
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/members/search?#{query_string}",
|
|
121
|
+
Authorization: token
|
|
122
|
+
)
|
|
123
|
+
end
|
|
124
|
+
|
|
141
125
|
# Update a user properties
|
|
142
126
|
# https://discord.com/developers/docs/resources/guild#modify-guild-member
|
|
143
127
|
def update_member(token, server_id, user_id, nick: :undef, roles: :undef, mute: :undef, deaf: :undef, channel_id: :undef,
|
|
144
|
-
communication_disabled_until: :undef, reason: nil)
|
|
128
|
+
communication_disabled_until: :undef, flags: :undef, reason: nil)
|
|
145
129
|
Discordrb::API.request(
|
|
146
130
|
:guilds_sid_members_uid,
|
|
147
131
|
server_id,
|
|
@@ -152,7 +136,8 @@ module Discordrb::API::Server
|
|
|
152
136
|
mute: mute,
|
|
153
137
|
deaf: deaf,
|
|
154
138
|
channel_id: channel_id,
|
|
155
|
-
communication_disabled_until: communication_disabled_until
|
|
139
|
+
communication_disabled_until: communication_disabled_until,
|
|
140
|
+
flags: flags
|
|
156
141
|
}.reject { |_, v| v == :undef }.to_json,
|
|
157
142
|
Authorization: token,
|
|
158
143
|
content_type: :json,
|
|
@@ -160,6 +145,21 @@ module Discordrb::API::Server
|
|
|
160
145
|
)
|
|
161
146
|
end
|
|
162
147
|
|
|
148
|
+
# Update the current member's properties.
|
|
149
|
+
# https://discord.com/developers/docs/resources/guild#modify-current-member
|
|
150
|
+
def update_current_member(token, server_id, nick = :undef, reason = nil)
|
|
151
|
+
Discordrb::API.request(
|
|
152
|
+
:guilds_sid_members_me,
|
|
153
|
+
server_id,
|
|
154
|
+
:patch,
|
|
155
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/members/@me",
|
|
156
|
+
{ nick: nick }.reject { |_, v| v == :undef }.to_json,
|
|
157
|
+
Authorization: token,
|
|
158
|
+
content_type: :json,
|
|
159
|
+
'X-Audit-Log-Reason': reason
|
|
160
|
+
)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
163
|
# Remove user from server
|
|
164
164
|
# https://discord.com/developers/docs/resources/guild#remove-guild-member
|
|
165
165
|
def remove_member(token, server_id, user_id, reason = nil)
|
|
@@ -187,17 +187,24 @@ module Discordrb::API::Server
|
|
|
187
187
|
)
|
|
188
188
|
end
|
|
189
189
|
|
|
190
|
-
#
|
|
190
|
+
# @deprecated Please use {ban_user!} instead.
|
|
191
191
|
# https://discord.com/developers/docs/resources/guild#create-guild-ban
|
|
192
192
|
def ban_user(token, server_id, user_id, message_days, reason = nil)
|
|
193
|
-
|
|
193
|
+
ban_user!(token, server_id, user_id, message_days * 86_400, reason)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Ban a user from a server and delete their messages up to a given amount of time.
|
|
197
|
+
# https://discord.com/developers/docs/resources/guild#create-guild-ban
|
|
198
|
+
def ban_user!(token, server_id, user_id, message_seconds, reason = nil)
|
|
194
199
|
Discordrb::API.request(
|
|
195
200
|
:guilds_sid_bans_uid,
|
|
196
201
|
server_id,
|
|
197
202
|
:put,
|
|
198
|
-
"#{Discordrb::API.api_base}/guilds/#{server_id}/bans/#{user_id}
|
|
199
|
-
|
|
200
|
-
Authorization: token
|
|
203
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/bans/#{user_id}",
|
|
204
|
+
{ delete_message_seconds: message_seconds }.to_json,
|
|
205
|
+
Authorization: token,
|
|
206
|
+
content_type: :json,
|
|
207
|
+
'X-Audit-Log-Reason': reason
|
|
201
208
|
)
|
|
202
209
|
end
|
|
203
210
|
|
|
@@ -231,13 +238,13 @@ module Discordrb::API::Server
|
|
|
231
238
|
# sending TTS messages, embedding links, sending files, reading the history, mentioning everybody,
|
|
232
239
|
# connecting to voice, speaking and voice activity (push-to-talk isn't mandatory)
|
|
233
240
|
# https://discord.com/developers/docs/resources/guild#get-guild-roles
|
|
234
|
-
def create_role(token, server_id, name, colour, hoist, mentionable, packed_permissions, reason = nil)
|
|
241
|
+
def create_role(token, server_id, name, colour, hoist, mentionable, packed_permissions, reason = nil, colours = nil, icon = nil, unicode_emoji = nil)
|
|
235
242
|
Discordrb::API.request(
|
|
236
243
|
:guilds_sid_roles,
|
|
237
244
|
server_id,
|
|
238
245
|
:post,
|
|
239
246
|
"#{Discordrb::API.api_base}/guilds/#{server_id}/roles",
|
|
240
|
-
{ color: colour, name: name, hoist: hoist, mentionable: mentionable, permissions: packed_permissions }.to_json,
|
|
247
|
+
{ color: colour, name: name, hoist: hoist, mentionable: mentionable, permissions: packed_permissions, colors: colours, icon: icon, unicode_emoji: unicode_emoji }.compact.to_json,
|
|
241
248
|
Authorization: token,
|
|
242
249
|
content_type: :json,
|
|
243
250
|
'X-Audit-Log-Reason': reason
|
|
@@ -250,17 +257,11 @@ module Discordrb::API::Server
|
|
|
250
257
|
# connecting to voice, speaking and voice activity (push-to-talk isn't mandatory)
|
|
251
258
|
# https://discord.com/developers/docs/resources/guild#batch-modify-guild-role
|
|
252
259
|
# @param icon [:undef, File]
|
|
253
|
-
def update_role(token, server_id, role_id, name, colour, hoist = false, mentionable = false, packed_permissions = 104_324_161, reason = nil, icon = :undef)
|
|
254
|
-
data = { color: colour, name: name, hoist: hoist, mentionable: mentionable, permissions: packed_permissions }
|
|
260
|
+
def update_role(token, server_id, role_id, name, colour, hoist = false, mentionable = false, packed_permissions = 104_324_161, reason = nil, icon = :undef, unicode_emoji = :undef, colours = :undef)
|
|
261
|
+
data = { color: colour, name: name, hoist: hoist, mentionable: mentionable, permissions: packed_permissions, colors: colours, unicode_emoji: unicode_emoji }
|
|
255
262
|
|
|
256
263
|
if icon != :undef && icon
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
raise ArgumentError, 'File object must respond to original_filename, path, or local path.' unless path_method
|
|
260
|
-
raise ArgumentError, 'File must respond to read' unless icon.respond_to? :read
|
|
261
|
-
|
|
262
|
-
mime_type = MIME::Types.type_for(icon.__send__(path_method)).first&.to_s || 'image/jpeg'
|
|
263
|
-
data[:icon] = "data:#{mime_type};base64,#{Base64.encode64(icon.read).strip}"
|
|
264
|
+
data[:icon] = Discordrb.encode64(icon)
|
|
264
265
|
elsif icon.nil?
|
|
265
266
|
data[:icon] = nil
|
|
266
267
|
end
|
|
@@ -270,7 +271,7 @@ module Discordrb::API::Server
|
|
|
270
271
|
server_id,
|
|
271
272
|
:patch,
|
|
272
273
|
"#{Discordrb::API.api_base}/guilds/#{server_id}/roles/#{role_id}",
|
|
273
|
-
data.to_json,
|
|
274
|
+
data.reject { |_, value| value == :undef }.to_json,
|
|
274
275
|
Authorization: token,
|
|
275
276
|
content_type: :json,
|
|
276
277
|
'X-Audit-Log-Reason': reason
|
|
@@ -556,4 +557,39 @@ module Discordrb::API::Server
|
|
|
556
557
|
Authorization: token
|
|
557
558
|
)
|
|
558
559
|
end
|
|
560
|
+
|
|
561
|
+
# Make an member avatar URL from the server, user and avatar IDs
|
|
562
|
+
def avatar_url(server_id, user_id, avatar_id, format = nil)
|
|
563
|
+
format ||= if avatar_id.start_with?('a_')
|
|
564
|
+
'gif'
|
|
565
|
+
else
|
|
566
|
+
'webp'
|
|
567
|
+
end
|
|
568
|
+
"#{Discordrb::API.cdn_url}/guilds/#{server_id}/users/#{user_id}/avatars/#{avatar_id}.#{format}"
|
|
569
|
+
end
|
|
570
|
+
|
|
571
|
+
# Make a banner URL from the server, user and banner IDs
|
|
572
|
+
def banner_url(server_id, user_id, banner_id, format = nil)
|
|
573
|
+
format ||= if banner_id.start_with?('a_')
|
|
574
|
+
'gif'
|
|
575
|
+
else
|
|
576
|
+
'webp'
|
|
577
|
+
end
|
|
578
|
+
"#{Discordrb::API.cdn_url}/guilds/#{server_id}/users/#{user_id}/banners/#{banner_id}.#{format}"
|
|
579
|
+
end
|
|
580
|
+
|
|
581
|
+
# Ban multiple users in one go
|
|
582
|
+
# https://discord.com/developers/docs/resources/guild#bulk-guild-ban
|
|
583
|
+
def bulk_ban(token, server_id, users, message_seconds, reason = nil)
|
|
584
|
+
Discordrb::API.request(
|
|
585
|
+
:guilds_sid_bulk_bans,
|
|
586
|
+
server_id,
|
|
587
|
+
:post,
|
|
588
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/bulk-ban",
|
|
589
|
+
{ user_ids: users, delete_message_seconds: message_seconds }.compact.to_json,
|
|
590
|
+
content_type: :json,
|
|
591
|
+
Authorization: token,
|
|
592
|
+
'X-Audit-Log-Reason': reason
|
|
593
|
+
)
|
|
594
|
+
end
|
|
559
595
|
end
|
data/lib/discordrb/api/user.rb
CHANGED
|
@@ -28,8 +28,8 @@ module Discordrb::API::User
|
|
|
28
28
|
)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
#
|
|
32
|
-
# https://discord.com/developers/docs/resources/user#modify-current-user
|
|
31
|
+
# @deprecated Please use {Discordrb::API::Server.update_current_member} instead.
|
|
32
|
+
# https://discord.com/developers/docs/resources/user#modify-current-user-nick
|
|
33
33
|
def change_own_nickname(token, server_id, nick, reason = nil)
|
|
34
34
|
Discordrb::API.request(
|
|
35
35
|
:guilds_sid_members_me_nick,
|
|
@@ -152,4 +152,14 @@ module Discordrb::API::User
|
|
|
152
152
|
end
|
|
153
153
|
"#{Discordrb::API.cdn_url}/avatars/#{user_id}/#{avatar_id}.#{format}"
|
|
154
154
|
end
|
|
155
|
+
|
|
156
|
+
# Make a banner URL from the user and banner IDs
|
|
157
|
+
def banner_url(user_id, banner_id, format = nil)
|
|
158
|
+
format ||= if banner_id.start_with?('a_')
|
|
159
|
+
'gif'
|
|
160
|
+
else
|
|
161
|
+
'png'
|
|
162
|
+
end
|
|
163
|
+
"#{Discordrb::API.cdn_url}/banners/#{user_id}/#{banner_id}.#{format}"
|
|
164
|
+
end
|
|
155
165
|
end
|
|
@@ -29,15 +29,19 @@ module Discordrb::API::Webhook
|
|
|
29
29
|
|
|
30
30
|
# Execute a webhook via token.
|
|
31
31
|
# https://discord.com/developers/docs/resources/webhook#execute-webhook
|
|
32
|
-
def token_execute_webhook(webhook_token, webhook_id, wait = false, content = nil, username = nil, avatar_url = nil, tts = nil, file = nil, embeds = nil, allowed_mentions = nil, flags = nil, components = nil)
|
|
32
|
+
def token_execute_webhook(webhook_token, webhook_id, wait = false, content = nil, username = nil, avatar_url = nil, tts = nil, file = nil, embeds = nil, allowed_mentions = nil, flags = nil, components = nil, attachments = nil)
|
|
33
33
|
body = { content: content, username: username, avatar_url: avatar_url, tts: tts, embeds: embeds&.map(&:to_hash), allowed_mentions: allowed_mentions, flags: flags, components: components }
|
|
34
|
+
|
|
34
35
|
body = if file
|
|
35
36
|
{ file: file, payload_json: body.to_json }
|
|
37
|
+
elsif attachments
|
|
38
|
+
files = [*0...attachments.size].zip(attachments).to_h
|
|
39
|
+
{ **files, payload_json: body.to_json }
|
|
36
40
|
else
|
|
37
41
|
body.to_json
|
|
38
42
|
end
|
|
39
43
|
|
|
40
|
-
headers = { content_type: :json } unless file
|
|
44
|
+
headers = { content_type: :json } unless file || attachments
|
|
41
45
|
|
|
42
46
|
Discordrb::API.request(
|
|
43
47
|
:webhooks_wid,
|
|
@@ -116,14 +120,25 @@ module Discordrb::API::Webhook
|
|
|
116
120
|
|
|
117
121
|
# Edit a webhook message via webhook token
|
|
118
122
|
# https://discord.com/developers/docs/resources/webhook#edit-webhook-message
|
|
119
|
-
def token_edit_message(webhook_token, webhook_id, message_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil)
|
|
123
|
+
def token_edit_message(webhook_token, webhook_id, message_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil, attachments = nil)
|
|
124
|
+
body = { content: content, embeds: embeds, allowed_mentions: allowed_mentions, components: components }
|
|
125
|
+
|
|
126
|
+
body = if attachments
|
|
127
|
+
files = [*0...attachments.size].zip(attachments).to_h
|
|
128
|
+
{ **files, payload_json: body.to_json }
|
|
129
|
+
else
|
|
130
|
+
body.to_json
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
headers = { content_type: :json } unless attachments
|
|
134
|
+
|
|
120
135
|
Discordrb::API.request(
|
|
121
136
|
:webhooks_wid_messages,
|
|
122
137
|
webhook_id,
|
|
123
138
|
:patch,
|
|
124
139
|
"#{Discordrb::API.api_base}/webhooks/#{webhook_id}/#{webhook_token}/messages/#{message_id}",
|
|
125
|
-
|
|
126
|
-
|
|
140
|
+
body,
|
|
141
|
+
headers
|
|
127
142
|
)
|
|
128
143
|
end
|
|
129
144
|
|