disrb 0.1.3 → 0.1.4
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 +4 -4
- data/CHANGELOG.md +13 -0
- data/LICENSE +1 -1
- data/README.md +19 -7
- data/lib/disrb/application_commands.rb +53 -45
- data/lib/disrb/guild.rb +162 -147
- data/lib/disrb/message.rb +87 -66
- data/lib/disrb/user.rb +36 -35
- data/lib/disrb.rb +183 -24
- data/lib/version.rb +5 -0
- metadata +30 -1
data/lib/disrb/guild.rb
CHANGED
|
@@ -12,10 +12,10 @@ class DiscordApi
|
|
|
12
12
|
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
13
13
|
url = "#{@base_url}/guilds/#{guild_id}#{query_string}"
|
|
14
14
|
headers = { 'Authorization' => @authorization_header }
|
|
15
|
-
response =
|
|
16
|
-
return response if response.status == 200
|
|
15
|
+
response = get(url, headers)
|
|
16
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
17
17
|
|
|
18
|
-
@logger.error("Could not get guild with Guild ID #{guild_id}. Response: #{response
|
|
18
|
+
@logger.error("Could not get guild with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
|
|
19
19
|
response
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -26,10 +26,10 @@ class DiscordApi
|
|
|
26
26
|
def get_guild_preview(guild_id)
|
|
27
27
|
url = URI("#{@base_url}/guilds/#{guild_id}/preview")
|
|
28
28
|
headers = { 'Authorization': @authorization_header }
|
|
29
|
-
response =
|
|
30
|
-
return response if response.status == 200
|
|
29
|
+
response = get(url, headers)
|
|
30
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
31
31
|
|
|
32
|
-
@logger.error("Could not get guild preview with Guild ID #{guild_id}. Response: #{response
|
|
32
|
+
@logger.error("Could not get guild preview with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
|
|
33
33
|
response
|
|
34
34
|
end
|
|
35
35
|
|
|
@@ -106,20 +106,20 @@ class DiscordApi
|
|
|
106
106
|
data = JSON.generate(output)
|
|
107
107
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
108
108
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
109
|
-
response =
|
|
110
|
-
return response if response.status == 200
|
|
109
|
+
response = patch(url, headers, data)
|
|
110
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
111
111
|
|
|
112
|
-
@logger.error("Could not modify guild with Guild ID #{guild_id}. Response: #{response
|
|
112
|
+
@logger.error("Could not modify guild with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
|
|
113
113
|
response
|
|
114
114
|
end
|
|
115
115
|
|
|
116
116
|
def delete_guild(guild_id)
|
|
117
117
|
url = "#{@base_url}/guilds/#{guild_id}"
|
|
118
118
|
headers = { 'Authorization': @authorization_header }
|
|
119
|
-
response =
|
|
120
|
-
return response if response.status == 204
|
|
119
|
+
response = delete(url, headers)
|
|
120
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
121
121
|
|
|
122
|
-
@logger.error("Could not delete guild with Guild ID #{guild_id}. Response: #{response
|
|
122
|
+
@logger.error("Could not delete guild with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
|
|
123
123
|
response
|
|
124
124
|
end
|
|
125
125
|
|
|
@@ -130,10 +130,10 @@ class DiscordApi
|
|
|
130
130
|
def get_guild_channels(guild_id)
|
|
131
131
|
url = "#{@base_url}/guilds/#{guild_id}/channels"
|
|
132
132
|
headers = { 'Authorization': @authorization_header }
|
|
133
|
-
response =
|
|
134
|
-
return response if response.status == 200
|
|
133
|
+
response = get(url, headers)
|
|
134
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
135
135
|
|
|
136
|
-
@logger.error("Could not get guild channels with Guild ID #{guild_id}. Response: #{response
|
|
136
|
+
@logger.error("Could not get guild channels with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
|
|
137
137
|
response
|
|
138
138
|
end
|
|
139
139
|
|
|
@@ -199,10 +199,10 @@ class DiscordApi
|
|
|
199
199
|
data = JSON.generate(output)
|
|
200
200
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
201
201
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
202
|
-
response =
|
|
203
|
-
return response if response.status == 200
|
|
202
|
+
response = post(url, data, headers)
|
|
203
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
204
204
|
|
|
205
|
-
@logger.error("Could not create guild channel in Guild ID #{guild_id}. Response: #{response
|
|
205
|
+
@logger.error("Could not create guild channel in Guild ID #{guild_id}. Response: #{response_error_body(response)}")
|
|
206
206
|
response
|
|
207
207
|
end
|
|
208
208
|
|
|
@@ -256,42 +256,47 @@ class DiscordApi
|
|
|
256
256
|
url = "#{@base_url}/guilds/#{guild_id}/channels"
|
|
257
257
|
data = JSON.generate(output)
|
|
258
258
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
259
|
-
response =
|
|
260
|
-
return response if response.status == 200
|
|
259
|
+
response = patch(url, headers, data)
|
|
260
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
261
261
|
|
|
262
|
-
@logger.error("Could not modify guild channel positions with Guild ID #{guild_id}.
|
|
262
|
+
@logger.error("Could not modify guild channel positions with Guild ID #{guild_id}." \
|
|
263
|
+
" Response: #{response_error_body(response)}")
|
|
263
264
|
response
|
|
264
265
|
end
|
|
265
266
|
|
|
266
|
-
# Returns a list of active threads in the specified guild.
|
|
267
|
+
# Returns a list of active threads in the specified guild.
|
|
268
|
+
# See https://discord.com/developers/docs/resources/guild#list-active-guild-threads
|
|
267
269
|
# @param guild_id [String] ID (as a string) of the guild to list active threads for.
|
|
268
270
|
# @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
|
|
269
271
|
def list_active_guild_threads(guild_id)
|
|
270
272
|
url = "#{@base_url}/guilds/#{guild_id}/threads/active"
|
|
271
273
|
headers = { 'Authorization': @authorization_header }
|
|
272
|
-
response =
|
|
273
|
-
return response if response.status == 200
|
|
274
|
+
response = get(url, headers)
|
|
275
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
274
276
|
|
|
275
|
-
@logger.error("Could not list active guild threads with Guild ID #{guild_id}.
|
|
277
|
+
@logger.error("Could not list active guild threads with Guild ID #{guild_id}." \
|
|
278
|
+
" Response: #{response_error_body(response)}")
|
|
276
279
|
response
|
|
277
280
|
end
|
|
278
281
|
|
|
279
|
-
# Returns a guild member object for the specified user in the specified guild.
|
|
282
|
+
# Returns a guild member object for the specified user in the specified guild.
|
|
283
|
+
# See https://discord.com/developers/docs/resources/guild#get-guild-member
|
|
280
284
|
# @param guild_id [String] ID (as a string) of the guild to get the member from.
|
|
281
285
|
# @param user_id [String] ID (as a string) of the user to get the member object for.
|
|
282
286
|
# @return [Faraday::Response] The response from the DiscordApi as a Faraday::Response object.
|
|
283
287
|
def get_guild_member(guild_id, user_id)
|
|
284
288
|
url = "#{@base_url}/guilds/#{guild_id}/members/#{user_id}"
|
|
285
289
|
headers = { 'Authorization' => @authorization_header }
|
|
286
|
-
response =
|
|
287
|
-
return response if response.status == 200
|
|
290
|
+
response = get(url, headers)
|
|
291
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
288
292
|
|
|
289
293
|
@logger.error("Could not get guild member with Guild ID #{guild_id} and User ID #{user_id}. Response:" \
|
|
290
|
-
"#{response
|
|
294
|
+
"#{response_error_body(response)}")
|
|
291
295
|
response
|
|
292
296
|
end
|
|
293
297
|
|
|
294
|
-
# Returns an array of guild member objects for the specified guild.
|
|
298
|
+
# Returns an array of guild member objects for the specified guild.
|
|
299
|
+
# See https://discord.com/developers/docs/resources/guild#list-guild-members
|
|
295
300
|
# @param guild_id [String] ID (as a string) of the guild to list the members for.
|
|
296
301
|
# @param limit [Integer, nil] Maximum number of members to return (1-100). Default: 1
|
|
297
302
|
# @param after [String, nil] Get users after this user ID (as a string)
|
|
@@ -303,14 +308,15 @@ class DiscordApi
|
|
|
303
308
|
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
304
309
|
url = "#{@base_url}/guilds/#{guild_id}/members#{query_string}"
|
|
305
310
|
headers = { 'Authorization': @authorization_header }
|
|
306
|
-
response =
|
|
307
|
-
return response if response.status == 200
|
|
311
|
+
response = get(url, headers)
|
|
312
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
308
313
|
|
|
309
|
-
@logger.error("Could not list members with Guild ID #{guild_id}. Response: #{response
|
|
314
|
+
@logger.error("Could not list members with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
|
|
310
315
|
response
|
|
311
316
|
end
|
|
312
317
|
|
|
313
|
-
# Returns an array of guild member objects whose username/nickname match the query.
|
|
318
|
+
# Returns an array of guild member objects whose username/nickname match the query.
|
|
319
|
+
# See https://discord.com/developers/docs/resources/guild#search-guild-members
|
|
314
320
|
# @param guild_id [String] ID (as a string) of the guild to search the members in
|
|
315
321
|
# @param query [String] Query string to match usernames and nicknames against.
|
|
316
322
|
# @param limit [Integer, nil] Maximum number of members to return (1-1000). Default: 1
|
|
@@ -322,15 +328,16 @@ class DiscordApi
|
|
|
322
328
|
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
323
329
|
url = "#{@base_url}/guilds/#{guild_id}/members/search#{query_string}"
|
|
324
330
|
headers = { 'Authorization': @authorization_header }
|
|
325
|
-
response =
|
|
326
|
-
return response if response.status == 200
|
|
331
|
+
response = get(url, headers)
|
|
332
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
327
333
|
|
|
328
|
-
@logger.error("Could not search members with Guild ID #{guild_id}. Response: #{response
|
|
334
|
+
@logger.error("Could not search members with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
|
|
329
335
|
response
|
|
330
336
|
end
|
|
331
337
|
|
|
332
338
|
# Adds a user to the specified guild. Returns 201 Created with the body being the Guild Member object of the added
|
|
333
|
-
# user or 204 No Content if the user is already in the guild.
|
|
339
|
+
# user or 204 No Content if the user is already in the guild.
|
|
340
|
+
# See https://discord.com/developers/docs/resources/guild#add-guild-member
|
|
334
341
|
# @param guild_id [String] ID (as a string) of the guild to add the user to
|
|
335
342
|
# @param user_id [String] ID (as a string) of the user to add to the guild
|
|
336
343
|
# @param access_token [String] A valid OAuth2 access token with the guilds.join scope created by the user you want to
|
|
@@ -350,13 +357,14 @@ class DiscordApi
|
|
|
350
357
|
url = "#{@base_url}/guilds/#{guild_id}/members/#{user_id}"
|
|
351
358
|
data = JSON.generate(output)
|
|
352
359
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
353
|
-
response =
|
|
354
|
-
if response.status == 204
|
|
360
|
+
response = put(url, data, headers)
|
|
361
|
+
if response.is_a?(Faraday::Response) && response.status == 204
|
|
355
362
|
@logger.warn("User with ID #{user_id} is already a member of the guild with ID #{guild_id}.")
|
|
356
|
-
elsif response.status == 201
|
|
363
|
+
elsif response.is_a?(Faraday::Response) && response.status == 201
|
|
357
364
|
@logger.info("Added user with ID #{user_id} to guild with ID #{guild_id}.")
|
|
358
365
|
else
|
|
359
|
-
@logger.error("Could not add user with ID #{user_id} to guild with ID #{guild_id}.
|
|
366
|
+
@logger.error("Could not add user with ID #{user_id} to guild with ID #{guild_id}." \
|
|
367
|
+
" Response: #{response_error_body(response)}")
|
|
360
368
|
end
|
|
361
369
|
response
|
|
362
370
|
end
|
|
@@ -403,11 +411,11 @@ class DiscordApi
|
|
|
403
411
|
data = JSON.generate(output)
|
|
404
412
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
405
413
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
406
|
-
response =
|
|
407
|
-
return response if response.status == 200
|
|
414
|
+
response = patch(url, data, headers)
|
|
415
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
408
416
|
|
|
409
417
|
@logger.error("Could not modify guild member with Guild ID #{guild_id} and User ID #{user_id}. " \
|
|
410
|
-
"Response: #{response
|
|
418
|
+
"Response: #{response_error_body(response)}")
|
|
411
419
|
response
|
|
412
420
|
end
|
|
413
421
|
|
|
@@ -440,10 +448,11 @@ class DiscordApi
|
|
|
440
448
|
end
|
|
441
449
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
442
450
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
443
|
-
response =
|
|
444
|
-
return response if response.status == 200
|
|
451
|
+
response = patch(url, data, headers)
|
|
452
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
445
453
|
|
|
446
|
-
@logger.error("Could not modify current member in guild with Guild ID #{guild_id}.
|
|
454
|
+
@logger.error("Could not modify current member in guild with Guild ID #{guild_id}." \
|
|
455
|
+
" Response: #{response_error_body(response)}")
|
|
447
456
|
response
|
|
448
457
|
end
|
|
449
458
|
|
|
@@ -462,10 +471,11 @@ class DiscordApi
|
|
|
462
471
|
data = JSON.generate(output)
|
|
463
472
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
464
473
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
465
|
-
response =
|
|
466
|
-
return response if response.status == 200
|
|
474
|
+
response = patch(url, data, headers)
|
|
475
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
467
476
|
|
|
468
|
-
@logger.error("Could not modify current user nick in guild with ID #{guild_id}.
|
|
477
|
+
@logger.error("Could not modify current user nick in guild with ID #{guild_id}." \
|
|
478
|
+
" Response: #{response_error_body(response)}")
|
|
469
479
|
response
|
|
470
480
|
end
|
|
471
481
|
|
|
@@ -480,11 +490,11 @@ class DiscordApi
|
|
|
480
490
|
url = "#{@base_url}/guilds/#{guild_id}/members/#{user_id}/roles/#{role_id}"
|
|
481
491
|
headers = { 'Authorization': @authorization_header }
|
|
482
492
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
483
|
-
response =
|
|
484
|
-
return response if response.status == 204
|
|
493
|
+
response = put(url, nil, headers)
|
|
494
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
485
495
|
|
|
486
496
|
@logger.error("Could not add role with ID #{role_id}, to user with ID #{user_id} in guild with ID #{guild_id}." \
|
|
487
|
-
" Response: #{response
|
|
497
|
+
" Response: #{response_error_body(response)}")
|
|
488
498
|
response
|
|
489
499
|
end
|
|
490
500
|
|
|
@@ -499,11 +509,11 @@ class DiscordApi
|
|
|
499
509
|
url = "#{@base_url}/guilds/#{guild_id}/members/#{user_id}/roles/#{role_id}"
|
|
500
510
|
headers = { 'Authorization': @authorization_header }
|
|
501
511
|
headers['x-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
502
|
-
response =
|
|
503
|
-
return response if response.status == 204
|
|
512
|
+
response = delete(url, headers)
|
|
513
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
504
514
|
|
|
505
515
|
@logger.error("Could not remove role with ID #{role_id}, from user with ID #{user_id}" \
|
|
506
|
-
" in guild with ID #{guild_id}. Response: #{response
|
|
516
|
+
" in guild with ID #{guild_id}. Response: #{response_error_body(response)}")
|
|
507
517
|
response
|
|
508
518
|
end
|
|
509
519
|
|
|
@@ -517,10 +527,11 @@ class DiscordApi
|
|
|
517
527
|
url = "#{@base_url}/guilds/#{guild_id}/members/#{user_id}"
|
|
518
528
|
headers = { 'Authorization' => @authorization_header }
|
|
519
529
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
520
|
-
response =
|
|
521
|
-
return response if response.status == 204
|
|
530
|
+
response = delete(url, headers)
|
|
531
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
522
532
|
|
|
523
|
-
@logger.error("Could not remove user with ID #{user_id} from guild with ID #{guild_id}.
|
|
533
|
+
@logger.error("Could not remove user with ID #{user_id} from guild with ID #{guild_id}." \
|
|
534
|
+
" Response: #{response_error_body(response)}")
|
|
524
535
|
response
|
|
525
536
|
end
|
|
526
537
|
|
|
@@ -539,10 +550,10 @@ class DiscordApi
|
|
|
539
550
|
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
540
551
|
url = "#{@base_url}/guilds/#{guild_id}/bans#{query_string}"
|
|
541
552
|
headers = { 'Authorization' => @authorization_header }
|
|
542
|
-
response =
|
|
543
|
-
return response if response.status == 200
|
|
553
|
+
response = get(url, headers)
|
|
554
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
544
555
|
|
|
545
|
-
@logger.error("Could not get guild bans with Guild ID #{guild_id}. Response: #{response
|
|
556
|
+
@logger.error("Could not get guild bans with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
|
|
546
557
|
response
|
|
547
558
|
end
|
|
548
559
|
|
|
@@ -554,14 +565,14 @@ class DiscordApi
|
|
|
554
565
|
def get_guild_ban(guild_id, user_id)
|
|
555
566
|
url = "#{@base_url}/guilds/#{guild_id}/bans/#{user_id}"
|
|
556
567
|
headers = { 'Authorization': @authorization_header }
|
|
557
|
-
response =
|
|
558
|
-
return response if response.status == 200
|
|
568
|
+
response = get(url, headers)
|
|
569
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
559
570
|
|
|
560
|
-
if response.status == 404
|
|
571
|
+
if response.is_a?(Faraday::Response) && response.status == 404
|
|
561
572
|
@logger.warn("No ban found for user with ID #{user_id} in guild with ID #{guild_id}.")
|
|
562
573
|
else
|
|
563
574
|
@logger.error("Could not get guild ban for user with ID #{user_id} in guild with ID #{guild_id}." \
|
|
564
|
-
" Response: #{response
|
|
575
|
+
" Response: #{response_error_body(response)}")
|
|
565
576
|
end
|
|
566
577
|
response
|
|
567
578
|
end
|
|
@@ -586,11 +597,11 @@ class DiscordApi
|
|
|
586
597
|
data = JSON.generate(output)
|
|
587
598
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
588
599
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
589
|
-
response =
|
|
590
|
-
return response if response.status == 204
|
|
600
|
+
response = put(url, data, headers)
|
|
601
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
591
602
|
|
|
592
603
|
@logger.error("Could not create guild ban for user with ID #{user_id} in guild with ID #{guild_id}." \
|
|
593
|
-
" Response: #{response
|
|
604
|
+
" Response: #{response_error_body(response)}")
|
|
594
605
|
response
|
|
595
606
|
end
|
|
596
607
|
|
|
@@ -604,11 +615,11 @@ class DiscordApi
|
|
|
604
615
|
url = "#{@base_url}/guilds/#{guild_id}/bans/#{user_id}"
|
|
605
616
|
headers = { 'Authorization': @authorization_header }
|
|
606
617
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
607
|
-
response =
|
|
608
|
-
return response if response.status == 204
|
|
618
|
+
response = delete(url, headers)
|
|
619
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
609
620
|
|
|
610
621
|
@logger.error("Could not remove guild ban for user with ID #{user_id} in guild with ID #{guild_id}" \
|
|
611
|
-
" Response: #{response
|
|
622
|
+
" Response: #{response_error_body(response)}")
|
|
612
623
|
response
|
|
613
624
|
end
|
|
614
625
|
|
|
@@ -628,13 +639,14 @@ class DiscordApi
|
|
|
628
639
|
data = JSON.generate(output)
|
|
629
640
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
630
641
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
631
|
-
response =
|
|
632
|
-
return response if response.status == 200
|
|
642
|
+
response = post(url, data, headers)
|
|
643
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
633
644
|
|
|
634
|
-
if response.status == 500_000
|
|
635
|
-
@logger.error("No users were banned in bulk ban in guild with ID #{guild_id}.
|
|
645
|
+
if response.is_a?(Faraday::Response) && response.status == 500_000
|
|
646
|
+
@logger.error("No users were banned in bulk ban in guild with ID #{guild_id}." \
|
|
647
|
+
" Response: #{response_error_body(response)}")
|
|
636
648
|
else
|
|
637
|
-
@logger.error("Could not bulk ban users in guild with ID #{guild_id}. Response: #{response
|
|
649
|
+
@logger.error("Could not bulk ban users in guild with ID #{guild_id}. Response: #{response_error_body(response)}")
|
|
638
650
|
end
|
|
639
651
|
response
|
|
640
652
|
end
|
|
@@ -646,10 +658,10 @@ class DiscordApi
|
|
|
646
658
|
def get_guild_roles(guild_id)
|
|
647
659
|
url = "#{@base_url}/guilds/#{guild_id}/roles"
|
|
648
660
|
headers = { 'Authorization': @authorization_header }
|
|
649
|
-
response =
|
|
650
|
-
return response if response.status == 200
|
|
661
|
+
response = get(url, headers)
|
|
662
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
651
663
|
|
|
652
|
-
@logger.error("Could not get guild roles with Guild ID #{guild_id}. Response: #{response
|
|
664
|
+
@logger.error("Could not get guild roles with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
|
|
653
665
|
response
|
|
654
666
|
end
|
|
655
667
|
|
|
@@ -661,10 +673,11 @@ class DiscordApi
|
|
|
661
673
|
def get_guild_role(guild_id, role_id)
|
|
662
674
|
url = "#{@base_url}/guilds/#{guild_id}/roles/#{role_id}"
|
|
663
675
|
headers = { 'Authorization': @authorization_header }
|
|
664
|
-
response =
|
|
665
|
-
return response if response.status == 200
|
|
676
|
+
response = get(url, headers)
|
|
677
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
666
678
|
|
|
667
|
-
@logger.error("Could not get role with ID #{role_id} in guild with ID #{guild_id}.
|
|
679
|
+
@logger.error("Could not get role with ID #{role_id} in guild with ID #{guild_id}." \
|
|
680
|
+
" Response: #{response_error_body(response)}")
|
|
668
681
|
response
|
|
669
682
|
end
|
|
670
683
|
|
|
@@ -701,10 +714,11 @@ class DiscordApi
|
|
|
701
714
|
data = JSON.generate(output)
|
|
702
715
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
703
716
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
704
|
-
response =
|
|
705
|
-
return response if response.status == 200
|
|
717
|
+
response = post(url, data, headers)
|
|
718
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
706
719
|
|
|
707
|
-
@logger.error("Could not create guild role in guild with ID #{guild_id}.
|
|
720
|
+
@logger.error("Could not create guild role in guild with ID #{guild_id}." \
|
|
721
|
+
"Response: #{response_error_body(response)}")
|
|
708
722
|
response
|
|
709
723
|
end
|
|
710
724
|
|
|
@@ -728,10 +742,11 @@ class DiscordApi
|
|
|
728
742
|
data = JSON.generate(role_positions)
|
|
729
743
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
730
744
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
731
|
-
response =
|
|
732
|
-
return response if response.status == 200
|
|
745
|
+
response = patch(url, data, headers)
|
|
746
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
733
747
|
|
|
734
|
-
@logger.error("Could not modify guild role positions in guild with ID #{guild_id}.
|
|
748
|
+
@logger.error("Could not modify guild role positions in guild with ID #{guild_id}." \
|
|
749
|
+
" Response: #{response_error_body(response)}")
|
|
735
750
|
response
|
|
736
751
|
end
|
|
737
752
|
|
|
@@ -769,11 +784,11 @@ class DiscordApi
|
|
|
769
784
|
data = JSON.generate(output)
|
|
770
785
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
771
786
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
772
|
-
response =
|
|
773
|
-
return response if response.status == 200
|
|
787
|
+
response = patch(url, data, headers)
|
|
788
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
774
789
|
|
|
775
790
|
@logger.error("Could not modify guild role with ID #{role_id} in guild with ID #{guild_id}." \
|
|
776
|
-
" Response: #{response
|
|
791
|
+
" Response: #{response_error_body(response)}")
|
|
777
792
|
response
|
|
778
793
|
end
|
|
779
794
|
|
|
@@ -790,10 +805,10 @@ class DiscordApi
|
|
|
790
805
|
data = JSON.generate(output)
|
|
791
806
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
792
807
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
793
|
-
response =
|
|
794
|
-
return
|
|
808
|
+
response = post(url, data, headers)
|
|
809
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
795
810
|
|
|
796
|
-
@logger.error("Failed to modify guild MFA level. Response: #{response
|
|
811
|
+
@logger.error("Failed to modify guild MFA level. Response: #{response_error_body(response)}")
|
|
797
812
|
response
|
|
798
813
|
end
|
|
799
814
|
|
|
@@ -807,10 +822,10 @@ class DiscordApi
|
|
|
807
822
|
url = "#{@base_url}/guilds/#{guild_id}/roles/#{role_id}"
|
|
808
823
|
headers = { 'Authorization': @authorization_header }
|
|
809
824
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
810
|
-
response =
|
|
811
|
-
return response if response.status == 204
|
|
825
|
+
response = delete(url, headers)
|
|
826
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
812
827
|
|
|
813
|
-
@logger.error("Failed to delete guild role. Response: #{response
|
|
828
|
+
@logger.error("Failed to delete guild role. Response: #{response_error_body(response)}")
|
|
814
829
|
response
|
|
815
830
|
end
|
|
816
831
|
|
|
@@ -828,10 +843,10 @@ class DiscordApi
|
|
|
828
843
|
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
829
844
|
url = "#{@base_url}/guilds/#{guild_id}/prune#{query_string}"
|
|
830
845
|
headers = { 'Authorization': @authorization_header }
|
|
831
|
-
response =
|
|
832
|
-
return response if response.status == 200
|
|
846
|
+
response = get(url, headers)
|
|
847
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
833
848
|
|
|
834
|
-
@logger.error("Failed to get guild prune count. Response: #{response
|
|
849
|
+
@logger.error("Failed to get guild prune count. Response: #{response_error_body(response)}")
|
|
835
850
|
response
|
|
836
851
|
end
|
|
837
852
|
|
|
@@ -861,10 +876,10 @@ class DiscordApi
|
|
|
861
876
|
data = JSON.generate(output)
|
|
862
877
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
863
878
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
864
|
-
response =
|
|
865
|
-
return response if response.status == 200
|
|
879
|
+
response = post(url, data, headers)
|
|
880
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
866
881
|
|
|
867
|
-
@logger.error("Failed to begin guild prune. Response: #{response
|
|
882
|
+
@logger.error("Failed to begin guild prune. Response: #{response_error_body(response)}")
|
|
868
883
|
response
|
|
869
884
|
end
|
|
870
885
|
|
|
@@ -875,10 +890,10 @@ class DiscordApi
|
|
|
875
890
|
def get_guild_voice_regions(guild_id)
|
|
876
891
|
url = "#{@base_url}/guilds/#{guild_id}/regions"
|
|
877
892
|
headers = { 'Authorization': @authorization_header }
|
|
878
|
-
response =
|
|
879
|
-
return response if response.status == 200
|
|
893
|
+
response = get(url, headers)
|
|
894
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
880
895
|
|
|
881
|
-
@logger.error("Failed to get guild voice regions. Response: #{response
|
|
896
|
+
@logger.error("Failed to get guild voice regions. Response: #{response_error_body(response)}")
|
|
882
897
|
response
|
|
883
898
|
end
|
|
884
899
|
|
|
@@ -889,10 +904,10 @@ class DiscordApi
|
|
|
889
904
|
def get_guild_invites(guild_id)
|
|
890
905
|
url = "#{@base_url}/guilds/#{guild_id}/invites"
|
|
891
906
|
headers = { 'Authorization': @authorization_header }
|
|
892
|
-
response =
|
|
893
|
-
return response if response.status == 200
|
|
907
|
+
response = get(url, headers)
|
|
908
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
894
909
|
|
|
895
|
-
@logger.error("Failed to get guild invites. Response: #{response
|
|
910
|
+
@logger.error("Failed to get guild invites. Response: #{response_error_body(response)}")
|
|
896
911
|
response
|
|
897
912
|
end
|
|
898
913
|
|
|
@@ -903,15 +918,15 @@ class DiscordApi
|
|
|
903
918
|
def get_guild_integrations(guild_id)
|
|
904
919
|
url = "#{@base_url}/guilds/#{guild_id}/integrations"
|
|
905
920
|
headers = { 'Authorization': @authorization_header }
|
|
906
|
-
response =
|
|
907
|
-
if response.status == 200
|
|
921
|
+
response = get(url, headers)
|
|
922
|
+
if response.is_a?(Faraday::Response) && response.status == 200
|
|
908
923
|
if JSON.parse(response.body).length == 50
|
|
909
924
|
@logger.warn('The endpoint returned 50 integrations, which means there could be more integrations not shown.')
|
|
910
925
|
end
|
|
911
926
|
return response
|
|
912
927
|
end
|
|
913
928
|
|
|
914
|
-
@logger.error("Failed to get guild integrations. Response: #{response
|
|
929
|
+
@logger.error("Failed to get guild integrations. Response: #{response_error_body(response)}")
|
|
915
930
|
response
|
|
916
931
|
end
|
|
917
932
|
|
|
@@ -925,10 +940,10 @@ class DiscordApi
|
|
|
925
940
|
url = "#{@base_url}/guilds/#{guild_id}/integrations/#{integration_id}"
|
|
926
941
|
headers = { 'Authorization': @authorization_header }
|
|
927
942
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
928
|
-
response =
|
|
929
|
-
return response if response.status == 204
|
|
943
|
+
response = delete(url, headers)
|
|
944
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
930
945
|
|
|
931
|
-
@logger.error("Failed to delete guild integration. Response: #{response
|
|
946
|
+
@logger.error("Failed to delete guild integration. Response: #{response_error_body(response)}")
|
|
932
947
|
response
|
|
933
948
|
end
|
|
934
949
|
|
|
@@ -939,10 +954,10 @@ class DiscordApi
|
|
|
939
954
|
def get_guild_widget_settings(guild_id)
|
|
940
955
|
url = "#{@base_url}/guilds/#{guild_id}/widget"
|
|
941
956
|
headers = { 'Authorization': @authorization_header }
|
|
942
|
-
response =
|
|
943
|
-
return response if response.status == 200
|
|
957
|
+
response = get(url, headers)
|
|
958
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
944
959
|
|
|
945
|
-
@logger.error("Failed to get guild widget settings. Response: #{response
|
|
960
|
+
@logger.error("Failed to get guild widget settings. Response: #{response_error_body(response)}")
|
|
946
961
|
response
|
|
947
962
|
end
|
|
948
963
|
|
|
@@ -962,10 +977,10 @@ class DiscordApi
|
|
|
962
977
|
data = JSON.generate(output)
|
|
963
978
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
964
979
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
965
|
-
response =
|
|
966
|
-
return response if response.status == 200
|
|
980
|
+
response = patch(url, data, headers)
|
|
981
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
967
982
|
|
|
968
|
-
@logger.error("Failed to modify guild widget. Response: #{response
|
|
983
|
+
@logger.error("Failed to modify guild widget. Response: #{response_error_body(response)}")
|
|
969
984
|
response
|
|
970
985
|
end
|
|
971
986
|
|
|
@@ -976,10 +991,10 @@ class DiscordApi
|
|
|
976
991
|
def get_guild_widget(guild_id)
|
|
977
992
|
url = "#{@base_url}/guilds/#{guild_id}/widget.json"
|
|
978
993
|
headers = { 'Authorization': @authorization_header }
|
|
979
|
-
response =
|
|
980
|
-
return response if response.status == 200
|
|
994
|
+
response = get(url, headers)
|
|
995
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
981
996
|
|
|
982
|
-
@logger.error("Failed to get guild widget. Response: #{response
|
|
997
|
+
@logger.error("Failed to get guild widget. Response: #{response_error_body(response)}")
|
|
983
998
|
response
|
|
984
999
|
end
|
|
985
1000
|
|
|
@@ -990,10 +1005,10 @@ class DiscordApi
|
|
|
990
1005
|
def get_guild_vanity_url(guild_id)
|
|
991
1006
|
url = "#{@base_url}/guilds/#{guild_id}/vanity-url"
|
|
992
1007
|
headers = { 'Authorization': @authorization_header }
|
|
993
|
-
response =
|
|
994
|
-
return response if response.status == 200
|
|
1008
|
+
response = get(url, headers)
|
|
1009
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
995
1010
|
|
|
996
|
-
@logger.error("Failed to get guild vanity URL. Response: #{response
|
|
1011
|
+
@logger.error("Failed to get guild vanity URL. Response: #{response_error_body(response)}")
|
|
997
1012
|
response
|
|
998
1013
|
end
|
|
999
1014
|
|
|
@@ -1027,10 +1042,10 @@ class DiscordApi
|
|
|
1027
1042
|
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
1028
1043
|
|
|
1029
1044
|
url = "#{@base_url}/guilds/#{guild_id}/widget.png#{query_string}"
|
|
1030
|
-
response =
|
|
1031
|
-
return
|
|
1045
|
+
response = get(url)
|
|
1046
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
1032
1047
|
|
|
1033
|
-
@logger.error("Failed to get guild widget image. Response: #{response
|
|
1048
|
+
@logger.error("Failed to get guild widget image. Response: #{response_error_body(response)}")
|
|
1034
1049
|
response
|
|
1035
1050
|
end
|
|
1036
1051
|
|
|
@@ -1041,10 +1056,10 @@ class DiscordApi
|
|
|
1041
1056
|
def get_guild_welcome_screen(guild_id)
|
|
1042
1057
|
url = "#{@base_url}/guilds/#{guild_id}/welcome-screen"
|
|
1043
1058
|
headers = { 'Authorization': @authorization_header }
|
|
1044
|
-
response =
|
|
1045
|
-
return response if response.status == 200
|
|
1059
|
+
response = get(url, headers)
|
|
1060
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
1046
1061
|
|
|
1047
|
-
@logger.error("Failed to get guild welcome screen. Response: #{response
|
|
1062
|
+
@logger.error("Failed to get guild welcome screen. Response: #{response_error_body(response)}")
|
|
1048
1063
|
response
|
|
1049
1064
|
end
|
|
1050
1065
|
|
|
@@ -1074,10 +1089,10 @@ class DiscordApi
|
|
|
1074
1089
|
data = JSON.generate(output)
|
|
1075
1090
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
1076
1091
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
1077
|
-
response =
|
|
1078
|
-
return response if response.status == 200
|
|
1092
|
+
response = patch(url, data, headers)
|
|
1093
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
1079
1094
|
|
|
1080
|
-
@logger.error("Failed to modify guild welcome screen. Response: #{response
|
|
1095
|
+
@logger.error("Failed to modify guild welcome screen. Response: #{response_error_body(response)}")
|
|
1081
1096
|
response
|
|
1082
1097
|
end
|
|
1083
1098
|
|
|
@@ -1088,10 +1103,10 @@ class DiscordApi
|
|
|
1088
1103
|
def get_guild_onboarding(guild_id)
|
|
1089
1104
|
url = "#{@base_url}/guilds/#{guild_id}/onboarding"
|
|
1090
1105
|
headers = { 'Authorization': @authorization_header }
|
|
1091
|
-
response =
|
|
1092
|
-
return response if response.status == 200
|
|
1106
|
+
response = get(url, headers)
|
|
1107
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
1093
1108
|
|
|
1094
|
-
@logger.error("Failed to get guild onboarding. Response: #{response
|
|
1109
|
+
@logger.error("Failed to get guild onboarding. Response: #{response_error_body(response)}")
|
|
1095
1110
|
response
|
|
1096
1111
|
end
|
|
1097
1112
|
|
|
@@ -1123,10 +1138,10 @@ class DiscordApi
|
|
|
1123
1138
|
data = JSON.generate(output)
|
|
1124
1139
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
1125
1140
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
1126
|
-
response =
|
|
1127
|
-
return response if response.status == 200
|
|
1141
|
+
response = put(url, data, headers)
|
|
1142
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
1128
1143
|
|
|
1129
|
-
@logger.error("Failed to modify guild onboarding. Response: #{response
|
|
1144
|
+
@logger.error("Failed to modify guild onboarding. Response: #{response_error_body(response)}")
|
|
1130
1145
|
response
|
|
1131
1146
|
end
|
|
1132
1147
|
|
|
@@ -1160,10 +1175,10 @@ class DiscordApi
|
|
|
1160
1175
|
url = "#{@base_url}/guilds/#{guild_id}/incident-actions"
|
|
1161
1176
|
data = JSON.generate(output)
|
|
1162
1177
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
1163
|
-
response =
|
|
1164
|
-
return response if response.status == 200
|
|
1178
|
+
response = put(url, data, headers)
|
|
1179
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
1165
1180
|
|
|
1166
|
-
@logger.error("Failed to modify guild incident actions. Response: #{response
|
|
1181
|
+
@logger.error("Failed to modify guild incident actions. Response: #{response_error_body(response)}")
|
|
1167
1182
|
response
|
|
1168
1183
|
end
|
|
1169
1184
|
end
|