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
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,20 +126,22 @@ 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)
|
131
|
+
query_string = URI.encode_www_form({ limit: limit, after: after }.compact)
|
130
132
|
Discordrb::API.request(
|
131
133
|
:guilds_sid_members,
|
132
134
|
server_id,
|
133
135
|
:get,
|
134
|
-
"#{Discordrb::API.api_base}/guilds/#{server_id}/members
|
136
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/members?#{query_string}",
|
135
137
|
Authorization: token
|
136
138
|
)
|
137
139
|
end
|
138
140
|
|
139
141
|
# Update a user properties
|
140
|
-
# https://
|
141
|
-
def update_member(token, server_id, user_id, nick:
|
142
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild-member
|
143
|
+
def update_member(token, server_id, user_id, nick: :undef, roles: :undef, mute: :undef, deaf: :undef, channel_id: :undef,
|
144
|
+
communication_disabled_until: :undef, reason: nil)
|
142
145
|
Discordrb::API.request(
|
143
146
|
:guilds_sid_members_uid,
|
144
147
|
server_id,
|
@@ -148,8 +151,9 @@ module Discordrb::API::Server
|
|
148
151
|
nick: nick,
|
149
152
|
mute: mute,
|
150
153
|
deaf: deaf,
|
151
|
-
channel_id: channel_id
|
152
|
-
|
154
|
+
channel_id: channel_id,
|
155
|
+
communication_disabled_until: communication_disabled_until
|
156
|
+
}.reject { |_, v| v == :undef }.to_json,
|
153
157
|
Authorization: token,
|
154
158
|
content_type: :json,
|
155
159
|
'X-Audit-Log-Reason': reason
|
@@ -157,7 +161,7 @@ module Discordrb::API::Server
|
|
157
161
|
end
|
158
162
|
|
159
163
|
# Remove user from server
|
160
|
-
# https://
|
164
|
+
# https://discord.com/developers/docs/resources/guild#remove-guild-member
|
161
165
|
def remove_member(token, server_id, user_id, reason = nil)
|
162
166
|
Discordrb::API.request(
|
163
167
|
:guilds_sid_members_uid,
|
@@ -171,33 +175,34 @@ module Discordrb::API::Server
|
|
171
175
|
end
|
172
176
|
|
173
177
|
# Get a server's banned users
|
174
|
-
# https://
|
175
|
-
def bans(token, server_id)
|
178
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-bans
|
179
|
+
def bans(token, server_id, limit = nil, before = nil, after = nil)
|
180
|
+
query_string = URI.encode_www_form({ limit: limit, before: before, after: after }.compact)
|
176
181
|
Discordrb::API.request(
|
177
182
|
:guilds_sid_bans,
|
178
183
|
server_id,
|
179
184
|
:get,
|
180
|
-
"#{Discordrb::API.api_base}/guilds/#{server_id}/bans",
|
185
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/bans?#{query_string}",
|
181
186
|
Authorization: token
|
182
187
|
)
|
183
188
|
end
|
184
189
|
|
185
190
|
# Ban a user from a server and delete their messages from the last message_days days
|
186
|
-
# https://
|
191
|
+
# https://discord.com/developers/docs/resources/guild#create-guild-ban
|
187
192
|
def ban_user(token, server_id, user_id, message_days, reason = nil)
|
188
|
-
reason = URI.
|
193
|
+
reason = URI.encode_www_form_component(reason) if reason
|
189
194
|
Discordrb::API.request(
|
190
195
|
:guilds_sid_bans_uid,
|
191
196
|
server_id,
|
192
197
|
:put,
|
193
|
-
"#{Discordrb::API.api_base}/guilds/#{server_id}/bans/#{user_id}?
|
198
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/bans/#{user_id}?delete_message_days=#{message_days}&reason=#{reason}",
|
194
199
|
nil,
|
195
200
|
Authorization: token
|
196
201
|
)
|
197
202
|
end
|
198
203
|
|
199
204
|
# Unban a user from a server
|
200
|
-
# https://
|
205
|
+
# https://discord.com/developers/docs/resources/guild#remove-guild-ban
|
201
206
|
def unban_user(token, server_id, user_id, reason = nil)
|
202
207
|
Discordrb::API.request(
|
203
208
|
:guilds_sid_bans_uid,
|
@@ -210,7 +215,7 @@ module Discordrb::API::Server
|
|
210
215
|
end
|
211
216
|
|
212
217
|
# Get server roles
|
213
|
-
# https://
|
218
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-roles
|
214
219
|
def roles(token, server_id)
|
215
220
|
Discordrb::API.request(
|
216
221
|
:guilds_sid_roles,
|
@@ -225,7 +230,7 @@ module Discordrb::API::Server
|
|
225
230
|
# Permissions are the Discord defaults; allowed: invite creation, reading/sending messages,
|
226
231
|
# sending TTS messages, embedding links, sending files, reading the history, mentioning everybody,
|
227
232
|
# connecting to voice, speaking and voice activity (push-to-talk isn't mandatory)
|
228
|
-
# https://
|
233
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-roles
|
229
234
|
def create_role(token, server_id, name, colour, hoist, mentionable, packed_permissions, reason = nil)
|
230
235
|
Discordrb::API.request(
|
231
236
|
:guilds_sid_roles,
|
@@ -243,14 +248,29 @@ module Discordrb::API::Server
|
|
243
248
|
# Permissions are the Discord defaults; allowed: invite creation, reading/sending messages,
|
244
249
|
# sending TTS messages, embedding links, sending files, reading the history, mentioning everybody,
|
245
250
|
# connecting to voice, speaking and voice activity (push-to-talk isn't mandatory)
|
246
|
-
# https://
|
247
|
-
|
251
|
+
# https://discord.com/developers/docs/resources/guild#batch-modify-guild-role
|
252
|
+
# @param icon [:undef, File]
|
253
|
+
def update_role(token, server_id, role_id, name, colour, hoist = false, mentionable = false, packed_permissions = 104_324_161, reason = nil, icon = :undef)
|
254
|
+
data = { color: colour, name: name, hoist: hoist, mentionable: mentionable, permissions: packed_permissions }
|
255
|
+
|
256
|
+
if icon != :undef && icon
|
257
|
+
path_method = %i[original_filename path local_path].find { |meth| icon.respond_to?(meth) }
|
258
|
+
|
259
|
+
raise ArgumentError, 'File object must respond to original_filename, path, or local path.' unless path_method
|
260
|
+
raise ArgumentError, 'File must respond to read' unless icon.respond_to? :read
|
261
|
+
|
262
|
+
mime_type = MIME::Types.type_for(icon.__send__(path_method)).first&.to_s || 'image/jpeg'
|
263
|
+
data[:icon] = "data:#{mime_type};base64,#{Base64.encode64(icon.read).strip}"
|
264
|
+
elsif icon.nil?
|
265
|
+
data[:icon] = nil
|
266
|
+
end
|
267
|
+
|
248
268
|
Discordrb::API.request(
|
249
269
|
:guilds_sid_roles_rid,
|
250
270
|
server_id,
|
251
271
|
:patch,
|
252
272
|
"#{Discordrb::API.api_base}/guilds/#{server_id}/roles/#{role_id}",
|
253
|
-
|
273
|
+
data.to_json,
|
254
274
|
Authorization: token,
|
255
275
|
content_type: :json,
|
256
276
|
'X-Audit-Log-Reason': reason
|
@@ -258,7 +278,7 @@ module Discordrb::API::Server
|
|
258
278
|
end
|
259
279
|
|
260
280
|
# Update role positions
|
261
|
-
# https://
|
281
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild-role-positions
|
262
282
|
def update_role_positions(token, server_id, roles)
|
263
283
|
Discordrb::API.request(
|
264
284
|
:guilds_sid_roles,
|
@@ -272,7 +292,7 @@ module Discordrb::API::Server
|
|
272
292
|
end
|
273
293
|
|
274
294
|
# Delete a role
|
275
|
-
# https://
|
295
|
+
# https://discord.com/developers/docs/resources/guild#delete-guild-role
|
276
296
|
def delete_role(token, server_id, role_id, reason = nil)
|
277
297
|
Discordrb::API.request(
|
278
298
|
:guilds_sid_roles_rid,
|
@@ -285,7 +305,7 @@ module Discordrb::API::Server
|
|
285
305
|
end
|
286
306
|
|
287
307
|
# Adds a single role to a member
|
288
|
-
# https://
|
308
|
+
# https://discord.com/developers/docs/resources/guild#add-guild-member-role
|
289
309
|
def add_member_role(token, server_id, user_id, role_id, reason = nil)
|
290
310
|
Discordrb::API.request(
|
291
311
|
:guilds_sid_members_uid_roles_rid,
|
@@ -299,7 +319,7 @@ module Discordrb::API::Server
|
|
299
319
|
end
|
300
320
|
|
301
321
|
# Removes a single role from a member
|
302
|
-
# https://
|
322
|
+
# https://discord.com/developers/docs/resources/guild#remove-guild-member-role
|
303
323
|
def remove_member_role(token, server_id, user_id, role_id, reason = nil)
|
304
324
|
Discordrb::API.request(
|
305
325
|
:guilds_sid_members_uid_roles_rid,
|
@@ -312,7 +332,7 @@ module Discordrb::API::Server
|
|
312
332
|
end
|
313
333
|
|
314
334
|
# Get server prune count
|
315
|
-
# https://
|
335
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-prune-count
|
316
336
|
def prune_count(token, server_id, days)
|
317
337
|
Discordrb::API.request(
|
318
338
|
:guilds_sid_prune,
|
@@ -324,7 +344,7 @@ module Discordrb::API::Server
|
|
324
344
|
end
|
325
345
|
|
326
346
|
# Begin server prune
|
327
|
-
# https://
|
347
|
+
# https://discord.com/developers/docs/resources/guild#begin-guild-prune
|
328
348
|
def begin_prune(token, server_id, days, reason = nil)
|
329
349
|
Discordrb::API.request(
|
330
350
|
:guilds_sid_prune,
|
@@ -338,7 +358,7 @@ module Discordrb::API::Server
|
|
338
358
|
end
|
339
359
|
|
340
360
|
# Get invites from server
|
341
|
-
# https://
|
361
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-invites
|
342
362
|
def invites(token, server_id)
|
343
363
|
Discordrb::API.request(
|
344
364
|
:guilds_sid_invites,
|
@@ -350,19 +370,19 @@ module Discordrb::API::Server
|
|
350
370
|
end
|
351
371
|
|
352
372
|
# Gets a server's audit logs
|
353
|
-
# https://
|
354
|
-
def audit_logs(token, server_id, limit,
|
373
|
+
# https://discord.com/developers/docs/resources/audit-log#get-guild-audit-log
|
374
|
+
def audit_logs(token, server_id, limit, user_id = nil, action_type = nil, before = nil)
|
355
375
|
Discordrb::API.request(
|
356
376
|
:guilds_sid_auditlogs,
|
357
377
|
server_id,
|
358
378
|
:get,
|
359
|
-
"#{Discordrb::API.api_base}/guilds/#{server_id}/audit-logs?limit=#{limit}#{"&user_id=#{
|
379
|
+
"#{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
380
|
Authorization: token
|
361
381
|
)
|
362
382
|
end
|
363
383
|
|
364
384
|
# Get server integrations
|
365
|
-
# https://
|
385
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-integrations
|
366
386
|
def integrations(token, server_id)
|
367
387
|
Discordrb::API.request(
|
368
388
|
:guilds_sid_integrations,
|
@@ -374,20 +394,21 @@ module Discordrb::API::Server
|
|
374
394
|
end
|
375
395
|
|
376
396
|
# Create a server integration
|
377
|
-
# https://
|
378
|
-
def create_integration(token, server_id, type, id)
|
397
|
+
# https://discord.com/developers/docs/resources/guild#create-guild-integration
|
398
|
+
def create_integration(token, server_id, type, id, reason = nil)
|
379
399
|
Discordrb::API.request(
|
380
400
|
:guilds_sid_integrations,
|
381
401
|
server_id,
|
382
402
|
:post,
|
383
403
|
"#{Discordrb::API.api_base}/guilds/#{server_id}/integrations",
|
384
404
|
{ type: type, id: id },
|
385
|
-
Authorization: token
|
405
|
+
Authorization: token,
|
406
|
+
'X-Audit-Log-Reason': reason
|
386
407
|
)
|
387
408
|
end
|
388
409
|
|
389
410
|
# Update integration from server
|
390
|
-
# https://
|
411
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild-integration
|
391
412
|
def update_integration(token, server_id, integration_id, expire_behavior, expire_grace_period, enable_emoticons)
|
392
413
|
Discordrb::API.request(
|
393
414
|
:guilds_sid_integrations_iid,
|
@@ -401,19 +422,20 @@ module Discordrb::API::Server
|
|
401
422
|
end
|
402
423
|
|
403
424
|
# Delete a server integration
|
404
|
-
# https://
|
405
|
-
def delete_integration(token, server_id, integration_id)
|
425
|
+
# https://discord.com/developers/docs/resources/guild#delete-guild-integration
|
426
|
+
def delete_integration(token, server_id, integration_id, reason = nil)
|
406
427
|
Discordrb::API.request(
|
407
428
|
:guilds_sid_integrations_iid,
|
408
429
|
server_id,
|
409
430
|
:delete,
|
410
431
|
"#{Discordrb::API.api_base}/guilds/#{server_id}/integrations/#{integration_id}",
|
411
|
-
Authorization: token
|
432
|
+
Authorization: token,
|
433
|
+
'X-Audit-Log-Reason': reason
|
412
434
|
)
|
413
435
|
end
|
414
436
|
|
415
437
|
# Sync an integration
|
416
|
-
# https://
|
438
|
+
# https://discord.com/developers/docs/resources/guild#sync-guild-integration
|
417
439
|
def sync_integration(token, server_id, integration_id)
|
418
440
|
Discordrb::API.request(
|
419
441
|
:guilds_sid_integrations_iid_sync,
|
@@ -425,55 +447,59 @@ module Discordrb::API::Server
|
|
425
447
|
)
|
426
448
|
end
|
427
449
|
|
428
|
-
# Retrieves a server's
|
429
|
-
# https://
|
430
|
-
def
|
450
|
+
# Retrieves a server's widget information
|
451
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-widget
|
452
|
+
def widget(token, server_id)
|
431
453
|
Discordrb::API.request(
|
432
454
|
:guilds_sid_embed,
|
433
455
|
server_id,
|
434
456
|
:get,
|
435
|
-
"#{Discordrb::API.api_base}/guilds/#{server_id}/
|
457
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/widget",
|
436
458
|
Authorization: token
|
437
459
|
)
|
438
460
|
end
|
461
|
+
alias embed widget
|
439
462
|
|
440
|
-
# Modify a server's
|
441
|
-
# https://
|
442
|
-
def
|
463
|
+
# Modify a server's widget settings
|
464
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild-widget
|
465
|
+
def modify_widget(token, server_id, enabled, channel_id, reason = nil)
|
443
466
|
Discordrb::API.request(
|
444
467
|
:guilds_sid_embed,
|
445
468
|
server_id,
|
446
469
|
:patch,
|
447
|
-
"#{Discordrb::API.api_base}/guilds/#{server_id}/
|
470
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/widget",
|
448
471
|
{ enabled: enabled, channel_id: channel_id }.to_json,
|
449
472
|
Authorization: token,
|
450
473
|
'X-Audit-Log-Reason': reason,
|
451
474
|
content_type: :json
|
452
475
|
)
|
453
476
|
end
|
477
|
+
alias modify_embed modify_widget
|
454
478
|
|
455
|
-
# Adds a custom emoji
|
456
|
-
|
479
|
+
# Adds a custom emoji.
|
480
|
+
# https://discord.com/developers/docs/resources/emoji#create-guild-emoji
|
481
|
+
def add_emoji(token, server_id, image, name, roles = [], reason = nil)
|
457
482
|
Discordrb::API.request(
|
458
483
|
:guilds_sid_emojis,
|
459
484
|
server_id,
|
460
485
|
:post,
|
461
486
|
"#{Discordrb::API.api_base}/guilds/#{server_id}/emojis",
|
462
|
-
{ image: image, name: name }.to_json,
|
487
|
+
{ image: image, name: name, roles: roles }.to_json,
|
463
488
|
Authorization: token,
|
464
489
|
content_type: :json,
|
465
490
|
'X-Audit-Log-Reason': reason
|
466
491
|
)
|
467
492
|
end
|
468
493
|
|
469
|
-
# Changes an emoji name
|
470
|
-
|
494
|
+
# Changes an emoji name and/or roles.
|
495
|
+
# https://discord.com/developers/docs/resources/emoji#modify-guild-emoji
|
496
|
+
def edit_emoji(token, server_id, emoji_id, name, roles = nil, reason = nil)
|
471
497
|
Discordrb::API.request(
|
472
498
|
:guilds_sid_emojis_eid,
|
473
499
|
server_id,
|
474
500
|
:patch,
|
475
501
|
"#{Discordrb::API.api_base}/guilds/#{server_id}/emojis/#{emoji_id}",
|
476
|
-
{ name: name }.to_json,
|
502
|
+
{ name: name, roles: roles }.to_json,
|
477
503
|
Authorization: token,
|
478
504
|
content_type: :json,
|
479
505
|
'X-Audit-Log-Reason': reason
|
@@ -481,6 +507,7 @@ module Discordrb::API::Server
|
|
481
507
|
end
|
482
508
|
|
483
509
|
# Deletes a custom emoji
|
510
|
+
# https://discord.com/developers/docs/resources/emoji#delete-guild-emoji
|
484
511
|
def delete_emoji(token, server_id, emoji_id, reason = nil)
|
485
512
|
Discordrb::API.request(
|
486
513
|
:guilds_sid_emojis_eid,
|
@@ -493,6 +520,7 @@ module Discordrb::API::Server
|
|
493
520
|
end
|
494
521
|
|
495
522
|
# Available voice regions for this server
|
523
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-voice-regions
|
496
524
|
def regions(token, server_id)
|
497
525
|
Discordrb::API.request(
|
498
526
|
:guilds_sid_regions,
|
@@ -504,7 +532,7 @@ module Discordrb::API::Server
|
|
504
532
|
end
|
505
533
|
|
506
534
|
# Get server webhooks
|
507
|
-
# https://
|
535
|
+
# https://discord.com/developers/docs/resources/webhook#get-guild-webhooks
|
508
536
|
def webhooks(token, server_id)
|
509
537
|
Discordrb::API.request(
|
510
538
|
:guilds_sid_webhooks,
|
@@ -516,7 +544,7 @@ module Discordrb::API::Server
|
|
516
544
|
end
|
517
545
|
|
518
546
|
# Adds a member to a server with an OAuth2 Bearer token that has been granted `guilds.join`
|
519
|
-
# https://
|
547
|
+
# https://discord.com/developers/docs/resources/guild#add-guild-member
|
520
548
|
def add_member(token, server_id, user_id, access_token, nick = nil, roles = [], mute = false, deaf = false)
|
521
549
|
Discordrb::API.request(
|
522
550
|
: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,
|
@@ -131,9 +132,14 @@ module Discordrb::API::User
|
|
131
132
|
)
|
132
133
|
end
|
133
134
|
|
134
|
-
# Returns one of the "default" discord avatars from the CDN given a discriminator
|
135
|
-
|
136
|
-
|
135
|
+
# Returns one of the "default" discord avatars from the CDN given a discriminator or id since new usernames
|
136
|
+
# TODO: Maybe change this method again after discriminator removal ?
|
137
|
+
def default_avatar(discrim_id = 0, legacy: false)
|
138
|
+
index = if legacy
|
139
|
+
discrim_id.to_i % 5
|
140
|
+
else
|
141
|
+
(discrim_id.to_i >> 22) % 5
|
142
|
+
end
|
137
143
|
"#{Discordrb::API.cdn_url}/embed/avatars/#{index}.png"
|
138
144
|
end
|
139
145
|
|