discordrb 3.3.0 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +152 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +24 -0
- data/.github/pull_request_template.md +37 -0
- data/.github/workflows/codeql.yml +65 -0
- data/.markdownlint.json +4 -0
- data/.rubocop.yml +39 -36
- data/CHANGELOG.md +874 -552
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +80 -86
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/discordrb-webhooks.gemspec +9 -6
- data/discordrb.gemspec +21 -18
- data/lib/discordrb/allowed_mentions.rb +36 -0
- data/lib/discordrb/api/application.rb +202 -0
- data/lib/discordrb/api/channel.rb +236 -47
- data/lib/discordrb/api/interaction.rb +54 -0
- data/lib/discordrb/api/invite.rb +5 -5
- data/lib/discordrb/api/server.rb +94 -66
- data/lib/discordrb/api/user.rb +17 -11
- data/lib/discordrb/api/webhook.rb +63 -6
- data/lib/discordrb/api.rb +55 -16
- data/lib/discordrb/await.rb +0 -1
- data/lib/discordrb/bot.rb +480 -93
- data/lib/discordrb/cache.rb +31 -24
- data/lib/discordrb/colour_rgb.rb +43 -0
- data/lib/discordrb/commands/command_bot.rb +35 -12
- data/lib/discordrb/commands/container.rb +21 -24
- data/lib/discordrb/commands/parser.rb +20 -20
- data/lib/discordrb/commands/rate_limiter.rb +4 -3
- data/lib/discordrb/container.rb +209 -20
- data/lib/discordrb/data/activity.rb +271 -0
- data/lib/discordrb/data/application.rb +50 -0
- data/lib/discordrb/data/attachment.rb +71 -0
- data/lib/discordrb/data/audit_logs.rb +345 -0
- data/lib/discordrb/data/channel.rb +993 -0
- data/lib/discordrb/data/component.rb +229 -0
- data/lib/discordrb/data/embed.rb +251 -0
- data/lib/discordrb/data/emoji.rb +82 -0
- data/lib/discordrb/data/integration.rb +122 -0
- data/lib/discordrb/data/interaction.rb +800 -0
- data/lib/discordrb/data/invite.rb +137 -0
- data/lib/discordrb/data/member.rb +372 -0
- data/lib/discordrb/data/message.rb +414 -0
- data/lib/discordrb/data/overwrite.rb +108 -0
- data/lib/discordrb/data/profile.rb +91 -0
- data/lib/discordrb/data/reaction.rb +33 -0
- data/lib/discordrb/data/recipient.rb +34 -0
- data/lib/discordrb/data/role.rb +248 -0
- data/lib/discordrb/data/server.rb +1004 -0
- data/lib/discordrb/data/user.rb +264 -0
- data/lib/discordrb/data/voice_region.rb +45 -0
- data/lib/discordrb/data/voice_state.rb +41 -0
- data/lib/discordrb/data/webhook.rb +238 -0
- data/lib/discordrb/data.rb +28 -4180
- data/lib/discordrb/errors.rb +46 -4
- data/lib/discordrb/events/bans.rb +7 -5
- data/lib/discordrb/events/channels.rb +3 -1
- data/lib/discordrb/events/guilds.rb +16 -9
- data/lib/discordrb/events/interactions.rb +482 -0
- data/lib/discordrb/events/invites.rb +125 -0
- data/lib/discordrb/events/members.rb +6 -2
- data/lib/discordrb/events/message.rb +72 -27
- data/lib/discordrb/events/presence.rb +35 -18
- data/lib/discordrb/events/raw.rb +1 -3
- data/lib/discordrb/events/reactions.rb +49 -4
- data/lib/discordrb/events/threads.rb +96 -0
- data/lib/discordrb/events/typing.rb +6 -4
- data/lib/discordrb/events/voice_server_update.rb +47 -0
- data/lib/discordrb/events/voice_state_update.rb +15 -10
- data/lib/discordrb/events/webhooks.rb +9 -6
- data/lib/discordrb/gateway.rb +99 -71
- data/lib/discordrb/id_object.rb +39 -0
- data/lib/discordrb/light/integrations.rb +1 -1
- data/lib/discordrb/light/light_bot.rb +1 -1
- data/lib/discordrb/logger.rb +4 -4
- data/lib/discordrb/paginator.rb +57 -0
- data/lib/discordrb/permissions.rb +159 -39
- data/lib/discordrb/version.rb +1 -1
- data/lib/discordrb/voice/encoder.rb +16 -7
- data/lib/discordrb/voice/network.rb +99 -47
- data/lib/discordrb/voice/sodium.rb +98 -0
- data/lib/discordrb/voice/voice_bot.rb +33 -25
- data/lib/discordrb/webhooks.rb +2 -0
- data/lib/discordrb.rb +107 -1
- metadata +126 -54
- data/.codeclimate.yml +0 -16
- data/.travis.yml +0 -33
- data/bin/travis_build_docs.sh +0 -17
- /data/{CONTRIBUTING.md → .github/CONTRIBUTING.md} +0 -0
@@ -5,7 +5,7 @@ module Discordrb::API::Channel
|
|
5
5
|
module_function
|
6
6
|
|
7
7
|
# Get a channel's data
|
8
|
-
# https://
|
8
|
+
# https://discord.com/developers/docs/resources/channel#get-channel
|
9
9
|
def resolve(token, channel_id)
|
10
10
|
Discordrb::API.request(
|
11
11
|
:channels_cid,
|
@@ -17,7 +17,7 @@ module Discordrb::API::Channel
|
|
17
17
|
end
|
18
18
|
|
19
19
|
# Update a channel's data
|
20
|
-
# https://
|
20
|
+
# https://discord.com/developers/docs/resources/channel#modify-channel
|
21
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
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 }
|
23
23
|
data[:permission_overwrites] = permission_overwrites unless permission_overwrites.nil?
|
@@ -34,7 +34,7 @@ module Discordrb::API::Channel
|
|
34
34
|
end
|
35
35
|
|
36
36
|
# Delete a channel
|
37
|
-
# https://
|
37
|
+
# https://discord.com/developers/docs/resources/channel#deleteclose-channel
|
38
38
|
def delete(token, channel_id, reason = nil)
|
39
39
|
Discordrb::API.request(
|
40
40
|
:channels_cid,
|
@@ -47,19 +47,20 @@ module Discordrb::API::Channel
|
|
47
47
|
end
|
48
48
|
|
49
49
|
# Get a list of messages from a channel's history
|
50
|
-
# https://
|
50
|
+
# https://discord.com/developers/docs/resources/channel#get-channel-messages
|
51
51
|
def messages(token, channel_id, amount, before = nil, after = nil, around = nil)
|
52
|
+
query_string = URI.encode_www_form({ limit: amount, before: before, after: after, around: around }.compact)
|
52
53
|
Discordrb::API.request(
|
53
54
|
:channels_cid_messages,
|
54
55
|
channel_id,
|
55
56
|
:get,
|
56
|
-
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages
|
57
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages?#{query_string}",
|
57
58
|
Authorization: token
|
58
59
|
)
|
59
60
|
end
|
60
61
|
|
61
62
|
# Get a single message from a channel's history by id
|
62
|
-
# https://
|
63
|
+
# https://discord.com/developers/docs/resources/channel#get-channel-message
|
63
64
|
def message(token, channel_id, message_id)
|
64
65
|
Discordrb::API.request(
|
65
66
|
:channels_cid_messages_mid,
|
@@ -71,25 +72,38 @@ module Discordrb::API::Channel
|
|
71
72
|
end
|
72
73
|
|
73
74
|
# Send a message to a channel
|
74
|
-
# https://
|
75
|
-
|
75
|
+
# https://discord.com/developers/docs/resources/channel#create-message
|
76
|
+
# @param attachments [Array<File>, nil] Attachments to use with `attachment://` in embeds. See
|
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 }
|
80
|
+
body = if attachments
|
81
|
+
files = [*0...attachments.size].zip(attachments).to_h
|
82
|
+
{ **files, payload_json: body.to_json }
|
83
|
+
else
|
84
|
+
body.to_json
|
85
|
+
end
|
86
|
+
|
87
|
+
headers = { Authorization: token }
|
88
|
+
headers[:content_type] = :json unless attachments
|
89
|
+
|
76
90
|
Discordrb::API.request(
|
77
91
|
:channels_cid_messages_mid,
|
78
92
|
channel_id,
|
79
93
|
:post,
|
80
94
|
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages",
|
81
|
-
|
82
|
-
|
83
|
-
content_type: :json
|
95
|
+
body,
|
96
|
+
**headers
|
84
97
|
)
|
85
98
|
rescue RestClient::BadRequest => e
|
86
99
|
parsed = JSON.parse(e.response.body)
|
87
|
-
raise Discordrb::Errors::MessageTooLong, "Message over the character limit (#{message.length} > 2000)" if parsed['content']
|
100
|
+
raise Discordrb::Errors::MessageTooLong, "Message over the character limit (#{message.length} > 2000)" if parsed['content'].is_a?(Array) && parsed['content'].first == 'Must be 2000 or fewer in length.'
|
101
|
+
|
88
102
|
raise
|
89
103
|
end
|
90
104
|
|
91
105
|
# Send a file as a message to a channel
|
92
|
-
# https://
|
106
|
+
# https://discord.com/developers/docs/resources/channel#upload-file
|
93
107
|
def upload_file(token, channel_id, file, caption: nil, tts: false)
|
94
108
|
Discordrb::API.request(
|
95
109
|
:channels_cid_messages_mid,
|
@@ -102,34 +116,35 @@ module Discordrb::API::Channel
|
|
102
116
|
end
|
103
117
|
|
104
118
|
# Edit a message
|
105
|
-
# https://
|
106
|
-
def edit_message(token, channel_id, message_id, message, mentions = [],
|
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)
|
107
121
|
Discordrb::API.request(
|
108
122
|
:channels_cid_messages_mid,
|
109
123
|
channel_id,
|
110
124
|
:patch,
|
111
125
|
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}",
|
112
|
-
{ content: message, mentions: mentions,
|
126
|
+
{ content: message, mentions: mentions, embeds: embeds, components: components }.to_json,
|
113
127
|
Authorization: token,
|
114
128
|
content_type: :json
|
115
129
|
)
|
116
130
|
end
|
117
131
|
|
118
132
|
# Delete a message
|
119
|
-
# https://
|
120
|
-
def delete_message(token, channel_id, message_id)
|
133
|
+
# https://discord.com/developers/docs/resources/channel#delete-message
|
134
|
+
def delete_message(token, channel_id, message_id, reason = nil)
|
121
135
|
Discordrb::API.request(
|
122
136
|
:channels_cid_messages_mid,
|
123
137
|
channel_id,
|
124
138
|
:delete,
|
125
139
|
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}",
|
126
|
-
Authorization: token
|
140
|
+
Authorization: token,
|
141
|
+
'X-Audit-Log-Reason': reason
|
127
142
|
)
|
128
143
|
end
|
129
144
|
|
130
145
|
# Delete messages in bulk
|
131
|
-
# https://
|
132
|
-
def bulk_delete_messages(token, channel_id, messages = [])
|
146
|
+
# https://discord.com/developers/docs/resources/channel#bulk-delete-messages
|
147
|
+
def bulk_delete_messages(token, channel_id, messages = [], reason = nil)
|
133
148
|
Discordrb::API.request(
|
134
149
|
:channels_cid_messages_bulk_delete,
|
135
150
|
channel_id,
|
@@ -137,14 +152,15 @@ module Discordrb::API::Channel
|
|
137
152
|
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/bulk-delete",
|
138
153
|
{ messages: messages }.to_json,
|
139
154
|
Authorization: token,
|
140
|
-
content_type: :json
|
155
|
+
content_type: :json,
|
156
|
+
'X-Audit-Log-Reason': reason
|
141
157
|
)
|
142
158
|
end
|
143
159
|
|
144
160
|
# Create a reaction on a message using this client
|
145
|
-
# https://
|
161
|
+
# https://discord.com/developers/docs/resources/channel#create-reaction
|
146
162
|
def create_reaction(token, channel_id, message_id, emoji)
|
147
|
-
emoji = URI.
|
163
|
+
emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
|
148
164
|
Discordrb::API.request(
|
149
165
|
:channels_cid_messages_mid_reactions_emoji_me,
|
150
166
|
channel_id,
|
@@ -157,9 +173,9 @@ module Discordrb::API::Channel
|
|
157
173
|
end
|
158
174
|
|
159
175
|
# Delete this client's own reaction on a message
|
160
|
-
# https://
|
176
|
+
# https://discord.com/developers/docs/resources/channel#delete-own-reaction
|
161
177
|
def delete_own_reaction(token, channel_id, message_id, emoji)
|
162
|
-
emoji = URI.
|
178
|
+
emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
|
163
179
|
Discordrb::API.request(
|
164
180
|
:channels_cid_messages_mid_reactions_emoji_me,
|
165
181
|
channel_id,
|
@@ -170,9 +186,9 @@ module Discordrb::API::Channel
|
|
170
186
|
end
|
171
187
|
|
172
188
|
# Delete another client's reaction on a message
|
173
|
-
# https://
|
189
|
+
# https://discord.com/developers/docs/resources/channel#delete-user-reaction
|
174
190
|
def delete_user_reaction(token, channel_id, message_id, emoji, user_id)
|
175
|
-
emoji = URI.
|
191
|
+
emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
|
176
192
|
Discordrb::API.request(
|
177
193
|
:channels_cid_messages_mid_reactions_emoji_uid,
|
178
194
|
channel_id,
|
@@ -183,20 +199,21 @@ module Discordrb::API::Channel
|
|
183
199
|
end
|
184
200
|
|
185
201
|
# Get a list of clients who reacted with a specific reaction on a message
|
186
|
-
# https://
|
187
|
-
def get_reactions(token, channel_id, message_id, emoji)
|
188
|
-
emoji = URI.
|
202
|
+
# https://discord.com/developers/docs/resources/channel#get-reactions
|
203
|
+
def get_reactions(token, channel_id, message_id, emoji, before_id, after_id, limit = 100)
|
204
|
+
emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
|
205
|
+
query_string = URI.encode_www_form({ limit: limit || 100, before: before_id, after: after_id }.compact)
|
189
206
|
Discordrb::API.request(
|
190
207
|
:channels_cid_messages_mid_reactions_emoji,
|
191
208
|
channel_id,
|
192
209
|
:get,
|
193
|
-
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}",
|
210
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}?#{query_string}",
|
194
211
|
Authorization: token
|
195
212
|
)
|
196
213
|
end
|
197
214
|
|
198
215
|
# Deletes all reactions on a message from all clients
|
199
|
-
# https://
|
216
|
+
# https://discord.com/developers/docs/resources/channel#delete-all-reactions
|
200
217
|
def delete_all_reactions(token, channel_id, message_id)
|
201
218
|
Discordrb::API.request(
|
202
219
|
:channels_cid_messages_mid_reactions,
|
@@ -207,8 +224,22 @@ module Discordrb::API::Channel
|
|
207
224
|
)
|
208
225
|
end
|
209
226
|
|
227
|
+
# Deletes all the reactions for a given emoji on a message
|
228
|
+
# https://discord.com/developers/docs/resources/channel#delete-all-reactions-for-emoji
|
229
|
+
def delete_all_emoji_reactions(token, channel_id, message_id, emoji)
|
230
|
+
emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
|
231
|
+
|
232
|
+
Discordrb::API.request(
|
233
|
+
:channels_cid_messages_mid_reactions_emoji,
|
234
|
+
channel_id,
|
235
|
+
:delete,
|
236
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}",
|
237
|
+
Authorization: token
|
238
|
+
)
|
239
|
+
end
|
240
|
+
|
210
241
|
# Update a channels permission for a role or member
|
211
|
-
# https://
|
242
|
+
# https://discord.com/developers/docs/resources/channel#edit-channel-permissions
|
212
243
|
def update_permission(token, channel_id, overwrite_id, allow, deny, type, reason = nil)
|
213
244
|
Discordrb::API.request(
|
214
245
|
:channels_cid_permissions_oid,
|
@@ -223,7 +254,7 @@ module Discordrb::API::Channel
|
|
223
254
|
end
|
224
255
|
|
225
256
|
# Get a channel's invite list
|
226
|
-
# https://
|
257
|
+
# https://discord.com/developers/docs/resources/channel#get-channel-invites
|
227
258
|
def invites(token, channel_id)
|
228
259
|
Discordrb::API.request(
|
229
260
|
:channels_cid_invites,
|
@@ -235,7 +266,7 @@ module Discordrb::API::Channel
|
|
235
266
|
end
|
236
267
|
|
237
268
|
# Create an instant invite from a server or a channel id
|
238
|
-
# https://
|
269
|
+
# https://discord.com/developers/docs/resources/channel#create-channel-invite
|
239
270
|
def create_invite(token, channel_id, max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil)
|
240
271
|
Discordrb::API.request(
|
241
272
|
:channels_cid_invites,
|
@@ -250,7 +281,7 @@ module Discordrb::API::Channel
|
|
250
281
|
end
|
251
282
|
|
252
283
|
# Delete channel permission
|
253
|
-
# https://
|
284
|
+
# https://discord.com/developers/docs/resources/channel#delete-channel-permission
|
254
285
|
def delete_permission(token, channel_id, overwrite_id, reason = nil)
|
255
286
|
Discordrb::API.request(
|
256
287
|
:channels_cid_permissions_oid,
|
@@ -263,7 +294,7 @@ module Discordrb::API::Channel
|
|
263
294
|
end
|
264
295
|
|
265
296
|
# Start typing (needs to be resent every 5 seconds to keep up the typing)
|
266
|
-
# https://
|
297
|
+
# https://discord.com/developers/docs/resources/channel#trigger-typing-indicator
|
267
298
|
def start_typing(token, channel_id)
|
268
299
|
Discordrb::API.request(
|
269
300
|
:channels_cid_typing,
|
@@ -276,7 +307,7 @@ module Discordrb::API::Channel
|
|
276
307
|
end
|
277
308
|
|
278
309
|
# Get a list of pinned messages in a channel
|
279
|
-
# https://
|
310
|
+
# https://discord.com/developers/docs/resources/channel#get-pinned-messages
|
280
311
|
def pinned_messages(token, channel_id)
|
281
312
|
Discordrb::API.request(
|
282
313
|
:channels_cid_pins,
|
@@ -288,31 +319,35 @@ module Discordrb::API::Channel
|
|
288
319
|
end
|
289
320
|
|
290
321
|
# Pin a message
|
291
|
-
# https://
|
292
|
-
def pin_message(token, channel_id, message_id)
|
322
|
+
# https://discord.com/developers/docs/resources/channel#add-pinned-channel-message
|
323
|
+
def pin_message(token, channel_id, message_id, reason = nil)
|
293
324
|
Discordrb::API.request(
|
294
325
|
:channels_cid_pins_mid,
|
295
326
|
channel_id,
|
296
327
|
:put,
|
297
328
|
"#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{message_id}",
|
298
329
|
nil,
|
299
|
-
Authorization: token
|
330
|
+
Authorization: token,
|
331
|
+
'X-Audit-Log-Reason': reason
|
300
332
|
)
|
301
333
|
end
|
302
334
|
|
303
335
|
# Unpin a message
|
304
|
-
# https://
|
305
|
-
def unpin_message(token, channel_id, message_id)
|
336
|
+
# https://discord.com/developers/docs/resources/channel#delete-pinned-channel-message
|
337
|
+
def unpin_message(token, channel_id, message_id, reason = nil)
|
306
338
|
Discordrb::API.request(
|
307
339
|
:channels_cid_pins_mid,
|
308
340
|
channel_id,
|
309
341
|
:delete,
|
310
342
|
"#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{message_id}",
|
311
|
-
Authorization: token
|
343
|
+
Authorization: token,
|
344
|
+
'X-Audit-Log-Reason': reason
|
312
345
|
)
|
313
346
|
end
|
314
347
|
|
315
348
|
# Create an empty group channel.
|
349
|
+
# @deprecated Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.
|
350
|
+
# https://discord.com/developers/docs/resources/user#create-group-dm
|
316
351
|
def create_empty_group(token, bot_user_id)
|
317
352
|
Discordrb::API.request(
|
318
353
|
:users_uid_channels,
|
@@ -326,6 +361,8 @@ module Discordrb::API::Channel
|
|
326
361
|
end
|
327
362
|
|
328
363
|
# Create a group channel.
|
364
|
+
# @deprecated Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.
|
365
|
+
# https://discord.com/developers/docs/resources/channel#group-dm-add-recipient
|
329
366
|
def create_group(token, pm_channel_id, user_id)
|
330
367
|
Discordrb::API.request(
|
331
368
|
:channels_cid_recipients_uid,
|
@@ -345,6 +382,8 @@ module Discordrb::API::Channel
|
|
345
382
|
end
|
346
383
|
|
347
384
|
# Add a user to a group channel.
|
385
|
+
# @deprecated Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.
|
386
|
+
# https://discord.com/developers/docs/resources/channel#group-dm-add-recipient
|
348
387
|
def add_group_user(token, group_channel_id, user_id)
|
349
388
|
Discordrb::API.request(
|
350
389
|
:channels_cid_recipients_uid,
|
@@ -358,6 +397,8 @@ module Discordrb::API::Channel
|
|
358
397
|
end
|
359
398
|
|
360
399
|
# Remove a user from a group channel.
|
400
|
+
# @deprecated Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.
|
401
|
+
# https://discord.com/developers/docs/resources/channel#group-dm-remove-recipient
|
361
402
|
def remove_group_user(token, group_channel_id, user_id)
|
362
403
|
Discordrb::API.request(
|
363
404
|
:channels_cid_recipients_uid,
|
@@ -370,6 +411,8 @@ module Discordrb::API::Channel
|
|
370
411
|
end
|
371
412
|
|
372
413
|
# Leave a group channel.
|
414
|
+
# @deprecated Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.
|
415
|
+
# https://discord.com/developers/docs/resources/channel#deleteclose-channel
|
373
416
|
def leave_group(token, group_channel_id)
|
374
417
|
Discordrb::API.request(
|
375
418
|
:channels_cid,
|
@@ -382,7 +425,7 @@ module Discordrb::API::Channel
|
|
382
425
|
end
|
383
426
|
|
384
427
|
# Create a webhook
|
385
|
-
# https://
|
428
|
+
# https://discord.com/developers/docs/resources/webhook#create-webhook
|
386
429
|
def create_webhook(token, channel_id, name, avatar = nil, reason = nil)
|
387
430
|
Discordrb::API.request(
|
388
431
|
:channels_cid_webhooks,
|
@@ -397,7 +440,7 @@ module Discordrb::API::Channel
|
|
397
440
|
end
|
398
441
|
|
399
442
|
# Get channel webhooks
|
400
|
-
# https://
|
443
|
+
# https://discord.com/developers/docs/resources/webhook#get-channel-webhooks
|
401
444
|
def webhooks(token, channel_id)
|
402
445
|
Discordrb::API.request(
|
403
446
|
:channels_cid_webhooks,
|
@@ -407,4 +450,150 @@ module Discordrb::API::Channel
|
|
407
450
|
Authorization: token
|
408
451
|
)
|
409
452
|
end
|
453
|
+
|
454
|
+
# Start a thread based off a channel message.
|
455
|
+
# https://discord.com/developers/docs/resources/channel#start-thread-with-message
|
456
|
+
def start_thread_with_message(token, channel_id, message_id, name, auto_archive_duration)
|
457
|
+
Discordrb::API.request(
|
458
|
+
:channels_cid_messages_mid_threads,
|
459
|
+
channel_id,
|
460
|
+
:post,
|
461
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/threads",
|
462
|
+
{ name: name, auto_archive_duration: auto_archive_duration }.to_json,
|
463
|
+
Authorization: token,
|
464
|
+
content_type: :json
|
465
|
+
)
|
466
|
+
end
|
467
|
+
|
468
|
+
# Start a thread without an associated message.
|
469
|
+
# https://discord.com/developers/docs/resources/channel#start-thread-without-message
|
470
|
+
def start_thread_without_message(token, channel_id, name, auto_archive_duration, type = 11)
|
471
|
+
Discordrb::API.request(
|
472
|
+
:channels_cid_threads,
|
473
|
+
channel_id,
|
474
|
+
:post,
|
475
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/threads",
|
476
|
+
{ name: name, auto_archive_duration: auto_archive_duration, type: type },
|
477
|
+
Authorization: token,
|
478
|
+
content_type: :json
|
479
|
+
)
|
480
|
+
end
|
481
|
+
|
482
|
+
# Add the current user to a thread.
|
483
|
+
# https://discord.com/developers/docs/resources/channel#join-thread
|
484
|
+
def join_thread(token, channel_id)
|
485
|
+
Discordrb::API.request(
|
486
|
+
:channels_cid_thread_members_me,
|
487
|
+
channel_id,
|
488
|
+
:put,
|
489
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/thread-members/@me",
|
490
|
+
nil,
|
491
|
+
Authorization: token
|
492
|
+
)
|
493
|
+
end
|
494
|
+
|
495
|
+
# Add a user to a thread.
|
496
|
+
# https://discord.com/developers/docs/resources/channel#add-thread-member
|
497
|
+
def add_thread_member(token, channel_id, user_id)
|
498
|
+
Discordrb::API.request(
|
499
|
+
:channels_cid_thread_members_uid,
|
500
|
+
channel_id,
|
501
|
+
:put,
|
502
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
|
503
|
+
nil,
|
504
|
+
Authorization: token
|
505
|
+
)
|
506
|
+
end
|
507
|
+
|
508
|
+
# Remove the current user from a thread.
|
509
|
+
# https://discord.com/developers/docs/resources/channel#leave-thread
|
510
|
+
def leave_thread(token, channel_id)
|
511
|
+
Discordrb::API.request(
|
512
|
+
:channels_cid_thread_members_me,
|
513
|
+
channel_id,
|
514
|
+
:delete,
|
515
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
|
516
|
+
Authorization: token
|
517
|
+
)
|
518
|
+
end
|
519
|
+
|
520
|
+
# Remove a user from a thread.
|
521
|
+
# https://discord.com/developers/docs/resources/channel#remove-thread-member
|
522
|
+
def remove_thread_member(token, channel_id, user_id)
|
523
|
+
Discordrb::API.request(
|
524
|
+
:channels_cid_thread_members_uid,
|
525
|
+
channel_id,
|
526
|
+
:delete,
|
527
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
|
528
|
+
Authorization: token
|
529
|
+
)
|
530
|
+
end
|
531
|
+
|
532
|
+
# Get the members of a thread.
|
533
|
+
# https://discord.com/developers/docs/resources/channel#list-thread-members
|
534
|
+
def list_thread_members(token, channel_id, before, limit)
|
535
|
+
query = URI.encode_www_form({ before: before, limit: limit }.compact)
|
536
|
+
|
537
|
+
Discordrb::API.request(
|
538
|
+
:channels_cid_thread_members,
|
539
|
+
channel_id,
|
540
|
+
:get,
|
541
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/thread-members?#{query}",
|
542
|
+
Authorization: token
|
543
|
+
)
|
544
|
+
end
|
545
|
+
|
546
|
+
# List active threads
|
547
|
+
# https://discord.com/developers/docs/resources/channel#list-active-threads
|
548
|
+
def list_active_threads(token, channel_id)
|
549
|
+
Discordrb::API.request(
|
550
|
+
:channels_cid_threads_active,
|
551
|
+
channel_id,
|
552
|
+
:get,
|
553
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/threads/active",
|
554
|
+
Authorization: token
|
555
|
+
)
|
556
|
+
end
|
557
|
+
|
558
|
+
# List public archived threads.
|
559
|
+
# https://discord.com/developers/docs/resources/channel#list-public-archived-threads
|
560
|
+
def list_public_archived_threads(token, channel_id, before = nil, limit = nil)
|
561
|
+
query = URI.encode_www_form({ before: before, limit: limit }.compact)
|
562
|
+
|
563
|
+
Discordrb::API.request(
|
564
|
+
:channels_cid_threads_archived_public,
|
565
|
+
channel_id,
|
566
|
+
:get,
|
567
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/threads/archived/public?#{query}",
|
568
|
+
Authorization: token
|
569
|
+
)
|
570
|
+
end
|
571
|
+
|
572
|
+
# List private archived threads.
|
573
|
+
# https://discord.com/developers/docs/resources/channel#list-private-archived-threads
|
574
|
+
def list_private_archived_threads(token, channel_id, before = nil, limit = nil)
|
575
|
+
query = URI.encode_www_form({ before: before, limit: limit }.compact)
|
576
|
+
|
577
|
+
Discordrb::API.request(
|
578
|
+
:channels_cid_threads_archived_private,
|
579
|
+
channel_id,
|
580
|
+
:get,
|
581
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/threads/archived/private?#{query}",
|
582
|
+
Authorization: token
|
583
|
+
)
|
584
|
+
end
|
585
|
+
|
586
|
+
# List joined private archived threads.
|
587
|
+
# https://discord.com/developers/docs/resources/channel#list-joined-private-archived-threads
|
588
|
+
def list_joined_private_archived_threads(token, channel_id, before = nil, limit = nil)
|
589
|
+
query = URI.encode_www_form({ before: before, limit: limit }.compact)
|
590
|
+
|
591
|
+
Discordrb::API.request(
|
592
|
+
:channels_cid_users_me_threads_archived_private,
|
593
|
+
channel_id,
|
594
|
+
:get,
|
595
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/users/@me/threads/archived/private?#{query}",
|
596
|
+
Authorization: token
|
597
|
+
)
|
598
|
+
end
|
410
599
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# API calls for interactions.
|
4
|
+
module Discordrb::API::Interaction
|
5
|
+
module_function
|
6
|
+
|
7
|
+
# Respond to an interaction.
|
8
|
+
# https://discord.com/developers/docs/interactions/slash-commands#create-interaction-response
|
9
|
+
def create_interaction_response(interaction_token, interaction_id, type, content = nil, tts = nil, embeds = nil, allowed_mentions = nil, flags = nil, components = nil)
|
10
|
+
data = { tts: tts, content: content, embeds: embeds, allowed_mentions: allowed_mentions, flags: flags, components: components }.compact
|
11
|
+
|
12
|
+
Discordrb::API.request(
|
13
|
+
:interactions_iid_token_callback,
|
14
|
+
interaction_id,
|
15
|
+
:post,
|
16
|
+
"#{Discordrb::API.api_base}/interactions/#{interaction_id}/#{interaction_token}/callback",
|
17
|
+
{ type: type, data: data }.to_json,
|
18
|
+
content_type: :json
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Create a response that results in a modal.
|
23
|
+
# https://discord.com/developers/docs/interactions/slash-commands#create-interaction-response
|
24
|
+
def create_interaction_modal_response(interaction_token, interaction_id, custom_id, title, components)
|
25
|
+
data = { custom_id: custom_id, title: title, components: components.to_a }.compact
|
26
|
+
|
27
|
+
Discordrb::API.request(
|
28
|
+
:interactions_iid_token_callback,
|
29
|
+
interaction_id,
|
30
|
+
:post,
|
31
|
+
"#{Discordrb::API.api_base}/interactions/#{interaction_id}/#{interaction_token}/callback",
|
32
|
+
{ type: 9, data: data }.to_json,
|
33
|
+
content_type: :json
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Get the original response to an interaction.
|
38
|
+
# https://discord.com/developers/docs/interactions/slash-commands#get-original-interaction-response
|
39
|
+
def get_original_interaction_response(interaction_token, application_id)
|
40
|
+
Discordrb::API::Webhook.token_get_message(interaction_token, application_id, '@original')
|
41
|
+
end
|
42
|
+
|
43
|
+
# Edit the original response to an interaction.
|
44
|
+
# 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)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Delete the original response to an interaction.
|
50
|
+
# https://discord.com/developers/docs/interactions/slash-commands#delete-original-interaction-response
|
51
|
+
def delete_original_interaction_response(interaction_token, application_id)
|
52
|
+
Discordrb::API::Webhook.token_delete_message(interaction_token, application_id, '@original')
|
53
|
+
end
|
54
|
+
end
|
data/lib/discordrb/api/invite.rb
CHANGED
@@ -5,19 +5,19 @@ module Discordrb::API::Invite
|
|
5
5
|
module_function
|
6
6
|
|
7
7
|
# Resolve an invite
|
8
|
-
# https://
|
8
|
+
# https://discord.com/developers/docs/resources/invite#get-invite
|
9
9
|
def resolve(token, invite_code, counts = true)
|
10
10
|
Discordrb::API.request(
|
11
11
|
:invite_code,
|
12
12
|
nil,
|
13
13
|
:get,
|
14
|
-
"#{Discordrb::API.api_base}/
|
14
|
+
"#{Discordrb::API.api_base}/invites/#{invite_code}#{counts ? '?with_counts=true' : ''}",
|
15
15
|
Authorization: token
|
16
16
|
)
|
17
17
|
end
|
18
18
|
|
19
19
|
# Delete an invite by code
|
20
|
-
# https://
|
20
|
+
# https://discord.com/developers/docs/resources/invite#delete-invite
|
21
21
|
def delete(token, code, reason = nil)
|
22
22
|
Discordrb::API.request(
|
23
23
|
:invites_code,
|
@@ -30,13 +30,13 @@ module Discordrb::API::Invite
|
|
30
30
|
end
|
31
31
|
|
32
32
|
# Join a server using an invite
|
33
|
-
# https://
|
33
|
+
# https://discord.com/developers/docs/resources/invite#accept-invite
|
34
34
|
def accept(token, invite_code)
|
35
35
|
Discordrb::API.request(
|
36
36
|
:invite_code,
|
37
37
|
nil,
|
38
38
|
:post,
|
39
|
-
"#{Discordrb::API.api_base}/
|
39
|
+
"#{Discordrb::API.api_base}/invites/#{invite_code}",
|
40
40
|
nil,
|
41
41
|
Authorization: token
|
42
42
|
)
|