disrb 0.1.3 → 0.1.4.1
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 +27 -0
- data/LICENSE +1 -1
- data/README.md +20 -8
- data/lib/disrb/application_commands.rb +53 -45
- data/lib/disrb/guild.rb +162 -147
- data/lib/disrb/message.rb +92 -66
- data/lib/disrb/user.rb +36 -35
- data/lib/disrb.rb +211 -63
- data/lib/version.rb +6 -0
- metadata +30 -1
data/lib/disrb/message.rb
CHANGED
|
@@ -33,10 +33,11 @@ class DiscordApi
|
|
|
33
33
|
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
34
34
|
url = "#{@base_url}/channels/#{channel_id}/messages#{query_string}"
|
|
35
35
|
headers = { 'Authorization': @authorization_header }
|
|
36
|
-
response =
|
|
37
|
-
return response if response.status == 200
|
|
36
|
+
response = get(url, headers)
|
|
37
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
38
38
|
|
|
39
|
-
@logger.error("Failed to get messages from channel with ID #{channel_id}.
|
|
39
|
+
@logger.error("Failed to get messages from channel with ID #{channel_id}." \
|
|
40
|
+
" Response: #{response_error_body(response)}")
|
|
40
41
|
response
|
|
41
42
|
end
|
|
42
43
|
|
|
@@ -48,11 +49,11 @@ class DiscordApi
|
|
|
48
49
|
def get_channel_message(channel_id, message_id)
|
|
49
50
|
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}"
|
|
50
51
|
headers = { 'Authorization': @authorization_header }
|
|
51
|
-
response =
|
|
52
|
-
return response if response.status == 200
|
|
52
|
+
response = get(url, headers)
|
|
53
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
53
54
|
|
|
54
55
|
@logger.error("Failed to get message with ID #{message_id} from channel with ID #{channel_id}. " \
|
|
55
|
-
"Response: #{response
|
|
56
|
+
"Response: #{response_error_body(response)}")
|
|
56
57
|
response
|
|
57
58
|
end
|
|
58
59
|
|
|
@@ -70,21 +71,26 @@ class DiscordApi
|
|
|
70
71
|
# @param message_reference [Hash, nil] Message reference object for replies/forwards
|
|
71
72
|
# @param components [Array, nil] An array of Components to include with the message
|
|
72
73
|
# @param sticker_ids [Array, nil] IDs of up to 3 stickers in the server to send in the message
|
|
73
|
-
# @param
|
|
74
|
-
#
|
|
75
|
-
#
|
|
74
|
+
# @param files [Array, nil] An array of arrays, each inner-array first has its filename (index 0),
|
|
75
|
+
# raw file data as a string (index 1), and then the MIME type of the file (index 2).
|
|
76
|
+
# @param attachments [Array, nil] Array of partial attachment objects, if left empty but the files parameter is
|
|
77
|
+
# not empty, this will be automatically generated.
|
|
76
78
|
# @param flags [Integer, nil] Message flags combined as a bitfield.
|
|
77
79
|
# @param enforce_nonce [TrueClass, FalseClass, nil] If true and a nonce is set, the nonce's uniqueness will be
|
|
78
80
|
# checked, if a message with the same nonce already exists from the same author, that message will be returned
|
|
79
81
|
# and no new message will be created.
|
|
80
82
|
# @param poll [Hash, nil] A poll object
|
|
83
|
+
# @param shared_client_theme [Hash, nil] THe custom client-side theme to share via the message;
|
|
84
|
+
# shared client theme object
|
|
81
85
|
# @return [Faraday::Response, nil] The response from the Discord API as a Faraday::Response object, or nil if none of
|
|
82
86
|
# content, embeds, sticker_ids, components or poll were provided.
|
|
83
87
|
def create_message(channel_id, content: nil, nonce: nil, tts: nil, embeds: nil, allowed_mentions: nil,
|
|
84
|
-
message_reference: nil, components: nil, sticker_ids: nil,
|
|
85
|
-
flags: nil, enforce_nonce: nil, poll: nil)
|
|
86
|
-
if content.nil? && embeds.nil? && sticker_ids.nil? && components.nil? && poll.nil?
|
|
87
|
-
|
|
88
|
+
message_reference: nil, components: nil, sticker_ids: nil, files: nil, attachments: nil,
|
|
89
|
+
flags: nil, enforce_nonce: nil, poll: nil, shared_client_theme: nil)
|
|
90
|
+
if content.nil? && embeds.nil? && sticker_ids.nil? && components.nil? && files.nil? && poll.nil? &&
|
|
91
|
+
shared_client_theme.nil?
|
|
92
|
+
@logger.warn('No content, embeds, sticker_ids, components, files, poll or shared client theme provided.' \
|
|
93
|
+
'Skipping function.')
|
|
88
94
|
return
|
|
89
95
|
end
|
|
90
96
|
output = {}
|
|
@@ -96,18 +102,27 @@ class DiscordApi
|
|
|
96
102
|
output[:message_reference] = message_reference unless message_reference.nil?
|
|
97
103
|
output[:components] = components unless components.nil?
|
|
98
104
|
output[:sticker_ids] = sticker_ids unless sticker_ids.nil?
|
|
99
|
-
|
|
100
|
-
|
|
105
|
+
if attachments.nil? && !files.nil?
|
|
106
|
+
output[:attachments] = generate_attachment_object_array(files)
|
|
107
|
+
elsif attachments
|
|
108
|
+
output[:attachments] = attachments
|
|
109
|
+
end
|
|
101
110
|
output[:flags] = flags unless flags.nil?
|
|
102
111
|
output[:enforce_nonce] = enforce_nonce unless enforce_nonce.nil?
|
|
103
112
|
output[:poll] = poll unless poll.nil?
|
|
113
|
+
output[:shared_client_theme] = shared_client_theme unless shared_client_theme.nil?
|
|
104
114
|
url = "#{@base_url}/channels/#{channel_id}/messages"
|
|
105
115
|
data = JSON.generate(output)
|
|
106
|
-
headers = { 'Authorization': @authorization_header
|
|
107
|
-
|
|
108
|
-
|
|
116
|
+
headers = { 'Authorization': @authorization_header }
|
|
117
|
+
if files
|
|
118
|
+
response = file_upload(url, files, payload_json: data, headers: headers)
|
|
119
|
+
else
|
|
120
|
+
headers['Content-Type'] = 'application/json'
|
|
121
|
+
response = post(url, data, headers)
|
|
122
|
+
end
|
|
123
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
109
124
|
|
|
110
|
-
@logger.error("Failed to create message in channel #{channel_id}. Response: #{response
|
|
125
|
+
@logger.error("Failed to create message in channel #{channel_id}. Response: #{response_error_body(response)}")
|
|
111
126
|
response
|
|
112
127
|
end
|
|
113
128
|
|
|
@@ -119,11 +134,11 @@ class DiscordApi
|
|
|
119
134
|
def crosspost_message(channel_id, message_id)
|
|
120
135
|
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}/crosspost"
|
|
121
136
|
headers = { 'Authorization': @authorization_header }
|
|
122
|
-
response =
|
|
123
|
-
return response if response.status == 200
|
|
137
|
+
response = post(url, nil, headers)
|
|
138
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
124
139
|
|
|
125
140
|
@logger.error("Failed to crosspost message with ID #{message_id} in channel with ID #{channel_id}. " \
|
|
126
|
-
"Response: #{response
|
|
141
|
+
"Response: #{response_error_body(response)}")
|
|
127
142
|
response
|
|
128
143
|
end
|
|
129
144
|
|
|
@@ -136,11 +151,11 @@ class DiscordApi
|
|
|
136
151
|
def create_reaction(channel_id, message_id, emoji)
|
|
137
152
|
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/@me"
|
|
138
153
|
headers = { 'Authorization': @authorization_header }
|
|
139
|
-
response =
|
|
140
|
-
return response if response.status == 204
|
|
154
|
+
response = put(url, nil, headers)
|
|
155
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
141
156
|
|
|
142
157
|
@logger.error("Failed to create reaction with emoji ID #{emoji} in channel with ID #{channel_id} " \
|
|
143
|
-
"for message with ID #{message_id}. Response: #{response
|
|
158
|
+
"for message with ID #{message_id}. Response: #{response_error_body(response)}")
|
|
144
159
|
response
|
|
145
160
|
end
|
|
146
161
|
|
|
@@ -153,11 +168,11 @@ class DiscordApi
|
|
|
153
168
|
def delete_own_reaction(channel_id, message_id, emoji)
|
|
154
169
|
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/@me"
|
|
155
170
|
headers = { 'Authorization': @authorization_header }
|
|
156
|
-
response =
|
|
157
|
-
return response if response.status == 204
|
|
171
|
+
response = delete(url, headers)
|
|
172
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
158
173
|
|
|
159
174
|
@logger.error("Failed to delete own reaction with emoji ID #{emoji} in channel with ID #{channel_id} " \
|
|
160
|
-
"for message with ID #{message_id}. Response: #{response
|
|
175
|
+
"for message with ID #{message_id}. Response: #{response_error_body(response)}")
|
|
161
176
|
response
|
|
162
177
|
end
|
|
163
178
|
|
|
@@ -171,11 +186,12 @@ class DiscordApi
|
|
|
171
186
|
def delete_user_reaction(channel_id, message_id, emoji, user_id)
|
|
172
187
|
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/#{user_id}"
|
|
173
188
|
headers = { 'Authorization': @authorization_header }
|
|
174
|
-
response =
|
|
175
|
-
return response if response.status == 204
|
|
189
|
+
response = delete(url, headers)
|
|
190
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
176
191
|
|
|
177
192
|
@logger.error("Failed to delete user reaction with emoji ID #{emoji} in channel with ID #{channel_id} " \
|
|
178
|
-
"for message with ID #{message_id} by user with ID #{user_id}.
|
|
193
|
+
"for message with ID #{message_id} by user with ID #{user_id}." \
|
|
194
|
+
" Response: #{response_error_body(response)}")
|
|
179
195
|
response
|
|
180
196
|
end
|
|
181
197
|
|
|
@@ -196,11 +212,11 @@ class DiscordApi
|
|
|
196
212
|
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
197
213
|
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}#{query_string}"
|
|
198
214
|
headers = { 'Authorization': @authorization_header }
|
|
199
|
-
response =
|
|
200
|
-
return response if response.status == 200
|
|
215
|
+
response = get(url, headers)
|
|
216
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
201
217
|
|
|
202
218
|
@logger.error("Failed to get reactions for emoji with ID #{emoji} in channel with ID #{channel_id} " \
|
|
203
|
-
"for message with ID #{message_id}. Response: #{response
|
|
219
|
+
"for message with ID #{message_id}. Response: #{response_error_body(response)}")
|
|
204
220
|
response
|
|
205
221
|
end
|
|
206
222
|
|
|
@@ -212,11 +228,11 @@ class DiscordApi
|
|
|
212
228
|
def delete_all_reactions(channel_id, message_id)
|
|
213
229
|
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}/reactions"
|
|
214
230
|
headers = { 'Authorization': @authorization_header }
|
|
215
|
-
response =
|
|
216
|
-
return response if response.status == 204
|
|
231
|
+
response = delete(url, headers)
|
|
232
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
217
233
|
|
|
218
234
|
@logger.error("Failed to delete all reactions in channel with ID #{channel_id} for message with ID #{message_id}" \
|
|
219
|
-
". Response: #{response
|
|
235
|
+
". Response: #{response_error_body(response)}")
|
|
220
236
|
end
|
|
221
237
|
|
|
222
238
|
# Deletes all reactions with the specified emoji on a message. Returns no content on success.
|
|
@@ -228,18 +244,17 @@ class DiscordApi
|
|
|
228
244
|
def delete_all_reactions_for_emoji(channel_id, message_id, emoji)
|
|
229
245
|
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}"
|
|
230
246
|
headers = { 'Authorization': @authorization_header }
|
|
231
|
-
response =
|
|
232
|
-
return response if response.status == 204
|
|
247
|
+
response = delete(url, headers)
|
|
248
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
233
249
|
|
|
234
250
|
@logger.error("Failed to delete all reactions for emoji with ID #{emoji} in channel with ID #{channel_id} for " \
|
|
235
|
-
"message with ID #{message_id}. Response: #{response
|
|
251
|
+
"message with ID #{message_id}. Response: #{response_error_body(response)}")
|
|
236
252
|
end
|
|
237
253
|
|
|
238
254
|
# Edits a message. Returns the edited message object on success.
|
|
239
255
|
# See https://discord.com/developers/docs/resources/message#edit-message
|
|
240
256
|
#
|
|
241
257
|
# If none of the optional parameters are provided (modifications), the function will not proceed and return nil.
|
|
242
|
-
# Since the files parameter is WIP, providing only files will also cause the function to not proceed.
|
|
243
258
|
# @param channel_id [String] The ID of the channel the message is located in
|
|
244
259
|
# @param message_id [String] The ID of the message to edit
|
|
245
260
|
# @param content [String, nil] Message contents (up to 2000 characters)
|
|
@@ -247,16 +262,17 @@ class DiscordApi
|
|
|
247
262
|
# @param flags [Integer, nil] Message flags combined as an integer.
|
|
248
263
|
# @param allowed_mentions [Hash, nil] Allowed mentions object
|
|
249
264
|
# @param components [Array, nil] An array of Components to include with the message
|
|
250
|
-
# @param files [
|
|
251
|
-
#
|
|
252
|
-
#
|
|
265
|
+
# @param files [Array] An array of arrays, each inner-array first has its filename (index 0),
|
|
266
|
+
# raw file data as a string (index 1), and then the MIME type of the file (index 2).
|
|
267
|
+
# @param attachments [Array, nil] Array of partial attachment objects, if left empty but the files parameter is
|
|
268
|
+
# not empty, this will be automatically generated.
|
|
253
269
|
# @return [Faraday::Response, nil] The response from the Discord API as a Faraday::Response object, or nil if no
|
|
254
270
|
# modifications were provided.
|
|
255
271
|
def edit_message(channel_id, message_id, content: nil, embeds: nil, flags: nil, allowed_mentions: nil,
|
|
256
272
|
components: nil, files: nil, attachments: nil)
|
|
257
|
-
if args[2..].all?(&:nil?)
|
|
273
|
+
if args[2..].all?(&:nil?)
|
|
258
274
|
@logger.warn("No modifications provided for message with ID #{message_id} in channel with ID #{channel_id}. " \
|
|
259
|
-
|
|
275
|
+
'Skipping function.')
|
|
260
276
|
return
|
|
261
277
|
end
|
|
262
278
|
output = {}
|
|
@@ -265,16 +281,24 @@ class DiscordApi
|
|
|
265
281
|
output[:flags] = flags unless flags.nil?
|
|
266
282
|
output[:allowed_mentions] = allowed_mentions unless allowed_mentions.nil?
|
|
267
283
|
output[:components] = components unless components.nil?
|
|
268
|
-
|
|
269
|
-
|
|
284
|
+
if attachments.nil? && !files.nil?
|
|
285
|
+
output[:attachments] = generate_attachment_object_array(files)
|
|
286
|
+
elsif attachments
|
|
287
|
+
output[:attachments] = attachments
|
|
288
|
+
end
|
|
270
289
|
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}"
|
|
271
290
|
data = JSON.generate(output)
|
|
272
291
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
273
|
-
|
|
274
|
-
|
|
292
|
+
if files
|
|
293
|
+
response = file_upload(url, files, headers: headers, payload_json: data, request_type: :patch)
|
|
294
|
+
else
|
|
295
|
+
headers['Content-Type'] = 'application/json'
|
|
296
|
+
response = patch(url, data, headers)
|
|
297
|
+
end
|
|
298
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
275
299
|
|
|
276
300
|
@logger.error("Failed to edit message with ID #{message_id} in channel with ID #{channel_id}. " \
|
|
277
|
-
"Response: #{response
|
|
301
|
+
"Response: #{response_error_body(response)}")
|
|
278
302
|
response
|
|
279
303
|
end
|
|
280
304
|
|
|
@@ -288,11 +312,11 @@ class DiscordApi
|
|
|
288
312
|
url = "#{@base_url}/channels/#{channel_id}/messages/#{message_id}"
|
|
289
313
|
headers = { 'Authorization': @authorization_header }
|
|
290
314
|
headers[:'X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
291
|
-
response =
|
|
292
|
-
return response if response.status == 204
|
|
315
|
+
response = delete(url, headers)
|
|
316
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
293
317
|
|
|
294
318
|
@logger.error("Failed to delete message with ID #{message_id} in channel with ID #{channel_id}. " \
|
|
295
|
-
"Response: #{response
|
|
319
|
+
"Response: #{response_error_body(response)}")
|
|
296
320
|
response
|
|
297
321
|
end
|
|
298
322
|
|
|
@@ -308,10 +332,11 @@ class DiscordApi
|
|
|
308
332
|
data = JSON.generate(output)
|
|
309
333
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
310
334
|
headers[:'X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
311
|
-
response =
|
|
312
|
-
return response if response.status == 204
|
|
335
|
+
response = post(url, data, headers)
|
|
336
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
313
337
|
|
|
314
|
-
@logger.error("Failed to bulk delete messages in channel with ID #{channel_id}.
|
|
338
|
+
@logger.error("Failed to bulk delete messages in channel with ID #{channel_id}." \
|
|
339
|
+
" Response: #{response_error_body(response)}")
|
|
315
340
|
response
|
|
316
341
|
end
|
|
317
342
|
|
|
@@ -328,10 +353,11 @@ class DiscordApi
|
|
|
328
353
|
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
329
354
|
url = "#{@base_url}/channels/#{channel_id}/messages/pins#{query_string}"
|
|
330
355
|
headers = { 'Authorization': @authorization_header }
|
|
331
|
-
response =
|
|
332
|
-
return response if response.status == 200
|
|
356
|
+
response = get(url, headers)
|
|
357
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
333
358
|
|
|
334
|
-
@logger.error("Failed to get pinned messages in channel with ID #{channel_id}.
|
|
359
|
+
@logger.error("Failed to get pinned messages in channel with ID #{channel_id}." \
|
|
360
|
+
" Response: #{response_error_body(response)}")
|
|
335
361
|
response
|
|
336
362
|
end
|
|
337
363
|
|
|
@@ -345,11 +371,11 @@ class DiscordApi
|
|
|
345
371
|
url = "#{@base_url}/channels/#{channel_id}/messages/pins/#{message_id}"
|
|
346
372
|
headers = { 'Authorization': @authorization_header }
|
|
347
373
|
headers[:'X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
348
|
-
response =
|
|
349
|
-
return response if response.status == 204
|
|
374
|
+
response = put(url, nil, headers)
|
|
375
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
350
376
|
|
|
351
377
|
@logger.error("Failed to pin message with ID #{message_id} in channel with ID #{channel_id}. " \
|
|
352
|
-
"Response: #{response
|
|
378
|
+
"Response: #{response_error_body(response)}")
|
|
353
379
|
response
|
|
354
380
|
end
|
|
355
381
|
|
|
@@ -363,11 +389,11 @@ class DiscordApi
|
|
|
363
389
|
url = "#{@base_url}/channels/#{channel_id}/messages/pins/#{message_id}"
|
|
364
390
|
headers = { 'Authorization': @authorization_header }
|
|
365
391
|
headers[:'X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
366
|
-
response =
|
|
367
|
-
return response if response.status == 204
|
|
392
|
+
response = delete(url, headers)
|
|
393
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
368
394
|
|
|
369
395
|
@logger.error("Failed to unpin message with ID #{message_id} in channel with ID #{channel_id}. " \
|
|
370
|
-
"Response: #{response
|
|
396
|
+
"Response: #{response_error_body(response)}")
|
|
371
397
|
response
|
|
372
398
|
end
|
|
373
399
|
end
|
data/lib/disrb/user.rb
CHANGED
|
@@ -9,10 +9,10 @@ class DiscordApi
|
|
|
9
9
|
def get_current_user
|
|
10
10
|
url = "#{@base_url}/users/@me"
|
|
11
11
|
headers = { 'Authorization': @authorization_header }
|
|
12
|
-
response =
|
|
13
|
-
return response if response.status == 200
|
|
12
|
+
response = get(url, headers)
|
|
13
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
14
14
|
|
|
15
|
-
@logger.error("Failed to get current user. Response: #{response
|
|
15
|
+
@logger.error("Failed to get current user. Response: #{response_error_body(response)}")
|
|
16
16
|
response
|
|
17
17
|
end
|
|
18
18
|
|
|
@@ -22,10 +22,10 @@ class DiscordApi
|
|
|
22
22
|
def get_user(user_id)
|
|
23
23
|
url = "#{@base_url}/users/#{user_id}"
|
|
24
24
|
headers = { 'Authorization': @authorization_header }
|
|
25
|
-
response =
|
|
26
|
-
return response if response.status == 200
|
|
25
|
+
response = get(url, headers)
|
|
26
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
27
27
|
|
|
28
|
-
@logger.error("Failed to get user with ID #{user_id}. Response: #{response
|
|
28
|
+
@logger.error("Failed to get user with ID #{user_id}. Response: #{response_error_body(response)}")
|
|
29
29
|
response
|
|
30
30
|
end
|
|
31
31
|
|
|
@@ -49,10 +49,10 @@ class DiscordApi
|
|
|
49
49
|
url = "#{@base_url}/users/@me"
|
|
50
50
|
data = JSON.generate(output)
|
|
51
51
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
52
|
-
response =
|
|
53
|
-
return response if response.status == 200
|
|
52
|
+
response = patch(url, data, headers)
|
|
53
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
54
54
|
|
|
55
|
-
@logger.error("Failed to modify current user. Response: #{response
|
|
55
|
+
@logger.error("Failed to modify current user. Response: #{response_error_body(response)}")
|
|
56
56
|
response
|
|
57
57
|
end
|
|
58
58
|
|
|
@@ -73,15 +73,16 @@ class DiscordApi
|
|
|
73
73
|
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
74
74
|
url = "#{@base_url}/users/@me/guilds#{query_string}"
|
|
75
75
|
headers = { 'Authorization': @authorization_header }
|
|
76
|
-
response =
|
|
77
|
-
if response.status == 200 && @authorization_token_type == 'Bot' &&
|
|
78
|
-
|
|
76
|
+
response = get(url, headers)
|
|
77
|
+
if response.is_a?(Faraday::Response) && response.status == 200 && @authorization_token_type == 'Bot' &&
|
|
78
|
+
JSON.parse(response.body).count == 200
|
|
79
|
+
@logger.info('A bot can be in more than 200 guilds, however 200 guilds were returned.' \
|
|
79
80
|
'Discord API doesn\'t allow you to fetch more than 200 guilds. Some guilds might not be listed.')
|
|
80
81
|
return response
|
|
81
82
|
end
|
|
82
|
-
return response if response.status == 200
|
|
83
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
83
84
|
|
|
84
|
-
@logger.error("Failed to get current user's guilds. Response: #{response
|
|
85
|
+
@logger.error("Failed to get current user's guilds. Response: #{response_error_body(response)}")
|
|
85
86
|
response
|
|
86
87
|
end
|
|
87
88
|
|
|
@@ -92,11 +93,11 @@ class DiscordApi
|
|
|
92
93
|
def get_current_user_guild_member(guild_id)
|
|
93
94
|
url = "#{@base_url}/users/@me/guilds/#{guild_id}/member"
|
|
94
95
|
headers = { 'Authorization': @authorization_header }
|
|
95
|
-
response =
|
|
96
|
-
return response
|
|
96
|
+
response = get(url, headers)
|
|
97
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
97
98
|
|
|
98
99
|
@logger.error("Failed to get current user's guild member for guild ID with ID #{guild_id}. Response: " \
|
|
99
|
-
"#{response
|
|
100
|
+
"#{response_error_body(response)}")
|
|
100
101
|
response
|
|
101
102
|
end
|
|
102
103
|
|
|
@@ -108,10 +109,10 @@ class DiscordApi
|
|
|
108
109
|
def leave_guild(guild_id)
|
|
109
110
|
url = "#{@base_url}/users/@me/guilds/#{guild_id}"
|
|
110
111
|
headers = { 'Authorization': @authorization_header }
|
|
111
|
-
response =
|
|
112
|
-
return response if response.status == 204
|
|
112
|
+
response = delete(url, headers)
|
|
113
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
113
114
|
|
|
114
|
-
@logger.error("Failed to leave guild with ID #{guild_id}. Response: #{response
|
|
115
|
+
@logger.error("Failed to leave guild with ID #{guild_id}. Response: #{response_error_body(response)}")
|
|
115
116
|
response
|
|
116
117
|
end
|
|
117
118
|
|
|
@@ -124,10 +125,10 @@ class DiscordApi
|
|
|
124
125
|
url = "#{@base_url}/users/@me/channels"
|
|
125
126
|
data = JSON.generate({ recipient_id: recipient_id })
|
|
126
127
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
127
|
-
response =
|
|
128
|
-
return response if response.status == 200
|
|
128
|
+
response = post(url, data, headers)
|
|
129
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
129
130
|
|
|
130
|
-
@logger.error("Failed to create DM with recipient ID #{recipient_id}. Response: #{response
|
|
131
|
+
@logger.error("Failed to create DM with recipient ID #{recipient_id}. Response: #{response_error_body(response)}")
|
|
131
132
|
response
|
|
132
133
|
end
|
|
133
134
|
|
|
@@ -144,10 +145,10 @@ class DiscordApi
|
|
|
144
145
|
url = "#{@base_url}/users/@me/channels"
|
|
145
146
|
data = JSON.generate(output)
|
|
146
147
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
147
|
-
response =
|
|
148
|
-
return response if response.status == 200
|
|
148
|
+
response = post(url, data, headers)
|
|
149
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
149
150
|
|
|
150
|
-
@logger.error("Failed to create group DM. Response: #{response
|
|
151
|
+
@logger.error("Failed to create group DM. Response: #{response_error_body(response)}")
|
|
151
152
|
response
|
|
152
153
|
end
|
|
153
154
|
|
|
@@ -157,10 +158,10 @@ class DiscordApi
|
|
|
157
158
|
def get_current_user_connections
|
|
158
159
|
url = "#{@base_url}/users/@me/connections"
|
|
159
160
|
headers = { 'Authorization': @authorization_header }
|
|
160
|
-
response =
|
|
161
|
-
return response if response.status == 200
|
|
161
|
+
response = get(url, headers)
|
|
162
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
162
163
|
|
|
163
|
-
@logger.error("Failed to get current user's connections. Response: #{response
|
|
164
|
+
@logger.error("Failed to get current user's connections. Response: #{response_error_body(response)}")
|
|
164
165
|
response
|
|
165
166
|
end
|
|
166
167
|
|
|
@@ -172,11 +173,11 @@ class DiscordApi
|
|
|
172
173
|
def get_current_user_application_role_connection(application_id)
|
|
173
174
|
url = "#{@base_url}/users/@me/applications/#{application_id}/role-connection"
|
|
174
175
|
headers = { 'Authorization': @authorization_header }
|
|
175
|
-
response =
|
|
176
|
-
return response if response.status == 200
|
|
176
|
+
response = get(url, headers)
|
|
177
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
177
178
|
|
|
178
179
|
@logger.error("Failed to get current user's application role connection for application ID #{application_id}. " \
|
|
179
|
-
"Response: #{response
|
|
180
|
+
"Response: #{response_error_body(response)}")
|
|
180
181
|
response
|
|
181
182
|
end
|
|
182
183
|
|
|
@@ -205,11 +206,11 @@ class DiscordApi
|
|
|
205
206
|
url = "#{@base_url}/users/@me/applications/#{application_id}/role-connection"
|
|
206
207
|
data = JSON.generate(output)
|
|
207
208
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
208
|
-
response =
|
|
209
|
-
return response if response.status == 200
|
|
209
|
+
response = put(url, data, headers)
|
|
210
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
210
211
|
|
|
211
212
|
@logger.error("Failed to update current user's application role connection for application ID #{application_id}. " \
|
|
212
|
-
"Response: #{response
|
|
213
|
+
"Response: #{response_error_body(response)}")
|
|
213
214
|
response
|
|
214
215
|
end
|
|
215
216
|
end
|