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
data/lib/discordrb/api/server.rb
CHANGED
@@ -5,7 +5,7 @@ module Discordrb::API::Server
|
|
5
5
|
module_function
|
6
6
|
|
7
7
|
# Create a server
|
8
|
-
# https://
|
8
|
+
# https://discord.com/developers/docs/resources/guild#create-guild
|
9
9
|
def create(token, name, region = :'eu-central')
|
10
10
|
Discordrb::API.request(
|
11
11
|
:guilds,
|
@@ -19,19 +19,19 @@ module Discordrb::API::Server
|
|
19
19
|
end
|
20
20
|
|
21
21
|
# Get a server's data
|
22
|
-
# https://
|
23
|
-
def resolve(token, server_id)
|
22
|
+
# https://discord.com/developers/docs/resources/guild#get-guild
|
23
|
+
def resolve(token, server_id, with_counts = nil)
|
24
24
|
Discordrb::API.request(
|
25
25
|
:guilds_sid,
|
26
26
|
server_id,
|
27
27
|
:get,
|
28
|
-
"#{Discordrb::API.api_base}/guilds/#{server_id}",
|
28
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}#{'?with_counts=true' if with_counts}",
|
29
29
|
Authorization: token
|
30
30
|
)
|
31
31
|
end
|
32
32
|
|
33
33
|
# Update a server
|
34
|
-
# https://
|
34
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild
|
35
35
|
def update(token, server_id, name, region, icon, afk_channel_id, afk_timeout, splash, default_message_notifications, verification_level, explicit_content_filter, system_channel_id, reason = nil)
|
36
36
|
Discordrb::API.request(
|
37
37
|
:guilds_sid,
|
@@ -46,6 +46,7 @@ module Discordrb::API::Server
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# Transfer server ownership
|
49
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild
|
49
50
|
def transfer_ownership(token, server_id, user_id, reason = nil)
|
50
51
|
Discordrb::API.request(
|
51
52
|
:guilds_sid,
|
@@ -60,7 +61,7 @@ module Discordrb::API::Server
|
|
60
61
|
end
|
61
62
|
|
62
63
|
# Delete a server
|
63
|
-
# https://
|
64
|
+
# https://discord.com/developers/docs/resources/guild#delete-guild
|
64
65
|
def delete(token, server_id)
|
65
66
|
Discordrb::API.request(
|
66
67
|
:guilds_sid,
|
@@ -72,7 +73,7 @@ module Discordrb::API::Server
|
|
72
73
|
end
|
73
74
|
|
74
75
|
# Get a server's channels list
|
75
|
-
# https://
|
76
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-channels
|
76
77
|
def channels(token, server_id)
|
77
78
|
Discordrb::API.request(
|
78
79
|
:guilds_sid_channels,
|
@@ -84,14 +85,14 @@ module Discordrb::API::Server
|
|
84
85
|
end
|
85
86
|
|
86
87
|
# Create a channel
|
87
|
-
# https://
|
88
|
-
def create_channel(token, server_id, name, type, topic, bitrate, user_limit, permission_overwrites, parent_id, nsfw, rate_limit_per_user, reason = nil)
|
88
|
+
# https://discord.com/developers/docs/resources/guild#create-guild-channel
|
89
|
+
def create_channel(token, server_id, name, type, topic, bitrate, user_limit, permission_overwrites, parent_id, nsfw, rate_limit_per_user, position, reason = nil)
|
89
90
|
Discordrb::API.request(
|
90
91
|
:guilds_sid_channels,
|
91
92
|
server_id,
|
92
93
|
:post,
|
93
94
|
"#{Discordrb::API.api_base}/guilds/#{server_id}/channels",
|
94
|
-
{ name: name, type: type, topic: topic, bitrate: bitrate, user_limit: user_limit, permission_overwrites: permission_overwrites, parent_id: parent_id, nsfw: nsfw, rate_limit_per_user: rate_limit_per_user }.to_json,
|
95
|
+
{ name: name, type: type, topic: topic, bitrate: bitrate, user_limit: user_limit, permission_overwrites: permission_overwrites, parent_id: parent_id, nsfw: nsfw, rate_limit_per_user: rate_limit_per_user, position: position }.to_json,
|
95
96
|
Authorization: token,
|
96
97
|
content_type: :json,
|
97
98
|
'X-Audit-Log-Reason': reason
|
@@ -99,7 +100,7 @@ module Discordrb::API::Server
|
|
99
100
|
end
|
100
101
|
|
101
102
|
# Update a channels position
|
102
|
-
# https://
|
103
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild-channel-positions
|
103
104
|
def update_channel_positions(token, server_id, positions)
|
104
105
|
Discordrb::API.request(
|
105
106
|
:guilds_sid_channels,
|
@@ -113,7 +114,7 @@ module Discordrb::API::Server
|
|
113
114
|
end
|
114
115
|
|
115
116
|
# Get a member's data
|
116
|
-
# https://
|
117
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-member
|
117
118
|
def resolve_member(token, server_id, user_id)
|
118
119
|
Discordrb::API.request(
|
119
120
|
:guilds_sid_members_uid,
|
@@ -125,7 +126,7 @@ module Discordrb::API::Server
|
|
125
126
|
end
|
126
127
|
|
127
128
|
# Gets members from the server
|
128
|
-
# https://
|
129
|
+
# https://discord.com/developers/docs/resources/guild#list-guild-members
|
129
130
|
def resolve_members(token, server_id, limit, after = nil)
|
130
131
|
Discordrb::API.request(
|
131
132
|
:guilds_sid_members,
|
@@ -137,7 +138,7 @@ module Discordrb::API::Server
|
|
137
138
|
end
|
138
139
|
|
139
140
|
# Update a user properties
|
140
|
-
# https://
|
141
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild-member
|
141
142
|
def update_member(token, server_id, user_id, nick: nil, roles: nil, mute: nil, deaf: nil, channel_id: nil, reason: nil)
|
142
143
|
Discordrb::API.request(
|
143
144
|
:guilds_sid_members_uid,
|
@@ -149,7 +150,7 @@ module Discordrb::API::Server
|
|
149
150
|
mute: mute,
|
150
151
|
deaf: deaf,
|
151
152
|
channel_id: channel_id
|
152
|
-
}.
|
153
|
+
}.compact.to_json,
|
153
154
|
Authorization: token,
|
154
155
|
content_type: :json,
|
155
156
|
'X-Audit-Log-Reason': reason
|
@@ -157,7 +158,7 @@ module Discordrb::API::Server
|
|
157
158
|
end
|
158
159
|
|
159
160
|
# Remove user from server
|
160
|
-
# https://
|
161
|
+
# https://discord.com/developers/docs/resources/guild#remove-guild-member
|
161
162
|
def remove_member(token, server_id, user_id, reason = nil)
|
162
163
|
Discordrb::API.request(
|
163
164
|
:guilds_sid_members_uid,
|
@@ -171,7 +172,7 @@ module Discordrb::API::Server
|
|
171
172
|
end
|
172
173
|
|
173
174
|
# Get a server's banned users
|
174
|
-
# https://
|
175
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-bans
|
175
176
|
def bans(token, server_id)
|
176
177
|
Discordrb::API.request(
|
177
178
|
:guilds_sid_bans,
|
@@ -183,9 +184,9 @@ module Discordrb::API::Server
|
|
183
184
|
end
|
184
185
|
|
185
186
|
# Ban a user from a server and delete their messages from the last message_days days
|
186
|
-
# https://
|
187
|
+
# https://discord.com/developers/docs/resources/guild#create-guild-ban
|
187
188
|
def ban_user(token, server_id, user_id, message_days, reason = nil)
|
188
|
-
reason = URI.
|
189
|
+
reason = URI.encode_www_form_component(reason) if reason
|
189
190
|
Discordrb::API.request(
|
190
191
|
:guilds_sid_bans_uid,
|
191
192
|
server_id,
|
@@ -197,7 +198,7 @@ module Discordrb::API::Server
|
|
197
198
|
end
|
198
199
|
|
199
200
|
# Unban a user from a server
|
200
|
-
# https://
|
201
|
+
# https://discord.com/developers/docs/resources/guild#remove-guild-ban
|
201
202
|
def unban_user(token, server_id, user_id, reason = nil)
|
202
203
|
Discordrb::API.request(
|
203
204
|
:guilds_sid_bans_uid,
|
@@ -210,7 +211,7 @@ module Discordrb::API::Server
|
|
210
211
|
end
|
211
212
|
|
212
213
|
# Get server roles
|
213
|
-
# https://
|
214
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-roles
|
214
215
|
def roles(token, server_id)
|
215
216
|
Discordrb::API.request(
|
216
217
|
:guilds_sid_roles,
|
@@ -225,7 +226,7 @@ module Discordrb::API::Server
|
|
225
226
|
# Permissions are the Discord defaults; allowed: invite creation, reading/sending messages,
|
226
227
|
# sending TTS messages, embedding links, sending files, reading the history, mentioning everybody,
|
227
228
|
# connecting to voice, speaking and voice activity (push-to-talk isn't mandatory)
|
228
|
-
# https://
|
229
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-roles
|
229
230
|
def create_role(token, server_id, name, colour, hoist, mentionable, packed_permissions, reason = nil)
|
230
231
|
Discordrb::API.request(
|
231
232
|
:guilds_sid_roles,
|
@@ -243,7 +244,7 @@ module Discordrb::API::Server
|
|
243
244
|
# Permissions are the Discord defaults; allowed: invite creation, reading/sending messages,
|
244
245
|
# sending TTS messages, embedding links, sending files, reading the history, mentioning everybody,
|
245
246
|
# connecting to voice, speaking and voice activity (push-to-talk isn't mandatory)
|
246
|
-
# https://
|
247
|
+
# https://discord.com/developers/docs/resources/guild#batch-modify-guild-role
|
247
248
|
def update_role(token, server_id, role_id, name, colour, hoist = false, mentionable = false, packed_permissions = 104_324_161, reason = nil)
|
248
249
|
Discordrb::API.request(
|
249
250
|
:guilds_sid_roles_rid,
|
@@ -258,7 +259,7 @@ module Discordrb::API::Server
|
|
258
259
|
end
|
259
260
|
|
260
261
|
# Update role positions
|
261
|
-
# https://
|
262
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild-role-positions
|
262
263
|
def update_role_positions(token, server_id, roles)
|
263
264
|
Discordrb::API.request(
|
264
265
|
:guilds_sid_roles,
|
@@ -272,7 +273,7 @@ module Discordrb::API::Server
|
|
272
273
|
end
|
273
274
|
|
274
275
|
# Delete a role
|
275
|
-
# https://
|
276
|
+
# https://discord.com/developers/docs/resources/guild#delete-guild-role
|
276
277
|
def delete_role(token, server_id, role_id, reason = nil)
|
277
278
|
Discordrb::API.request(
|
278
279
|
:guilds_sid_roles_rid,
|
@@ -285,7 +286,7 @@ module Discordrb::API::Server
|
|
285
286
|
end
|
286
287
|
|
287
288
|
# Adds a single role to a member
|
288
|
-
# https://
|
289
|
+
# https://discord.com/developers/docs/resources/guild#add-guild-member-role
|
289
290
|
def add_member_role(token, server_id, user_id, role_id, reason = nil)
|
290
291
|
Discordrb::API.request(
|
291
292
|
:guilds_sid_members_uid_roles_rid,
|
@@ -299,7 +300,7 @@ module Discordrb::API::Server
|
|
299
300
|
end
|
300
301
|
|
301
302
|
# Removes a single role from a member
|
302
|
-
# https://
|
303
|
+
# https://discord.com/developers/docs/resources/guild#remove-guild-member-role
|
303
304
|
def remove_member_role(token, server_id, user_id, role_id, reason = nil)
|
304
305
|
Discordrb::API.request(
|
305
306
|
:guilds_sid_members_uid_roles_rid,
|
@@ -312,7 +313,7 @@ module Discordrb::API::Server
|
|
312
313
|
end
|
313
314
|
|
314
315
|
# Get server prune count
|
315
|
-
# https://
|
316
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-prune-count
|
316
317
|
def prune_count(token, server_id, days)
|
317
318
|
Discordrb::API.request(
|
318
319
|
:guilds_sid_prune,
|
@@ -324,7 +325,7 @@ module Discordrb::API::Server
|
|
324
325
|
end
|
325
326
|
|
326
327
|
# Begin server prune
|
327
|
-
# https://
|
328
|
+
# https://discord.com/developers/docs/resources/guild#begin-guild-prune
|
328
329
|
def begin_prune(token, server_id, days, reason = nil)
|
329
330
|
Discordrb::API.request(
|
330
331
|
:guilds_sid_prune,
|
@@ -338,7 +339,7 @@ module Discordrb::API::Server
|
|
338
339
|
end
|
339
340
|
|
340
341
|
# Get invites from server
|
341
|
-
# https://
|
342
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-invites
|
342
343
|
def invites(token, server_id)
|
343
344
|
Discordrb::API.request(
|
344
345
|
:guilds_sid_invites,
|
@@ -350,19 +351,19 @@ module Discordrb::API::Server
|
|
350
351
|
end
|
351
352
|
|
352
353
|
# Gets a server's audit logs
|
353
|
-
# https://
|
354
|
-
def audit_logs(token, server_id, limit,
|
354
|
+
# https://discord.com/developers/docs/resources/audit-log#get-guild-audit-log
|
355
|
+
def audit_logs(token, server_id, limit, user_id = nil, action_type = nil, before = nil)
|
355
356
|
Discordrb::API.request(
|
356
357
|
:guilds_sid_auditlogs,
|
357
358
|
server_id,
|
358
359
|
:get,
|
359
|
-
"#{Discordrb::API.api_base}/guilds/#{server_id}/audit-logs?limit=#{limit}#{"&user_id=#{
|
360
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/audit-logs?limit=#{limit}#{"&user_id=#{user_id}" if user_id}#{"&action_type=#{action_type}" if action_type}#{"&before=#{before}" if before}",
|
360
361
|
Authorization: token
|
361
362
|
)
|
362
363
|
end
|
363
364
|
|
364
365
|
# Get server integrations
|
365
|
-
# https://
|
366
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-integrations
|
366
367
|
def integrations(token, server_id)
|
367
368
|
Discordrb::API.request(
|
368
369
|
:guilds_sid_integrations,
|
@@ -375,19 +376,20 @@ module Discordrb::API::Server
|
|
375
376
|
|
376
377
|
# Create a server integration
|
377
378
|
# https://discordapp.com/developers/docs/resources/guild#create-guild-integration
|
378
|
-
def create_integration(token, server_id, type, id)
|
379
|
+
def create_integration(token, server_id, type, id, reason = nil)
|
379
380
|
Discordrb::API.request(
|
380
381
|
:guilds_sid_integrations,
|
381
382
|
server_id,
|
382
383
|
:post,
|
383
384
|
"#{Discordrb::API.api_base}/guilds/#{server_id}/integrations",
|
384
385
|
{ type: type, id: id },
|
385
|
-
Authorization: token
|
386
|
+
Authorization: token,
|
387
|
+
'X-Audit-Log-Reason': reason
|
386
388
|
)
|
387
389
|
end
|
388
390
|
|
389
391
|
# Update integration from server
|
390
|
-
# https://
|
392
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild-integration
|
391
393
|
def update_integration(token, server_id, integration_id, expire_behavior, expire_grace_period, enable_emoticons)
|
392
394
|
Discordrb::API.request(
|
393
395
|
:guilds_sid_integrations_iid,
|
@@ -402,18 +404,19 @@ module Discordrb::API::Server
|
|
402
404
|
|
403
405
|
# Delete a server integration
|
404
406
|
# https://discordapp.com/developers/docs/resources/guild#delete-guild-integration
|
405
|
-
def delete_integration(token, server_id, integration_id)
|
407
|
+
def delete_integration(token, server_id, integration_id, reason = nil)
|
406
408
|
Discordrb::API.request(
|
407
409
|
:guilds_sid_integrations_iid,
|
408
410
|
server_id,
|
409
411
|
:delete,
|
410
412
|
"#{Discordrb::API.api_base}/guilds/#{server_id}/integrations/#{integration_id}",
|
411
|
-
Authorization: token
|
413
|
+
Authorization: token,
|
414
|
+
'X-Audit-Log-Reason': reason
|
412
415
|
)
|
413
416
|
end
|
414
417
|
|
415
418
|
# Sync an integration
|
416
|
-
# https://
|
419
|
+
# https://discord.com/developers/docs/resources/guild#sync-guild-integration
|
417
420
|
def sync_integration(token, server_id, integration_id)
|
418
421
|
Discordrb::API.request(
|
419
422
|
:guilds_sid_integrations_iid_sync,
|
@@ -426,7 +429,7 @@ module Discordrb::API::Server
|
|
426
429
|
end
|
427
430
|
|
428
431
|
# Retrieves a server's embed information
|
429
|
-
# https://
|
432
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-embed
|
430
433
|
def embed(token, server_id)
|
431
434
|
Discordrb::API.request(
|
432
435
|
:guilds_sid_embed,
|
@@ -438,7 +441,7 @@ module Discordrb::API::Server
|
|
438
441
|
end
|
439
442
|
|
440
443
|
# Modify a server's embed settings
|
441
|
-
# https://
|
444
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild-embed
|
442
445
|
def modify_embed(token, server_id, enabled, channel_id, reason = nil)
|
443
446
|
Discordrb::API.request(
|
444
447
|
:guilds_sid_embed,
|
@@ -452,28 +455,30 @@ module Discordrb::API::Server
|
|
452
455
|
)
|
453
456
|
end
|
454
457
|
|
455
|
-
# Adds a custom emoji
|
456
|
-
|
458
|
+
# Adds a custom emoji.
|
459
|
+
# https://discord.com/developers/docs/resources/emoji#create-guild-emoji
|
460
|
+
def add_emoji(token, server_id, image, name, roles = [], reason = nil)
|
457
461
|
Discordrb::API.request(
|
458
462
|
:guilds_sid_emojis,
|
459
463
|
server_id,
|
460
464
|
:post,
|
461
465
|
"#{Discordrb::API.api_base}/guilds/#{server_id}/emojis",
|
462
|
-
{ image: image, name: name }.to_json,
|
466
|
+
{ image: image, name: name, roles: roles }.to_json,
|
463
467
|
Authorization: token,
|
464
468
|
content_type: :json,
|
465
469
|
'X-Audit-Log-Reason': reason
|
466
470
|
)
|
467
471
|
end
|
468
472
|
|
469
|
-
# Changes an emoji name
|
470
|
-
|
473
|
+
# Changes an emoji name and/or roles.
|
474
|
+
# https://discord.com/developers/docs/resources/emoji#modify-guild-emoji
|
475
|
+
def edit_emoji(token, server_id, emoji_id, name, roles = nil, reason = nil)
|
471
476
|
Discordrb::API.request(
|
472
477
|
:guilds_sid_emojis_eid,
|
473
478
|
server_id,
|
474
479
|
:patch,
|
475
480
|
"#{Discordrb::API.api_base}/guilds/#{server_id}/emojis/#{emoji_id}",
|
476
|
-
{ name: name }.to_json,
|
481
|
+
{ name: name, roles: roles }.to_json,
|
477
482
|
Authorization: token,
|
478
483
|
content_type: :json,
|
479
484
|
'X-Audit-Log-Reason': reason
|
@@ -481,6 +486,7 @@ module Discordrb::API::Server
|
|
481
486
|
end
|
482
487
|
|
483
488
|
# Deletes a custom emoji
|
489
|
+
# https://discord.com/developers/docs/resources/emoji#delete-guild-emoji
|
484
490
|
def delete_emoji(token, server_id, emoji_id, reason = nil)
|
485
491
|
Discordrb::API.request(
|
486
492
|
:guilds_sid_emojis_eid,
|
@@ -493,6 +499,7 @@ module Discordrb::API::Server
|
|
493
499
|
end
|
494
500
|
|
495
501
|
# Available voice regions for this server
|
502
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-voice-regions
|
496
503
|
def regions(token, server_id)
|
497
504
|
Discordrb::API.request(
|
498
505
|
:guilds_sid_regions,
|
@@ -504,7 +511,7 @@ module Discordrb::API::Server
|
|
504
511
|
end
|
505
512
|
|
506
513
|
# Get server webhooks
|
507
|
-
# https://
|
514
|
+
# https://discord.com/developers/docs/resources/webhook#get-guild-webhooks
|
508
515
|
def webhooks(token, server_id)
|
509
516
|
Discordrb::API.request(
|
510
517
|
:guilds_sid_webhooks,
|
@@ -516,7 +523,7 @@ module Discordrb::API::Server
|
|
516
523
|
end
|
517
524
|
|
518
525
|
# Adds a member to a server with an OAuth2 Bearer token that has been granted `guilds.join`
|
519
|
-
# https://
|
526
|
+
# https://discord.com/developers/docs/resources/guild#add-guild-member
|
520
527
|
def add_member(token, server_id, user_id, access_token, nick = nil, roles = [], mute = false, deaf = false)
|
521
528
|
Discordrb::API.request(
|
522
529
|
:guilds_sid_members_uid,
|
data/lib/discordrb/api/user.rb
CHANGED
@@ -5,7 +5,7 @@ module Discordrb::API::User
|
|
5
5
|
module_function
|
6
6
|
|
7
7
|
# Get user data
|
8
|
-
# https://
|
8
|
+
# https://discord.com/developers/docs/resources/user#get-user
|
9
9
|
def resolve(token, user_id)
|
10
10
|
Discordrb::API.request(
|
11
11
|
:users_uid,
|
@@ -17,7 +17,7 @@ module Discordrb::API::User
|
|
17
17
|
end
|
18
18
|
|
19
19
|
# Get profile data
|
20
|
-
# https://
|
20
|
+
# https://discord.com/developers/docs/resources/user#get-current-user
|
21
21
|
def profile(token)
|
22
22
|
Discordrb::API.request(
|
23
23
|
:users_me,
|
@@ -29,6 +29,7 @@ module Discordrb::API::User
|
|
29
29
|
end
|
30
30
|
|
31
31
|
# Change the current bot's nickname on a server
|
32
|
+
# https://discord.com/developers/docs/resources/user#modify-current-user
|
32
33
|
def change_own_nickname(token, server_id, nick, reason = nil)
|
33
34
|
Discordrb::API.request(
|
34
35
|
:guilds_sid_members_me_nick,
|
@@ -43,7 +44,7 @@ module Discordrb::API::User
|
|
43
44
|
end
|
44
45
|
|
45
46
|
# Update user data
|
46
|
-
# https://
|
47
|
+
# https://discord.com/developers/docs/resources/user#modify-current-user
|
47
48
|
def update_profile(token, email, password, new_username, avatar, new_password = nil)
|
48
49
|
Discordrb::API.request(
|
49
50
|
:users_me,
|
@@ -57,7 +58,7 @@ module Discordrb::API::User
|
|
57
58
|
end
|
58
59
|
|
59
60
|
# Get the servers a user is connected to
|
60
|
-
# https://
|
61
|
+
# https://discord.com/developers/docs/resources/user#get-current-user-guilds
|
61
62
|
def servers(token)
|
62
63
|
Discordrb::API.request(
|
63
64
|
:users_me_guilds,
|
@@ -69,7 +70,7 @@ module Discordrb::API::User
|
|
69
70
|
end
|
70
71
|
|
71
72
|
# Leave a server
|
72
|
-
# https://
|
73
|
+
# https://discord.com/developers/docs/resources/user#leave-guild
|
73
74
|
def leave_server(token, server_id)
|
74
75
|
Discordrb::API.request(
|
75
76
|
:users_me_guilds_sid,
|
@@ -81,7 +82,7 @@ module Discordrb::API::User
|
|
81
82
|
end
|
82
83
|
|
83
84
|
# Get the DMs for the current user
|
84
|
-
# https://
|
85
|
+
# https://discord.com/developers/docs/resources/user#get-user-dms
|
85
86
|
def user_dms(token)
|
86
87
|
Discordrb::API.request(
|
87
88
|
:users_me_channels,
|
@@ -93,7 +94,7 @@ module Discordrb::API::User
|
|
93
94
|
end
|
94
95
|
|
95
96
|
# Create a DM to another user
|
96
|
-
# https://
|
97
|
+
# https://discord.com/developers/docs/resources/user#create-dm
|
97
98
|
def create_pm(token, recipient_id)
|
98
99
|
Discordrb::API.request(
|
99
100
|
:users_me_channels,
|
@@ -107,7 +108,7 @@ module Discordrb::API::User
|
|
107
108
|
end
|
108
109
|
|
109
110
|
# Get information about a user's connections
|
110
|
-
# https://
|
111
|
+
# https://discord.com/developers/docs/resources/user#get-users-connections
|
111
112
|
def connections(token)
|
112
113
|
Discordrb::API.request(
|
113
114
|
:users_me_connections,
|
@@ -5,7 +5,7 @@ module Discordrb::API::Webhook
|
|
5
5
|
module_function
|
6
6
|
|
7
7
|
# Get a webhook
|
8
|
-
# https://
|
8
|
+
# https://discord.com/developers/docs/resources/webhook#get-webhook
|
9
9
|
def webhook(token, webhook_id)
|
10
10
|
Discordrb::API.request(
|
11
11
|
:webhooks_wid,
|
@@ -17,7 +17,7 @@ module Discordrb::API::Webhook
|
|
17
17
|
end
|
18
18
|
|
19
19
|
# Get a webhook via webhook token
|
20
|
-
# https://
|
20
|
+
# https://discord.com/developers/docs/resources/webhook#get-webhook-with-token
|
21
21
|
def token_webhook(webhook_token, webhook_id)
|
22
22
|
Discordrb::API.request(
|
23
23
|
:webhooks_wid,
|
@@ -28,7 +28,7 @@ module Discordrb::API::Webhook
|
|
28
28
|
end
|
29
29
|
|
30
30
|
# Update a webhook
|
31
|
-
# https://
|
31
|
+
# https://discord.com/developers/docs/resources/webhook#modify-webhook
|
32
32
|
def update_webhook(token, webhook_id, data, reason = nil)
|
33
33
|
Discordrb::API.request(
|
34
34
|
:webhooks_wid,
|
@@ -43,7 +43,7 @@ module Discordrb::API::Webhook
|
|
43
43
|
end
|
44
44
|
|
45
45
|
# Update a webhook via webhook token
|
46
|
-
# https://
|
46
|
+
# https://discord.com/developers/docs/resources/webhook#modify-webhook-with-token
|
47
47
|
def token_update_webhook(webhook_token, webhook_id, data, reason = nil)
|
48
48
|
Discordrb::API.request(
|
49
49
|
:webhooks_wid,
|
@@ -57,7 +57,7 @@ module Discordrb::API::Webhook
|
|
57
57
|
end
|
58
58
|
|
59
59
|
# Deletes a webhook
|
60
|
-
# https://
|
60
|
+
# https://discord.com/developers/docs/resources/webhook#delete-webhook
|
61
61
|
def delete_webhook(token, webhook_id, reason = nil)
|
62
62
|
Discordrb::API.request(
|
63
63
|
:webhooks_wid,
|
@@ -70,7 +70,7 @@ module Discordrb::API::Webhook
|
|
70
70
|
end
|
71
71
|
|
72
72
|
# Deletes a webhook via webhook token
|
73
|
-
# https://
|
73
|
+
# https://discord.com/developers/docs/resources/webhook#delete-webhook-with-token
|
74
74
|
def token_delete_webhook(webhook_token, webhook_id, reason = nil)
|
75
75
|
Discordrb::API.request(
|
76
76
|
:webhooks_wid,
|
data/lib/discordrb/api.rb
CHANGED
@@ -9,10 +9,10 @@ require 'discordrb/errors'
|
|
9
9
|
# List of methods representing endpoints in Discord's API
|
10
10
|
module Discordrb::API
|
11
11
|
# The base URL of the Discord REST API.
|
12
|
-
APIBASE = 'https://
|
12
|
+
APIBASE = 'https://discord.com/api/v6'
|
13
13
|
|
14
14
|
# The URL of Discord's CDN
|
15
|
-
CDN_URL = 'https://cdn.discordapp.com'
|
15
|
+
CDN_URL = 'https://cdn.discordapp.com'
|
16
16
|
|
17
17
|
module_function
|
18
18
|
|
@@ -31,12 +31,12 @@ module Discordrb::API
|
|
31
31
|
@cdn_url || CDN_URL
|
32
32
|
end
|
33
33
|
|
34
|
-
# @return [String] the bot name, previously specified using
|
34
|
+
# @return [String] the bot name, previously specified using {.bot_name=}.
|
35
35
|
def bot_name
|
36
36
|
@bot_name
|
37
37
|
end
|
38
38
|
|
39
|
-
# Sets the bot name to something.
|
39
|
+
# Sets the bot name to something. Used in {.user_agent}. For the bot's username, see {Profile#username=}.
|
40
40
|
def bot_name=(value)
|
41
41
|
@bot_name = value
|
42
42
|
end
|
@@ -51,7 +51,7 @@ module Discordrb::API
|
|
51
51
|
# Generate a user agent identifying this requester as discordrb.
|
52
52
|
def user_agent
|
53
53
|
# This particular string is required by the Discord devs.
|
54
|
-
required = "DiscordBot (https://github.com/
|
54
|
+
required = "DiscordBot (https://github.com/shardlab/discordrb, v#{Discordrb::VERSION})"
|
55
55
|
@bot_name ||= ''
|
56
56
|
|
57
57
|
"#{required} rest-client/#{RestClient::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION}p#{RUBY_PATCHLEVEL} discordrb/#{Discordrb::VERSION} #{@bot_name}"
|
@@ -80,7 +80,7 @@ module Discordrb::API
|
|
80
80
|
def raw_request(type, attributes)
|
81
81
|
RestClient.send(type, *attributes)
|
82
82
|
rescue RestClient::Forbidden => e
|
83
|
-
# HACK: for #request, dynamically inject restclient's response into NoPermission - this allows us to
|
83
|
+
# HACK: for #request, dynamically inject restclient's response into NoPermission - this allows us to rate limit
|
84
84
|
noprm = Discordrb::Errors::NoPermission.new
|
85
85
|
noprm.define_singleton_method(:_rc_response) { e.response }
|
86
86
|
raise noprm, "The bot doesn't have the required permission to do this!"
|
@@ -94,6 +94,9 @@ module Discordrb::API
|
|
94
94
|
# Add a custom user agent
|
95
95
|
attributes.last[:user_agent] = user_agent if attributes.last.is_a? Hash
|
96
96
|
|
97
|
+
# Specify RateLimit precision
|
98
|
+
attributes.last[:x_ratelimit_precision] = 'millisecond' if attributes.last.is_a?(Hash)
|
99
|
+
|
97
100
|
# The most recent Discord rate limit requirements require the support of major parameters, where a particular route
|
98
101
|
# and major parameter combination (*not* the HTTP method) uniquely identifies a RL bucket.
|
99
102
|
key = [key, major_parameter].freeze
|
@@ -149,17 +152,12 @@ module Discordrb::API
|
|
149
152
|
response
|
150
153
|
end
|
151
154
|
|
152
|
-
# Handles
|
155
|
+
# Handles pre-emptive rate limiting by waiting the given mutex by the difference of the Date header to the
|
153
156
|
# X-Ratelimit-Reset header, thus making sure we don't get 429'd in any subsequent requests.
|
154
157
|
def handle_preemptive_rl(headers, mutex, key)
|
155
158
|
Discordrb::LOGGER.ratelimit "RL bucket depletion detected! Date: #{headers[:date]} Reset: #{headers[:x_ratelimit_reset]}"
|
156
|
-
|
157
|
-
|
158
|
-
reset = Time.at(headers[:x_ratelimit_reset].to_i)
|
159
|
-
|
160
|
-
delta = reset - now
|
161
|
-
|
162
|
-
Discordrb::LOGGER.warn("Locking RL mutex (key: #{key}) for #{delta} seconds preemptively")
|
159
|
+
delta = headers[:x_ratelimit_reset_after].to_f
|
160
|
+
Discordrb::LOGGER.warn("Locking RL mutex (key: #{key}) for #{delta} seconds pre-emptively")
|
163
161
|
sync_wait(delta, mutex)
|
164
162
|
end
|
165
163
|
|
@@ -175,7 +173,7 @@ module Discordrb::API
|
|
175
173
|
Discordrb::LOGGER.ratelimit("Trace (#{reason}):")
|
176
174
|
|
177
175
|
caller.each do |str|
|
178
|
-
Discordrb::LOGGER.ratelimit(
|
176
|
+
Discordrb::LOGGER.ratelimit(" #{str}")
|
179
177
|
end
|
180
178
|
end
|
181
179
|
|
@@ -199,11 +197,26 @@ module Discordrb::API
|
|
199
197
|
"#{cdn_url}/splashes/#{server_id}/#{splash_id}.#{format}"
|
200
198
|
end
|
201
199
|
|
200
|
+
# Make a banner URL from server and banner IDs
|
201
|
+
def banner_url(server_id, banner_id, format = 'webp')
|
202
|
+
"#{cdn_url}/banners/#{server_id}/#{banner_id}.#{format}"
|
203
|
+
end
|
204
|
+
|
202
205
|
# Make an emoji icon URL from emoji ID
|
203
206
|
def emoji_icon_url(emoji_id, format = 'webp')
|
204
207
|
"#{cdn_url}/emojis/#{emoji_id}.#{format}"
|
205
208
|
end
|
206
209
|
|
210
|
+
# Make an asset URL from application and asset IDs
|
211
|
+
def asset_url(application_id, asset_id, format = 'webp')
|
212
|
+
"#{cdn_url}/app-assets/#{application_id}/#{asset_id}.#{format}"
|
213
|
+
end
|
214
|
+
|
215
|
+
# Make an achievement icon URL from application ID, achievement ID, and icon hash
|
216
|
+
def achievement_icon_url(application_id, achievement_id, icon_hash, format = 'webp')
|
217
|
+
"#{cdn_url}/app-assets/#{application_id}/achievements/#{achievement_id}/icons/#{icon_hash}.#{format}"
|
218
|
+
end
|
219
|
+
|
207
220
|
# Login to the server
|
208
221
|
def login(email, password)
|
209
222
|
request(
|
@@ -290,6 +303,18 @@ module Discordrb::API
|
|
290
303
|
)
|
291
304
|
end
|
292
305
|
|
306
|
+
# Get the gateway to be used, with additional information for sharding and
|
307
|
+
# session start limits
|
308
|
+
def gateway_bot(token)
|
309
|
+
request(
|
310
|
+
:gateway_bot,
|
311
|
+
nil,
|
312
|
+
:get,
|
313
|
+
"#{api_base}/gateway/bot",
|
314
|
+
Authorization: token
|
315
|
+
)
|
316
|
+
end
|
317
|
+
|
293
318
|
# Validate a token (this request will fail if the token is invalid)
|
294
319
|
def validate_token(token)
|
295
320
|
request(
|
data/lib/discordrb/await.rb
CHANGED
@@ -43,7 +43,6 @@ module Discordrb
|
|
43
43
|
dummy_handler = EventContainer.handler_class(@type).new(@attributes, @bot)
|
44
44
|
return [nil, nil] unless event.instance_of?(@type) && dummy_handler.matches?(event)
|
45
45
|
|
46
|
-
should_delete = nil
|
47
46
|
should_delete = true if (@block && @block.call(event) != false) || !@block
|
48
47
|
|
49
48
|
[@key, should_delete]
|