discordrb 3.3.0 → 3.4.3
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 +126 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +25 -0
- data/.github/pull_request_template.md +37 -0
- data/.rubocop.yml +34 -37
- data/.travis.yml +5 -6
- data/CHANGELOG.md +504 -347
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +61 -79
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/discordrb-webhooks.gemspec +6 -6
- data/discordrb.gemspec +18 -18
- data/lib/discordrb/allowed_mentions.rb +36 -0
- data/lib/discordrb/api/channel.rb +62 -39
- data/lib/discordrb/api/invite.rb +3 -3
- data/lib/discordrb/api/server.rb +57 -50
- data/lib/discordrb/api/user.rb +9 -8
- data/lib/discordrb/api/webhook.rb +6 -6
- data/lib/discordrb/api.rb +40 -15
- data/lib/discordrb/await.rb +0 -1
- data/lib/discordrb/bot.rb +175 -73
- data/lib/discordrb/cache.rb +4 -2
- data/lib/discordrb/colour_rgb.rb +43 -0
- data/lib/discordrb/commands/command_bot.rb +30 -9
- data/lib/discordrb/commands/container.rb +20 -23
- data/lib/discordrb/commands/parser.rb +18 -18
- data/lib/discordrb/commands/rate_limiter.rb +3 -2
- data/lib/discordrb/container.rb +77 -17
- data/lib/discordrb/data/activity.rb +271 -0
- data/lib/discordrb/data/application.rb +50 -0
- data/lib/discordrb/data/attachment.rb +56 -0
- data/lib/discordrb/data/audit_logs.rb +345 -0
- data/lib/discordrb/data/channel.rb +849 -0
- data/lib/discordrb/data/embed.rb +251 -0
- data/lib/discordrb/data/emoji.rb +82 -0
- data/lib/discordrb/data/integration.rb +83 -0
- data/lib/discordrb/data/invite.rb +137 -0
- data/lib/discordrb/data/member.rb +297 -0
- data/lib/discordrb/data/message.rb +334 -0
- data/lib/discordrb/data/overwrite.rb +102 -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 +191 -0
- data/lib/discordrb/data/server.rb +1002 -0
- data/lib/discordrb/data/user.rb +204 -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 +145 -0
- data/lib/discordrb/data.rb +25 -4180
- data/lib/discordrb/errors.rb +2 -1
- data/lib/discordrb/events/bans.rb +7 -5
- data/lib/discordrb/events/channels.rb +2 -0
- data/lib/discordrb/events/guilds.rb +16 -9
- data/lib/discordrb/events/invites.rb +125 -0
- data/lib/discordrb/events/members.rb +6 -2
- data/lib/discordrb/events/message.rb +69 -27
- data/lib/discordrb/events/presence.rb +14 -4
- data/lib/discordrb/events/raw.rb +1 -3
- data/lib/discordrb/events/reactions.rb +49 -3
- 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 +72 -57
- 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 +103 -8
- data/lib/discordrb/version.rb +1 -1
- data/lib/discordrb/voice/encoder.rb +16 -7
- data/lib/discordrb/voice/network.rb +84 -43
- data/lib/discordrb/voice/sodium.rb +96 -0
- data/lib/discordrb/voice/voice_bot.rb +34 -26
- data/lib/discordrb.rb +73 -0
- metadata +98 -60
- /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,7 +47,7 @@ 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
52
|
Discordrb::API.request(
|
53
53
|
:channels_cid_messages,
|
@@ -59,7 +59,7 @@ module Discordrb::API::Channel
|
|
59
59
|
end
|
60
60
|
|
61
61
|
# Get a single message from a channel's history by id
|
62
|
-
# https://
|
62
|
+
# https://discord.com/developers/docs/resources/channel#get-channel-message
|
63
63
|
def message(token, channel_id, message_id)
|
64
64
|
Discordrb::API.request(
|
65
65
|
:channels_cid_messages_mid,
|
@@ -72,24 +72,37 @@ module Discordrb::API::Channel
|
|
72
72
|
|
73
73
|
# Send a message to a channel
|
74
74
|
# https://discordapp.com/developers/docs/resources/channel#create-message
|
75
|
-
|
75
|
+
# @param attachments [Array<File>, nil] Attachments to use with `attachment://` in embeds. See
|
76
|
+
# https://discord.com/developers/docs/resources/channel#create-message-using-attachments-within-embeds
|
77
|
+
def create_message(token, channel_id, message, tts = false, embed = nil, nonce = nil, attachments = nil, allowed_mentions = nil, message_reference = nil)
|
78
|
+
body = { content: message, tts: tts, embed: embed, nonce: nonce, allowed_mentions: allowed_mentions, message_reference: message_reference }
|
79
|
+
body = if attachments
|
80
|
+
files = [*0...attachments.size].zip(attachments).to_h
|
81
|
+
{ **files, payload_json: body.to_json }
|
82
|
+
else
|
83
|
+
body.to_json
|
84
|
+
end
|
85
|
+
|
86
|
+
headers = { Authorization: token }
|
87
|
+
headers[:content_type] = :json unless attachments
|
88
|
+
|
76
89
|
Discordrb::API.request(
|
77
90
|
:channels_cid_messages_mid,
|
78
91
|
channel_id,
|
79
92
|
:post,
|
80
93
|
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages",
|
81
|
-
|
82
|
-
|
83
|
-
content_type: :json
|
94
|
+
body,
|
95
|
+
**headers
|
84
96
|
)
|
85
97
|
rescue RestClient::BadRequest => e
|
86
98
|
parsed = JSON.parse(e.response.body)
|
87
|
-
raise Discordrb::Errors::MessageTooLong, "Message over the character limit (#{message.length} > 2000)" if parsed['content']
|
99
|
+
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.'
|
100
|
+
|
88
101
|
raise
|
89
102
|
end
|
90
103
|
|
91
104
|
# Send a file as a message to a channel
|
92
|
-
# https://
|
105
|
+
# https://discord.com/developers/docs/resources/channel#upload-file
|
93
106
|
def upload_file(token, channel_id, file, caption: nil, tts: false)
|
94
107
|
Discordrb::API.request(
|
95
108
|
:channels_cid_messages_mid,
|
@@ -102,7 +115,7 @@ module Discordrb::API::Channel
|
|
102
115
|
end
|
103
116
|
|
104
117
|
# Edit a message
|
105
|
-
# https://
|
118
|
+
# https://discord.com/developers/docs/resources/channel#edit-message
|
106
119
|
def edit_message(token, channel_id, message_id, message, mentions = [], embed = nil)
|
107
120
|
Discordrb::API.request(
|
108
121
|
:channels_cid_messages_mid,
|
@@ -117,19 +130,20 @@ module Discordrb::API::Channel
|
|
117
130
|
|
118
131
|
# Delete a message
|
119
132
|
# https://discordapp.com/developers/docs/resources/channel#delete-message
|
120
|
-
def delete_message(token, channel_id, message_id)
|
133
|
+
def delete_message(token, channel_id, message_id, reason = nil)
|
121
134
|
Discordrb::API.request(
|
122
135
|
:channels_cid_messages_mid,
|
123
136
|
channel_id,
|
124
137
|
:delete,
|
125
138
|
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}",
|
126
|
-
Authorization: token
|
139
|
+
Authorization: token,
|
140
|
+
'X-Audit-Log-Reason': reason
|
127
141
|
)
|
128
142
|
end
|
129
143
|
|
130
144
|
# Delete messages in bulk
|
131
145
|
# https://discordapp.com/developers/docs/resources/channel#bulk-delete-messages
|
132
|
-
def bulk_delete_messages(token, channel_id, messages = [])
|
146
|
+
def bulk_delete_messages(token, channel_id, messages = [], reason = nil)
|
133
147
|
Discordrb::API.request(
|
134
148
|
:channels_cid_messages_bulk_delete,
|
135
149
|
channel_id,
|
@@ -137,14 +151,15 @@ module Discordrb::API::Channel
|
|
137
151
|
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/bulk-delete",
|
138
152
|
{ messages: messages }.to_json,
|
139
153
|
Authorization: token,
|
140
|
-
content_type: :json
|
154
|
+
content_type: :json,
|
155
|
+
'X-Audit-Log-Reason': reason
|
141
156
|
)
|
142
157
|
end
|
143
158
|
|
144
159
|
# Create a reaction on a message using this client
|
145
|
-
# https://
|
160
|
+
# https://discord.com/developers/docs/resources/channel#create-reaction
|
146
161
|
def create_reaction(token, channel_id, message_id, emoji)
|
147
|
-
emoji = URI.
|
162
|
+
emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
|
148
163
|
Discordrb::API.request(
|
149
164
|
:channels_cid_messages_mid_reactions_emoji_me,
|
150
165
|
channel_id,
|
@@ -157,9 +172,9 @@ module Discordrb::API::Channel
|
|
157
172
|
end
|
158
173
|
|
159
174
|
# Delete this client's own reaction on a message
|
160
|
-
# https://
|
175
|
+
# https://discord.com/developers/docs/resources/channel#delete-own-reaction
|
161
176
|
def delete_own_reaction(token, channel_id, message_id, emoji)
|
162
|
-
emoji = URI.
|
177
|
+
emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
|
163
178
|
Discordrb::API.request(
|
164
179
|
:channels_cid_messages_mid_reactions_emoji_me,
|
165
180
|
channel_id,
|
@@ -170,9 +185,9 @@ module Discordrb::API::Channel
|
|
170
185
|
end
|
171
186
|
|
172
187
|
# Delete another client's reaction on a message
|
173
|
-
# https://
|
188
|
+
# https://discord.com/developers/docs/resources/channel#delete-user-reaction
|
174
189
|
def delete_user_reaction(token, channel_id, message_id, emoji, user_id)
|
175
|
-
emoji = URI.
|
190
|
+
emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
|
176
191
|
Discordrb::API.request(
|
177
192
|
:channels_cid_messages_mid_reactions_emoji_uid,
|
178
193
|
channel_id,
|
@@ -183,20 +198,21 @@ module Discordrb::API::Channel
|
|
183
198
|
end
|
184
199
|
|
185
200
|
# 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.
|
201
|
+
# https://discord.com/developers/docs/resources/channel#get-reactions
|
202
|
+
def get_reactions(token, channel_id, message_id, emoji, before_id, after_id, limit = 100)
|
203
|
+
emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
|
204
|
+
query_string = "limit=#{limit}#{"&before=#{before_id}" if before_id}#{"&after=#{after_id}" if after_id}"
|
189
205
|
Discordrb::API.request(
|
190
206
|
:channels_cid_messages_mid_reactions_emoji,
|
191
207
|
channel_id,
|
192
208
|
:get,
|
193
|
-
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}",
|
209
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}?#{query_string}",
|
194
210
|
Authorization: token
|
195
211
|
)
|
196
212
|
end
|
197
213
|
|
198
214
|
# Deletes all reactions on a message from all clients
|
199
|
-
# https://
|
215
|
+
# https://discord.com/developers/docs/resources/channel#delete-all-reactions
|
200
216
|
def delete_all_reactions(token, channel_id, message_id)
|
201
217
|
Discordrb::API.request(
|
202
218
|
:channels_cid_messages_mid_reactions,
|
@@ -208,7 +224,7 @@ module Discordrb::API::Channel
|
|
208
224
|
end
|
209
225
|
|
210
226
|
# Update a channels permission for a role or member
|
211
|
-
# https://
|
227
|
+
# https://discord.com/developers/docs/resources/channel#edit-channel-permissions
|
212
228
|
def update_permission(token, channel_id, overwrite_id, allow, deny, type, reason = nil)
|
213
229
|
Discordrb::API.request(
|
214
230
|
:channels_cid_permissions_oid,
|
@@ -223,7 +239,7 @@ module Discordrb::API::Channel
|
|
223
239
|
end
|
224
240
|
|
225
241
|
# Get a channel's invite list
|
226
|
-
# https://
|
242
|
+
# https://discord.com/developers/docs/resources/channel#get-channel-invites
|
227
243
|
def invites(token, channel_id)
|
228
244
|
Discordrb::API.request(
|
229
245
|
:channels_cid_invites,
|
@@ -235,7 +251,7 @@ module Discordrb::API::Channel
|
|
235
251
|
end
|
236
252
|
|
237
253
|
# Create an instant invite from a server or a channel id
|
238
|
-
# https://
|
254
|
+
# https://discord.com/developers/docs/resources/channel#create-channel-invite
|
239
255
|
def create_invite(token, channel_id, max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil)
|
240
256
|
Discordrb::API.request(
|
241
257
|
:channels_cid_invites,
|
@@ -250,7 +266,7 @@ module Discordrb::API::Channel
|
|
250
266
|
end
|
251
267
|
|
252
268
|
# Delete channel permission
|
253
|
-
# https://
|
269
|
+
# https://discord.com/developers/docs/resources/channel#delete-channel-permission
|
254
270
|
def delete_permission(token, channel_id, overwrite_id, reason = nil)
|
255
271
|
Discordrb::API.request(
|
256
272
|
:channels_cid_permissions_oid,
|
@@ -263,7 +279,7 @@ module Discordrb::API::Channel
|
|
263
279
|
end
|
264
280
|
|
265
281
|
# Start typing (needs to be resent every 5 seconds to keep up the typing)
|
266
|
-
# https://
|
282
|
+
# https://discord.com/developers/docs/resources/channel#trigger-typing-indicator
|
267
283
|
def start_typing(token, channel_id)
|
268
284
|
Discordrb::API.request(
|
269
285
|
:channels_cid_typing,
|
@@ -276,7 +292,7 @@ module Discordrb::API::Channel
|
|
276
292
|
end
|
277
293
|
|
278
294
|
# Get a list of pinned messages in a channel
|
279
|
-
# https://
|
295
|
+
# https://discord.com/developers/docs/resources/channel#get-pinned-messages
|
280
296
|
def pinned_messages(token, channel_id)
|
281
297
|
Discordrb::API.request(
|
282
298
|
:channels_cid_pins,
|
@@ -289,30 +305,33 @@ module Discordrb::API::Channel
|
|
289
305
|
|
290
306
|
# Pin a message
|
291
307
|
# https://discordapp.com/developers/docs/resources/channel#add-pinned-channel-message
|
292
|
-
def pin_message(token, channel_id, message_id)
|
308
|
+
def pin_message(token, channel_id, message_id, reason = nil)
|
293
309
|
Discordrb::API.request(
|
294
310
|
:channels_cid_pins_mid,
|
295
311
|
channel_id,
|
296
312
|
:put,
|
297
313
|
"#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{message_id}",
|
298
314
|
nil,
|
299
|
-
Authorization: token
|
315
|
+
Authorization: token,
|
316
|
+
'X-Audit-Log-Reason': reason
|
300
317
|
)
|
301
318
|
end
|
302
319
|
|
303
320
|
# Unpin a message
|
304
321
|
# https://discordapp.com/developers/docs/resources/channel#delete-pinned-channel-message
|
305
|
-
def unpin_message(token, channel_id, message_id)
|
322
|
+
def unpin_message(token, channel_id, message_id, reason = nil)
|
306
323
|
Discordrb::API.request(
|
307
324
|
:channels_cid_pins_mid,
|
308
325
|
channel_id,
|
309
326
|
:delete,
|
310
327
|
"#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{message_id}",
|
311
|
-
Authorization: token
|
328
|
+
Authorization: token,
|
329
|
+
'X-Audit-Log-Reason': reason
|
312
330
|
)
|
313
331
|
end
|
314
332
|
|
315
333
|
# Create an empty group channel.
|
334
|
+
# https://discord.com/developers/docs/resources/user#create-group-dm
|
316
335
|
def create_empty_group(token, bot_user_id)
|
317
336
|
Discordrb::API.request(
|
318
337
|
:users_uid_channels,
|
@@ -326,6 +345,7 @@ module Discordrb::API::Channel
|
|
326
345
|
end
|
327
346
|
|
328
347
|
# Create a group channel.
|
348
|
+
# https://discord.com/developers/docs/resources/channel#group-dm-add-recipient
|
329
349
|
def create_group(token, pm_channel_id, user_id)
|
330
350
|
Discordrb::API.request(
|
331
351
|
:channels_cid_recipients_uid,
|
@@ -345,6 +365,7 @@ module Discordrb::API::Channel
|
|
345
365
|
end
|
346
366
|
|
347
367
|
# Add a user to a group channel.
|
368
|
+
# https://discord.com/developers/docs/resources/channel#group-dm-add-recipient
|
348
369
|
def add_group_user(token, group_channel_id, user_id)
|
349
370
|
Discordrb::API.request(
|
350
371
|
:channels_cid_recipients_uid,
|
@@ -358,6 +379,7 @@ module Discordrb::API::Channel
|
|
358
379
|
end
|
359
380
|
|
360
381
|
# Remove a user from a group channel.
|
382
|
+
# https://discord.com/developers/docs/resources/channel#group-dm-remove-recipient
|
361
383
|
def remove_group_user(token, group_channel_id, user_id)
|
362
384
|
Discordrb::API.request(
|
363
385
|
:channels_cid_recipients_uid,
|
@@ -370,6 +392,7 @@ module Discordrb::API::Channel
|
|
370
392
|
end
|
371
393
|
|
372
394
|
# Leave a group channel.
|
395
|
+
# https://discord.com/developers/docs/resources/channel#deleteclose-channel
|
373
396
|
def leave_group(token, group_channel_id)
|
374
397
|
Discordrb::API.request(
|
375
398
|
:channels_cid,
|
@@ -382,7 +405,7 @@ module Discordrb::API::Channel
|
|
382
405
|
end
|
383
406
|
|
384
407
|
# Create a webhook
|
385
|
-
# https://
|
408
|
+
# https://discord.com/developers/docs/resources/webhook#create-webhook
|
386
409
|
def create_webhook(token, channel_id, name, avatar = nil, reason = nil)
|
387
410
|
Discordrb::API.request(
|
388
411
|
:channels_cid_webhooks,
|
@@ -397,7 +420,7 @@ module Discordrb::API::Channel
|
|
397
420
|
end
|
398
421
|
|
399
422
|
# Get channel webhooks
|
400
|
-
# https://
|
423
|
+
# https://discord.com/developers/docs/resources/webhook#get-channel-webhooks
|
401
424
|
def webhooks(token, channel_id)
|
402
425
|
Discordrb::API.request(
|
403
426
|
:channels_cid_webhooks,
|
data/lib/discordrb/api/invite.rb
CHANGED
@@ -5,7 +5,7 @@ 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,
|
@@ -17,7 +17,7 @@ module Discordrb::API::Invite
|
|
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,7 +30,7 @@ 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,
|