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