disrb 0.1.0 → 0.1.1.2
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/README.md +30 -1
- data/lib/disrb/guild.rb +236 -190
- data/lib/disrb/logger.rb +27 -13
- data/lib/disrb/message.rb +16 -16
- data/lib/disrb/user.rb +41 -39
- data/lib/disrb.rb +180 -68
- metadata +1 -1
data/lib/disrb/guild.rb
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
# DiscordApi
|
|
4
4
|
# The class that contains everything that interacts with the Discord API.
|
|
5
5
|
class DiscordApi
|
|
6
|
-
def create_guild(name, region
|
|
7
|
-
explicit_content_filter
|
|
8
|
-
system_channel_id
|
|
6
|
+
def create_guild(name, region: nil, icon: nil, verification_level: nil, default_message_notifications: nil,
|
|
7
|
+
explicit_content_filter: nil, roles: nil, channels: nil, afk_channel_id: nil, afk_timeout: nil,
|
|
8
|
+
system_channel_id: nil, system_channel_flags: nil)
|
|
9
9
|
output = {}
|
|
10
10
|
output[:name] = name
|
|
11
11
|
unless region.nil?
|
|
@@ -22,22 +22,21 @@ class DiscordApi
|
|
|
22
22
|
output[:afk_timeout] = afk_timeout unless afk_timeout.nil?
|
|
23
23
|
output[:system_channel_id] = system_channel_id unless system_channel_id.nil?
|
|
24
24
|
output[:system_channel_flags] = system_channel_flags unless system_channel_flags.nil?
|
|
25
|
-
url =
|
|
25
|
+
url = "#{@base_url}/guilds"
|
|
26
26
|
data = JSON.generate(output)
|
|
27
27
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
28
|
-
response =
|
|
29
|
-
return response unless response.
|
|
28
|
+
response = DiscordApi.post(url, data, headers)
|
|
29
|
+
return response unless response.status != 200
|
|
30
30
|
|
|
31
31
|
@logger.error("Could not create guild. Response: #{response.body}")
|
|
32
32
|
response
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def get_guild(guild_id, with_counts = nil)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
end
|
|
36
|
+
query_string_hash = {}
|
|
37
|
+
query_string_hash[:with_counts] = with_counts unless with_counts.nil?
|
|
38
|
+
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
39
|
+
url = "#{@base_url}/guilds/#{guild_id}#{query_string}"
|
|
41
40
|
headers = { 'Authorization' => @authorization_header }
|
|
42
41
|
response = DiscordApi.get(url, headers)
|
|
43
42
|
return response unless response.status != 200
|
|
@@ -49,19 +48,23 @@ class DiscordApi
|
|
|
49
48
|
def get_guild_preview(guild_id)
|
|
50
49
|
url = URI("#{@base_url}/guilds/#{guild_id}/preview")
|
|
51
50
|
headers = { 'Authorization': @authorization_header }
|
|
52
|
-
response =
|
|
53
|
-
return response unless response.
|
|
51
|
+
response = DiscordApi.get(url, headers)
|
|
52
|
+
return response unless response.status != 200
|
|
54
53
|
|
|
55
54
|
@logger.error("Could not get guild preview with Guild ID #{guild_id}. Response: #{response.body}")
|
|
56
55
|
response
|
|
57
56
|
end
|
|
58
57
|
|
|
59
|
-
def modify_guild(guild_id, name
|
|
60
|
-
explicit_content_filter
|
|
61
|
-
splash
|
|
62
|
-
system_channel_flags
|
|
63
|
-
preferred_locale
|
|
64
|
-
safety_alerts_channel_id
|
|
58
|
+
def modify_guild(guild_id, name: nil, region: nil, verification_level: nil, default_message_notifications: nil,
|
|
59
|
+
explicit_content_filter: nil, afk_channel_id: nil, afk_timeout: nil, icon: nil, owner_id: nil,
|
|
60
|
+
splash: nil, discovery_splash: nil, banner: nil, system_channel_id: nil,
|
|
61
|
+
system_channel_flags: nil, rules_channel_id: nil, public_updates_channel_id: nil,
|
|
62
|
+
preferred_locale: nil, features: nil, description: nil, premium_progress_bar_enabled: nil,
|
|
63
|
+
safety_alerts_channel_id: nil, audit_reason: nil)
|
|
64
|
+
if args[1..-2].all?(&:nil?)
|
|
65
|
+
@logger.warn("No modifications for guild with ID #{guild_id} provided. Skipping.")
|
|
66
|
+
return nil
|
|
67
|
+
end
|
|
65
68
|
output = {}
|
|
66
69
|
output[:name] = name unless name.nil?
|
|
67
70
|
unless region.nil?
|
|
@@ -85,44 +88,44 @@ class DiscordApi
|
|
|
85
88
|
output[:preferred_locale] = preferred_locale unless preferred_locale.nil?
|
|
86
89
|
output[:features] = features unless features.nil?
|
|
87
90
|
output[:description] = description unless description.nil?
|
|
88
|
-
output[:premium_progress_bar_enabled] =
|
|
91
|
+
output[:premium_progress_bar_enabled] = premium_progress_bar_enabled unless premium_progress_bar_enabled.nil?
|
|
89
92
|
output[:safety_alerts_channel_id] = safety_alerts_channel_id unless safety_alerts_channel_id.nil?
|
|
90
|
-
url =
|
|
93
|
+
url = "#{@base_url}/guilds/#{guild_id}"
|
|
91
94
|
data = JSON.generate(output)
|
|
92
95
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
93
96
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
94
|
-
response =
|
|
95
|
-
return response unless response.
|
|
97
|
+
response = DiscordApi.patch(url, headers, data)
|
|
98
|
+
return response unless response.status != 200
|
|
96
99
|
|
|
97
100
|
@logger.error("Could not modify guild with Guild ID #{guild_id}. Response: #{response.body}")
|
|
98
101
|
response
|
|
99
102
|
end
|
|
100
103
|
|
|
101
104
|
def delete_guild(guild_id)
|
|
102
|
-
url =
|
|
105
|
+
url = "#{@base_url}/guilds/#{guild_id}"
|
|
103
106
|
headers = { 'Authorization': @authorization_header }
|
|
104
|
-
response =
|
|
105
|
-
return response unless response.
|
|
107
|
+
response = DiscordApi.delete(url, headers)
|
|
108
|
+
return response unless response.status != 204
|
|
106
109
|
|
|
107
110
|
@logger.error("Could not delete guild with Guild ID #{guild_id}. Response: #{response.body}")
|
|
108
111
|
response
|
|
109
112
|
end
|
|
110
113
|
|
|
111
114
|
def get_guild_channels(guild_id)
|
|
112
|
-
url =
|
|
115
|
+
url = "#{@base_url}/guilds/#{guild_id}/channels"
|
|
113
116
|
headers = { 'Authorization': @authorization_header }
|
|
114
|
-
response =
|
|
115
|
-
return response unless response.
|
|
117
|
+
response = DiscordApi.get(url, headers)
|
|
118
|
+
return response unless response.status != 200
|
|
116
119
|
|
|
117
120
|
@logger.error("Could not get guild channels with Guild ID #{guild_id}. Response: #{response.body}")
|
|
118
121
|
response
|
|
119
122
|
end
|
|
120
123
|
|
|
121
|
-
def create_guild_channel(guild_id, name, type
|
|
122
|
-
rate_limit_per_user
|
|
123
|
-
nsfw
|
|
124
|
-
default_reaction_emoji
|
|
125
|
-
default_forum_layout
|
|
124
|
+
def create_guild_channel(guild_id, name, type: nil, topic: nil, bitrate: nil, user_limit: nil,
|
|
125
|
+
rate_limit_per_user: nil, position: nil, permission_overwrites: nil, parent_id: nil,
|
|
126
|
+
nsfw: nil, rtc_region: nil, video_quality_mode: nil, default_auto_archive_duration: nil,
|
|
127
|
+
default_reaction_emoji: nil, available_tags: nil, default_sort_order: nil,
|
|
128
|
+
default_forum_layout: nil, default_thread_rate_limit_per_user: nil, audit_reason: nil)
|
|
126
129
|
output = {}
|
|
127
130
|
output[:name] = name
|
|
128
131
|
output[:type] = type unless type.nil?
|
|
@@ -142,41 +145,45 @@ class DiscordApi
|
|
|
142
145
|
output[:default_sort_order] = default_sort_order unless default_sort_order.nil?
|
|
143
146
|
output[:default_forum_layout] = default_forum_layout unless default_forum_layout.nil?
|
|
144
147
|
unless default_thread_rate_limit_per_user.nil?
|
|
145
|
-
output[:default_thread_rate_limit_per_user] =
|
|
146
|
-
default_thread_rate_limit_per_user
|
|
148
|
+
output[:default_thread_rate_limit_per_user] = default_thread_rate_limit_per_user
|
|
147
149
|
end
|
|
148
|
-
url =
|
|
150
|
+
url = "#{@base_url}/guilds/#{guild_id}/channels"
|
|
149
151
|
data = JSON.generate(output)
|
|
150
152
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
151
153
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
152
|
-
response =
|
|
153
|
-
return response unless response.
|
|
154
|
+
response = DiscordApi.post(url, data, headers)
|
|
155
|
+
return response unless response.status != 200
|
|
154
156
|
|
|
155
157
|
@logger.error("Could not create guild channel in Guild ID #{guild_id}. Response: #{response.body}")
|
|
156
158
|
response
|
|
157
159
|
end
|
|
158
160
|
|
|
159
|
-
def modify_guild_channel_positions(guild_id, channel_id, position
|
|
161
|
+
def modify_guild_channel_positions(guild_id, channel_id, position: nil, lock_permissions: nil, parent_id: nil)
|
|
162
|
+
if args[2..].all?(&:nil?)
|
|
163
|
+
@logger.warn("No modifications for guild channel positions with guild ID #{guild_id} and channel ID " \
|
|
164
|
+
"#{channel_id} provided. Skipping.")
|
|
165
|
+
return nil
|
|
166
|
+
end
|
|
160
167
|
output = {}
|
|
161
168
|
output[:id] = channel_id
|
|
162
169
|
output[:position] = position unless position.nil?
|
|
163
170
|
output[:lock_permissions] = lock_permissions unless lock_permissions.nil?
|
|
164
171
|
output[:parent_id] = parent_id unless parent_id.nil?
|
|
165
|
-
url =
|
|
172
|
+
url = "#{@base_url}/guilds/#{guild_id}/channels"
|
|
166
173
|
data = JSON.generate(output)
|
|
167
174
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
168
|
-
response =
|
|
169
|
-
return response unless response.
|
|
175
|
+
response = DiscordApi.patch(url, headers, data)
|
|
176
|
+
return response unless response.status != 200
|
|
170
177
|
|
|
171
178
|
@logger.error("Could not modify guild channel positions with Guild ID #{guild_id}. Response: #{response.body}")
|
|
172
179
|
response
|
|
173
180
|
end
|
|
174
181
|
|
|
175
182
|
def list_active_guild_threads(guild_id)
|
|
176
|
-
url =
|
|
183
|
+
url = "#{@base_url}/guilds/#{guild_id}/threads/active"
|
|
177
184
|
headers = { 'Authorization': @authorization_header }
|
|
178
|
-
response =
|
|
179
|
-
return response unless response.
|
|
185
|
+
response = DiscordApi.get(url, headers)
|
|
186
|
+
return response unless response.status != 200
|
|
180
187
|
|
|
181
188
|
@logger.error("Could not list active guild threads with Guild ID #{guild_id}. Response: #{response.body}")
|
|
182
189
|
response
|
|
@@ -193,15 +200,15 @@ class DiscordApi
|
|
|
193
200
|
response
|
|
194
201
|
end
|
|
195
202
|
|
|
196
|
-
def list_guild_members(guild_id, limit
|
|
203
|
+
def list_guild_members(guild_id, limit: nil, after: nil)
|
|
197
204
|
query_string_hash = {}
|
|
198
|
-
query_string_hash[:limit] = limit
|
|
199
|
-
query_string_hash[:after] = after
|
|
205
|
+
query_string_hash[:limit] = limit unless limit.nil?
|
|
206
|
+
query_string_hash[:after] = after unless after.nil?
|
|
200
207
|
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
201
|
-
url =
|
|
208
|
+
url = "#{@base_url}/guilds/#{guild_id}/members#{query_string}"
|
|
202
209
|
headers = { 'Authorization': @authorization_header }
|
|
203
|
-
response =
|
|
204
|
-
return response unless response.
|
|
210
|
+
response = DiscordApi.get(url, headers)
|
|
211
|
+
return response unless response.status != 200
|
|
205
212
|
|
|
206
213
|
@logger.error("Could not list members with Guild ID #{guild_id}. Response: #{response.body}")
|
|
207
214
|
response
|
|
@@ -210,7 +217,7 @@ class DiscordApi
|
|
|
210
217
|
def search_guild_members(guild_id, query, limit = nil)
|
|
211
218
|
query_string_hash = {}
|
|
212
219
|
query_string_hash[:query] = query
|
|
213
|
-
query_string_hash[:limit] = limit
|
|
220
|
+
query_string_hash[:limit] = limit unless limit.nil?
|
|
214
221
|
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
215
222
|
url = "#{@base_url}/guilds/#{guild_id}/members/search#{query_string}"
|
|
216
223
|
headers = { 'Authorization': @authorization_header }
|
|
@@ -221,20 +228,20 @@ class DiscordApi
|
|
|
221
228
|
response
|
|
222
229
|
end
|
|
223
230
|
|
|
224
|
-
def add_guild_member(guild_id, user_id, access_token, nick
|
|
231
|
+
def add_guild_member(guild_id, user_id, access_token, nick: nil, roles: nil, mute: nil, deaf: nil)
|
|
225
232
|
output = {}
|
|
226
233
|
output[:access_token] = access_token
|
|
227
234
|
output[:nick] = nick unless nick.nil?
|
|
228
235
|
output[:roles] = roles unless roles.nil?
|
|
229
236
|
output[:mute] = mute unless mute.nil?
|
|
230
237
|
output[:deaf] = deaf unless deaf.nil?
|
|
231
|
-
url =
|
|
238
|
+
url = "#{@base_url}/guilds/#{guild_id}/members/#{user_id}"
|
|
232
239
|
data = JSON.generate(output)
|
|
233
240
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
234
|
-
response =
|
|
235
|
-
if response.
|
|
241
|
+
response = DiscordApi.put(url, data, headers)
|
|
242
|
+
if response.status == 204
|
|
236
243
|
@logger.warn("User with ID #{user_id} is already a member of the guild with ID #{guild_id}.")
|
|
237
|
-
elsif response.
|
|
244
|
+
elsif response.status == 201
|
|
238
245
|
@logger.info("Added user with ID #{user_id} to guild with ID #{guild_id}.")
|
|
239
246
|
else
|
|
240
247
|
@logger.error("Could not add user with ID #{user_id} to guild with ID #{guild_id}. Response: #{response.body}")
|
|
@@ -242,63 +249,76 @@ class DiscordApi
|
|
|
242
249
|
response
|
|
243
250
|
end
|
|
244
251
|
|
|
245
|
-
def modify_guild_member(guild_id, user_id, nick
|
|
246
|
-
communication_disabled_until
|
|
252
|
+
def modify_guild_member(guild_id, user_id, nick: nil, roles: nil, mute: nil, deaf: nil, channel_id: nil,
|
|
253
|
+
communication_disabled_until: nil, flags: nil, audit_reason: nil)
|
|
254
|
+
if args[2..-2].all?(&:nil?)
|
|
255
|
+
@logger.warn("No modifications for guild member with guild ID #{guild_id} and user ID #{user_id} provided. " \
|
|
256
|
+
'Skipping.')
|
|
257
|
+
return nil
|
|
258
|
+
end
|
|
247
259
|
output = {}
|
|
248
260
|
output[:nick] = nick unless nick.nil?
|
|
249
261
|
output[:roles] = roles unless roles.nil?
|
|
250
262
|
output[:mute] = mute unless mute.nil?
|
|
251
263
|
output[:deaf] = deaf unless deaf.nil?
|
|
252
264
|
output[:channel_id] = channel_id unless channel_id.nil?
|
|
253
|
-
output[:communication_disabled_until] = communication_disabled_until
|
|
265
|
+
output[:communication_disabled_until] = communication_disabled_until unless communication_disabled_until.nil?
|
|
254
266
|
output[:flags] = flags unless flags.nil?
|
|
255
|
-
url =
|
|
267
|
+
url = "#{@base_url}/guilds/#{guild_id}/members/#{user_id}"
|
|
256
268
|
data = JSON.generate(output)
|
|
257
269
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
258
270
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
259
|
-
response =
|
|
260
|
-
return response unless response.
|
|
271
|
+
response = DiscordApi.patch(url, data, headers)
|
|
272
|
+
return response unless response.status != 200
|
|
261
273
|
|
|
262
274
|
@logger.error("Could not modify guild member with Guild ID #{guild_id} and User ID #{user_id}. " \
|
|
263
275
|
"Response: #{response.body}")
|
|
264
276
|
response
|
|
265
277
|
end
|
|
266
278
|
|
|
267
|
-
def modify_current_member(guild_id, nick
|
|
279
|
+
def modify_current_member(guild_id, nick: nil, audit_reason: nil)
|
|
280
|
+
if nick.nil?
|
|
281
|
+
@logger.warn("No modifications for current member in guild ID #{guild_id} provided. Skipping.")
|
|
282
|
+
return nil
|
|
283
|
+
end
|
|
268
284
|
output = {}
|
|
269
285
|
output[:nick] = nick unless nick.nil?
|
|
270
|
-
url =
|
|
286
|
+
url = "#{@base_url}/guilds/#{guild_id}/members/@me"
|
|
271
287
|
data = JSON.generate(output)
|
|
272
288
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
273
289
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
274
|
-
response =
|
|
275
|
-
return response unless response.
|
|
290
|
+
response = DiscordApi.patch(url, data, headers)
|
|
291
|
+
return response unless response.status != 200
|
|
276
292
|
|
|
277
293
|
@logger.error("Could not modify current member in guild with Guild ID #{guild_id}. Response: #{response.body}")
|
|
278
294
|
response
|
|
279
295
|
end
|
|
280
296
|
|
|
281
|
-
def modify_current_user_nick(guild_id, nick
|
|
297
|
+
def modify_current_user_nick(guild_id, nick: nil, audit_reason: nil)
|
|
282
298
|
@logger.warn('The "Modify Current User Nick" endpoint has been deprecated and should not be used!')
|
|
299
|
+
if nick.nil?
|
|
300
|
+
@logger.warn("No modifications for current user nick in guild ID #{guild_id} provided. Skipping.")
|
|
301
|
+
return nil
|
|
302
|
+
end
|
|
283
303
|
output = {}
|
|
284
304
|
output[:nick] = nick unless nick.nil?
|
|
285
|
-
url =
|
|
305
|
+
url = "#{@base_url}/guilds/#{guild_id}/users/@me/nick"
|
|
286
306
|
data = JSON.generate(output)
|
|
287
307
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
288
308
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
289
|
-
response =
|
|
290
|
-
return response unless response.
|
|
309
|
+
response = DiscordApi.patch(url, data, headers)
|
|
310
|
+
return response unless response.status != 200
|
|
291
311
|
|
|
292
312
|
@logger.error("Could not modify current user nick in guild with ID #{guild_id}. Response: #{response.body}")
|
|
293
313
|
response
|
|
294
314
|
end
|
|
295
315
|
|
|
296
316
|
def add_guild_member_role(guild_id, user_id, role_id, audit_reason = nil)
|
|
297
|
-
url =
|
|
317
|
+
url = "#{@base_url}/guilds/#{guild_id}/members/#{user_id}/roles/#{role_id}"
|
|
298
318
|
headers = { 'Authorization': @authorization_header }
|
|
299
319
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
300
|
-
response =
|
|
301
|
-
return response unless response.
|
|
320
|
+
response = DiscordApi.put(url, nil, headers)
|
|
321
|
+
return response unless response.status != 204
|
|
302
322
|
|
|
303
323
|
@logger.error("Could not add role with ID #{role_id}, to user with ID #{user_id} in guild with ID #{guild_id}." \
|
|
304
324
|
" Response: #{response.body}")
|
|
@@ -306,20 +326,18 @@ class DiscordApi
|
|
|
306
326
|
end
|
|
307
327
|
|
|
308
328
|
def remove_guild_member_role(guild_id, user_id, role_id, audit_reason = nil)
|
|
309
|
-
url =
|
|
329
|
+
url = "#{@base_url}/guilds/#{guild_id}/members/#{user_id}/roles/#{role_id}"
|
|
310
330
|
headers = { 'Authorization': @authorization_header }
|
|
311
331
|
headers['x-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
312
|
-
response =
|
|
313
|
-
return response unless response.
|
|
332
|
+
response = DiscordApi.delete(url, headers)
|
|
333
|
+
return response unless response.status != 204
|
|
314
334
|
|
|
315
335
|
@logger.error("Could not remove role with ID #{role_id}, from user with ID #{user_id}" \
|
|
316
336
|
" in guild with ID #{guild_id}. Response: #{response.body}")
|
|
317
337
|
response
|
|
318
338
|
end
|
|
319
339
|
|
|
320
|
-
|
|
321
|
-
# I should probably migrate to Faraday everywhere, but for now just a temporary fix.
|
|
322
|
-
def remove_guild_member(guild_id, user_id, audit_reason: nil)
|
|
340
|
+
def remove_guild_member(guild_id, user_id, audit_reason = nil)
|
|
323
341
|
url = "#{@base_url}/guilds/#{guild_id}/members/#{user_id}"
|
|
324
342
|
headers = { 'Authorization' => @authorization_header }
|
|
325
343
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
@@ -330,7 +348,7 @@ class DiscordApi
|
|
|
330
348
|
response
|
|
331
349
|
end
|
|
332
350
|
|
|
333
|
-
def get_guild_bans(guild_id, limit
|
|
351
|
+
def get_guild_bans(guild_id, limit: nil, before: nil, after: nil)
|
|
334
352
|
query_string_hash = {}
|
|
335
353
|
query_string_hash[:limit] = limit unless limit.nil?
|
|
336
354
|
query_string_hash[:before] = before unless before.nil?
|
|
@@ -339,7 +357,7 @@ class DiscordApi
|
|
|
339
357
|
url = "#{@base_url}/guilds/#{guild_id}/bans#{query_string}"
|
|
340
358
|
headers = { 'Authorization' => @authorization_header }
|
|
341
359
|
response = DiscordApi.get(url, headers)
|
|
342
|
-
return response unless response.status !=
|
|
360
|
+
return response unless response.status != 200
|
|
343
361
|
|
|
344
362
|
@logger.error("Could not get guild bans with Guild ID #{guild_id}. Response: #{response.body}")
|
|
345
363
|
response
|
|
@@ -367,12 +385,12 @@ class DiscordApi
|
|
|
367
385
|
output[:delete_message_days] = delete_message_days
|
|
368
386
|
end
|
|
369
387
|
output[:delete_message_seconds] = delete_message_seconds unless delete_message_seconds.nil?
|
|
370
|
-
url =
|
|
388
|
+
url = "#{@base_url}/guilds/#{guild_id}/bans/#{user_id}"
|
|
371
389
|
data = JSON.generate(output)
|
|
372
390
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
373
391
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
374
|
-
response =
|
|
375
|
-
return response unless response.
|
|
392
|
+
response = DiscordApi.put(url, data, headers)
|
|
393
|
+
return response unless response.status != 204
|
|
376
394
|
|
|
377
395
|
@logger.error("Could not create guild ban for user with ID #{user_id} in guild with ID #{guild_id}." \
|
|
378
396
|
" Response: #{response.body}")
|
|
@@ -380,29 +398,29 @@ class DiscordApi
|
|
|
380
398
|
end
|
|
381
399
|
|
|
382
400
|
def remove_guild_ban(guild_id, user_id, audit_reason = nil)
|
|
383
|
-
url =
|
|
401
|
+
url = "#{@base_url}/guilds/#{guild_id}/bans/#{user_id}"
|
|
384
402
|
headers = { 'Authorization': @authorization_header }
|
|
385
403
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
386
|
-
response =
|
|
387
|
-
return response unless response.
|
|
404
|
+
response = DiscordApi.delete(url, headers)
|
|
405
|
+
return response unless response.status != 204
|
|
388
406
|
|
|
389
407
|
@logger.error("Could not remove guild ban for user with ID #{user_id} in guild with ID #{guild_id}" \
|
|
390
408
|
" Response: #{response.body}")
|
|
391
409
|
response
|
|
392
410
|
end
|
|
393
411
|
|
|
394
|
-
def bulk_guild_ban(guild_id, user_ids, delete_message_seconds
|
|
412
|
+
def bulk_guild_ban(guild_id, user_ids, delete_message_seconds: nil, audit_reason: nil)
|
|
395
413
|
output = {}
|
|
396
414
|
output[:user_ids] = user_ids unless user_ids.nil?
|
|
397
415
|
output[:delete_message_seconds] = delete_message_seconds unless delete_message_seconds.nil?
|
|
398
|
-
url =
|
|
416
|
+
url = "#{@base_url}/guilds/#{guild_id}/bulk-ban"
|
|
399
417
|
data = JSON.generate(output)
|
|
400
418
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
401
419
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
402
|
-
response =
|
|
403
|
-
return response unless response.
|
|
420
|
+
response = DiscordApi.post(url, data, headers)
|
|
421
|
+
return response unless response.status != 200
|
|
404
422
|
|
|
405
|
-
if response.
|
|
423
|
+
if response.status == 500_000
|
|
406
424
|
@logger.error("No users were banned in bulk ban in guild with ID #{guild_id}. Response: #{response.body}")
|
|
407
425
|
else
|
|
408
426
|
@logger.error("Could not bulk ban users in guild with ID #{guild_id}. Response: #{response.body}")
|
|
@@ -411,63 +429,76 @@ class DiscordApi
|
|
|
411
429
|
end
|
|
412
430
|
|
|
413
431
|
def get_guild_roles(guild_id)
|
|
414
|
-
url =
|
|
432
|
+
url = "#{@base_url}/guilds/#{guild_id}/roles"
|
|
415
433
|
headers = { 'Authorization': @authorization_header }
|
|
416
|
-
response =
|
|
417
|
-
return response unless response.
|
|
434
|
+
response = DiscordApi.get(url, headers)
|
|
435
|
+
return response unless response.status != 200
|
|
418
436
|
|
|
419
437
|
@logger.error("Could not get guild roles with Guild ID #{guild_id}. Response: #{response.body}")
|
|
420
438
|
response
|
|
421
439
|
end
|
|
422
440
|
|
|
423
441
|
def get_guild_role(guild_id, role_id)
|
|
424
|
-
url =
|
|
442
|
+
url = "#{@base_url}/guilds/#{guild_id}/roles/#{role_id}"
|
|
425
443
|
headers = { 'Authorization': @authorization_header }
|
|
426
|
-
response =
|
|
427
|
-
return response unless response.
|
|
444
|
+
response = DiscordApi.get(url, headers)
|
|
445
|
+
return response unless response.status != 200
|
|
428
446
|
|
|
429
447
|
@logger.error("Could not get role with ID #{role_id} in guild with ID #{guild_id}. Response: #{response.body}")
|
|
430
448
|
response
|
|
431
449
|
end
|
|
432
450
|
|
|
433
|
-
def create_guild_role(guild_id, name
|
|
434
|
-
unicode_emoji
|
|
451
|
+
def create_guild_role(guild_id, name: nil, permissions: nil, color: nil, colors: nil, hoist: nil, icon: nil,
|
|
452
|
+
unicode_emoji: nil, mentionable: nil, audit_reason: nil)
|
|
435
453
|
output = {}
|
|
436
454
|
output[:name] = name unless name.nil?
|
|
437
455
|
output[:permissions] = permissions unless permissions.nil?
|
|
438
|
-
|
|
456
|
+
unless color.nil?
|
|
457
|
+
@logger.warn('The "color" parameter has been deprecated and should not be used!')
|
|
458
|
+
output[:color] = color
|
|
459
|
+
end
|
|
460
|
+
output[:colors] = colors unless colors.nil?
|
|
439
461
|
output[:hoist] = hoist unless hoist.nil?
|
|
440
462
|
output[:icon] = icon unless icon.nil?
|
|
441
463
|
output[:unicode_emoji] = unicode_emoji unless unicode_emoji.nil?
|
|
442
464
|
output[:mentionable] = mentionable unless mentionable.nil?
|
|
443
|
-
url =
|
|
465
|
+
url = "#{@base_url}/guilds/#{guild_id}/roles"
|
|
444
466
|
data = JSON.generate(output)
|
|
445
467
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
446
468
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
447
|
-
response =
|
|
448
|
-
return response unless response.
|
|
469
|
+
response = DiscordApi.post(url, data, headers)
|
|
470
|
+
return response unless response.status != 200
|
|
449
471
|
|
|
450
472
|
@logger.error("Could not create guild role in guild with ID #{guild_id}. Response: #{response.body}")
|
|
451
473
|
response
|
|
452
474
|
end
|
|
453
475
|
|
|
454
|
-
def modify_guild_role_positions(guild_id, id, position
|
|
476
|
+
def modify_guild_role_positions(guild_id, id, position: nil, audit_reason: nil)
|
|
477
|
+
if position.nil?
|
|
478
|
+
@logger.warn("No role positions provided for guild with ID #{guild_id}. Skipping function.")
|
|
479
|
+
return nil
|
|
480
|
+
end
|
|
455
481
|
output = {}
|
|
456
482
|
output[:id] = id
|
|
457
483
|
output[:position] = position unless position.nil?
|
|
458
|
-
url =
|
|
484
|
+
url = "#{@base_url}/guilds/#{guild_id}/roles"
|
|
459
485
|
data = JSON.generate(output)
|
|
460
486
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
461
487
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
462
|
-
response =
|
|
463
|
-
return response unless response.
|
|
488
|
+
response = DiscordApi.patch(url, data, headers)
|
|
489
|
+
return response unless response.status != 200
|
|
464
490
|
|
|
465
491
|
@logger.error("Could not modify guild role positions in guild with ID #{guild_id}. Response: #{response.body}")
|
|
466
492
|
response
|
|
467
493
|
end
|
|
468
494
|
|
|
469
|
-
def modify_guild_role(guild_id, role_id, name
|
|
470
|
-
unicode_emoji
|
|
495
|
+
def modify_guild_role(guild_id, role_id, name: nil, permissions: nil, color: nil, hoist: nil, icon: nil,
|
|
496
|
+
unicode_emoji: nil, mentionable: nil, audit_reason: nil)
|
|
497
|
+
if args[2..-2].all?(&:nil?)
|
|
498
|
+
@logger.warn("No modifications for guild role with ID #{role_id} in guild with ID #{guild_id} provided. " \
|
|
499
|
+
'Skipping.')
|
|
500
|
+
return nil
|
|
501
|
+
end
|
|
471
502
|
output = {}
|
|
472
503
|
output[:name] = name unless name.nil?
|
|
473
504
|
output[:permissions] = permissions unless permissions.nil?
|
|
@@ -476,12 +507,12 @@ class DiscordApi
|
|
|
476
507
|
output[:icon] = icon unless icon.nil?
|
|
477
508
|
output[:unicode_emoji] = unicode_emoji unless unicode_emoji.nil?
|
|
478
509
|
output[:mentionable] = mentionable unless mentionable.nil?
|
|
479
|
-
url =
|
|
510
|
+
url = "#{@base_url}/guilds/#{guild_id}/roles/#{role_id}"
|
|
480
511
|
data = JSON.generate(output)
|
|
481
512
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
482
513
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
483
|
-
response =
|
|
484
|
-
return response unless response.
|
|
514
|
+
response = DiscordApi.patch(url, data, headers)
|
|
515
|
+
return response unless response.status != 200
|
|
485
516
|
|
|
486
517
|
@logger.error("Could not modify guild role with ID #{role_id} in guild with ID #{guild_id}." \
|
|
487
518
|
" Response: #{response.body}")
|
|
@@ -490,45 +521,45 @@ class DiscordApi
|
|
|
490
521
|
|
|
491
522
|
def modify_guild_mfa_level(guild_id, level, audit_reason = nil)
|
|
492
523
|
output = {}
|
|
493
|
-
output[:level] = level
|
|
494
|
-
url =
|
|
524
|
+
output[:level] = level
|
|
525
|
+
url = "#{@base_url}/guilds/#{guild_id}/mfa"
|
|
495
526
|
data = JSON.generate(output)
|
|
496
527
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
497
528
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
498
|
-
response =
|
|
499
|
-
return unless response !=
|
|
529
|
+
response = DiscordApi.post(url, data, headers)
|
|
530
|
+
return unless response.status != 200
|
|
500
531
|
|
|
501
532
|
@logger.error("Failed to modify guild MFA level. Response: #{response.body}")
|
|
502
533
|
response
|
|
503
534
|
end
|
|
504
535
|
|
|
505
536
|
def delete_guild_role(guild_id, role_id, audit_reason = nil)
|
|
506
|
-
url =
|
|
537
|
+
url = "#{@base_url}/guilds/#{guild_id}/roles/#{role_id}"
|
|
507
538
|
headers = { 'Authorization': @authorization_header }
|
|
508
539
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
509
|
-
response =
|
|
510
|
-
return response unless response.
|
|
540
|
+
response = DiscordApi.delete(url, headers)
|
|
541
|
+
return response unless response.status != 204
|
|
511
542
|
|
|
512
543
|
@logger.error("Failed to delete guild role. Response: #{response.body}")
|
|
513
544
|
response
|
|
514
545
|
end
|
|
515
546
|
|
|
516
|
-
def get_guild_prune_count(guild_id, days
|
|
547
|
+
def get_guild_prune_count(guild_id, days: nil, include_roles: nil)
|
|
517
548
|
query_string_hash = {}
|
|
518
549
|
query_string_hash[:days] = days unless days.nil?
|
|
519
550
|
query_string_hash[:include_roles] = include_roles unless include_roles.nil?
|
|
520
551
|
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
521
|
-
url =
|
|
552
|
+
url = "#{@base_url}/guilds/#{guild_id}/prune#{query_string}"
|
|
522
553
|
headers = { 'Authorization': @authorization_header }
|
|
523
|
-
response =
|
|
524
|
-
return response unless response.
|
|
554
|
+
response = DiscordApi.get(url, headers)
|
|
555
|
+
return response unless response.status != 200
|
|
525
556
|
|
|
526
557
|
@logger.error("Failed to get guild prune count. Response: #{response.body}")
|
|
527
558
|
response
|
|
528
559
|
end
|
|
529
560
|
|
|
530
|
-
def begin_guild_prune(guild_id, days
|
|
531
|
-
|
|
561
|
+
def begin_guild_prune(guild_id, days: nil, compute_prune_count: nil, include_roles: nil, reason: nil,
|
|
562
|
+
audit_reason: nil)
|
|
532
563
|
output = {}
|
|
533
564
|
output[:days] = days unless days.nil?
|
|
534
565
|
output[:compute_prune_count] = compute_prune_count unless compute_prune_count.nil?
|
|
@@ -537,46 +568,46 @@ class DiscordApi
|
|
|
537
568
|
@logger.warn('The "reason" parameter has been deprecated and should not be used!')
|
|
538
569
|
output[:reason] = reason
|
|
539
570
|
end
|
|
540
|
-
url =
|
|
571
|
+
url = "#{@base_url}/guilds/#{guild_id}/prune"
|
|
541
572
|
data = JSON.generate(output)
|
|
542
573
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
543
574
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
544
|
-
response =
|
|
545
|
-
return response unless response.
|
|
575
|
+
response = DiscordApi.post(url, data, headers)
|
|
576
|
+
return response unless response.status != 200
|
|
546
577
|
|
|
547
578
|
@logger.error("Failed to begin guild prune. Response: #{response.body}")
|
|
548
579
|
response
|
|
549
580
|
end
|
|
550
581
|
|
|
551
582
|
def get_guild_voice_regions(guild_id)
|
|
552
|
-
url =
|
|
583
|
+
url = "#{@base_url}/guilds/#{guild_id}/regions"
|
|
553
584
|
headers = { 'Authorization': @authorization_header }
|
|
554
|
-
response =
|
|
555
|
-
return response unless response.
|
|
585
|
+
response = DiscordApi.get(url, headers)
|
|
586
|
+
return response unless response.status != 200
|
|
556
587
|
|
|
557
588
|
@logger.error("Failed to get guild voice regions. Response: #{response.body}")
|
|
558
589
|
response
|
|
559
590
|
end
|
|
560
591
|
|
|
561
592
|
def get_guild_invites(guild_id)
|
|
562
|
-
url =
|
|
593
|
+
url = "#{@base_url}/guilds/#{guild_id}/invites"
|
|
563
594
|
headers = { 'Authorization': @authorization_header }
|
|
564
|
-
response =
|
|
565
|
-
return response unless response.
|
|
595
|
+
response = DiscordApi.get(url, headers)
|
|
596
|
+
return response unless response.status != 200
|
|
566
597
|
|
|
567
598
|
@logger.error("Failed to get guild invites. Response: #{response.body}")
|
|
568
599
|
response
|
|
569
600
|
end
|
|
570
601
|
|
|
571
602
|
def get_guild_integrations(guild_id)
|
|
572
|
-
url =
|
|
603
|
+
url = "#{@base_url}/guilds/#{guild_id}/integrations"
|
|
573
604
|
headers = { 'Authorization': @authorization_header }
|
|
574
|
-
response =
|
|
575
|
-
|
|
605
|
+
response = DiscordApi.get(url, headers)
|
|
606
|
+
if response.status == 200
|
|
576
607
|
if JSON.parse(response.body).length == 50
|
|
577
608
|
@logger.warn('The endpoint returned 50 integrations, which means there could be more integrations not shown.')
|
|
578
609
|
end
|
|
579
|
-
response
|
|
610
|
+
return response
|
|
580
611
|
end
|
|
581
612
|
|
|
582
613
|
@logger.error("Failed to get guild integrations. Response: #{response.body}")
|
|
@@ -584,59 +615,58 @@ class DiscordApi
|
|
|
584
615
|
end
|
|
585
616
|
|
|
586
617
|
def delete_guild_integration(guild_id, integration_id, audit_reason = nil)
|
|
587
|
-
url =
|
|
618
|
+
url = "#{@base_url}/guilds/#{guild_id}/integrations/#{integration_id}"
|
|
588
619
|
headers = { 'Authorization': @authorization_header }
|
|
589
620
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
590
|
-
response =
|
|
591
|
-
return response unless response.
|
|
621
|
+
response = DiscordApi.delete(url, headers)
|
|
622
|
+
return response unless response.status != 204
|
|
592
623
|
|
|
593
624
|
@logger.error("Failed to delete guild integration. Response: #{response.body}")
|
|
594
625
|
response
|
|
595
626
|
end
|
|
596
627
|
|
|
597
628
|
def get_guild_widget_settings(guild_id)
|
|
598
|
-
url =
|
|
629
|
+
url = "#{@base_url}/guilds/#{guild_id}/widget"
|
|
599
630
|
headers = { 'Authorization': @authorization_header }
|
|
600
|
-
response =
|
|
601
|
-
return response unless response.
|
|
631
|
+
response = DiscordApi.get(url, headers)
|
|
632
|
+
return response unless response.status != 200
|
|
602
633
|
|
|
603
634
|
@logger.error("Failed to get guild widget settings. Response: #{response.body}")
|
|
604
635
|
response
|
|
605
636
|
end
|
|
606
637
|
|
|
607
|
-
def modify_guild_widget(guild_id, enabled, channel_id
|
|
638
|
+
def modify_guild_widget(guild_id, enabled, channel_id, audit_reason: nil)
|
|
608
639
|
output = {}
|
|
609
640
|
output[:enabled] = enabled
|
|
610
|
-
output[:channel_id] = channel_id
|
|
611
|
-
url =
|
|
641
|
+
output[:channel_id] = channel_id
|
|
642
|
+
url = "#{@base_url}/guilds/#{guild_id}/widget"
|
|
612
643
|
data = JSON.generate(output)
|
|
613
644
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
614
645
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
615
|
-
response =
|
|
616
|
-
return response unless response.
|
|
646
|
+
response = DiscordApi.patch(url, data, headers)
|
|
647
|
+
return response unless response.status != 200
|
|
617
648
|
|
|
618
649
|
@logger.error("Failed to modify guild widget. Response: #{response.body}")
|
|
619
650
|
response
|
|
620
651
|
end
|
|
621
652
|
|
|
622
653
|
def get_guild_wiget(guild_id)
|
|
623
|
-
url =
|
|
654
|
+
url = "#{@base_url}/guilds/#{guild_id}/widget.json"
|
|
624
655
|
headers = { 'Authorization': @authorization_header }
|
|
625
|
-
response =
|
|
626
|
-
return response unless response.
|
|
656
|
+
response = DiscordApi.get(url, headers)
|
|
657
|
+
return response unless response.status != 200
|
|
627
658
|
|
|
628
659
|
@logger.error("Failed to get guild widget. Response: #{response.body}")
|
|
629
660
|
response
|
|
630
661
|
end
|
|
631
662
|
|
|
632
663
|
def get_guild_vanity_url(guild_id)
|
|
633
|
-
url =
|
|
664
|
+
url = "#{@base_url}/guilds/#{guild_id}/vanity-url"
|
|
634
665
|
headers = { 'Authorization': @authorization_header }
|
|
635
|
-
response =
|
|
636
|
-
return response unless response.
|
|
666
|
+
response = DiscordApi.get(url, headers)
|
|
667
|
+
return response unless response.status != 200
|
|
637
668
|
|
|
638
|
-
@logger.error(
|
|
639
|
-
"If you only want to get the Vanity URL, use the get_guild endpoint. Response: #{response.body}")
|
|
669
|
+
@logger.error("Failed to get guild vanity URL. Response: #{response.body}")
|
|
640
670
|
response
|
|
641
671
|
end
|
|
642
672
|
|
|
@@ -649,93 +679,109 @@ class DiscordApi
|
|
|
649
679
|
nil
|
|
650
680
|
elsif true_keys.size == 1
|
|
651
681
|
style = true_keys.first.to_s
|
|
682
|
+
else
|
|
683
|
+
style = nil
|
|
652
684
|
end
|
|
653
685
|
|
|
654
686
|
query_string_hash = {}
|
|
655
687
|
query_string_hash[:style] = style unless style.nil?
|
|
656
688
|
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
657
689
|
|
|
658
|
-
url =
|
|
659
|
-
response =
|
|
660
|
-
return unless response.
|
|
690
|
+
url = "#{@base_url}/guilds/#{guild_id}/widget.png#{query_string}"
|
|
691
|
+
response = DiscordApi.get(url)
|
|
692
|
+
return unless response.status != 200
|
|
661
693
|
|
|
662
694
|
@logger.error("Failed to get guild widget image. Response: #{response.body}")
|
|
663
695
|
response
|
|
664
696
|
end
|
|
665
697
|
|
|
666
698
|
def get_guild_welcome_screen(guild_id)
|
|
667
|
-
url =
|
|
699
|
+
url = "#{@base_url}/guilds/#{guild_id}/welcome-screen"
|
|
668
700
|
headers = { 'Authorization': @authorization_header }
|
|
669
|
-
response =
|
|
670
|
-
return response unless response.
|
|
701
|
+
response = DiscordApi.get(url, headers)
|
|
702
|
+
return response unless response.status != 200
|
|
671
703
|
|
|
672
704
|
@logger.error("Failed to get guild welcome screen. Response: #{response.body}")
|
|
673
705
|
response
|
|
674
706
|
end
|
|
675
707
|
|
|
676
|
-
def modify_guild_welcome_screen(guild_id, enabled
|
|
677
|
-
audit_reason
|
|
708
|
+
def modify_guild_welcome_screen(guild_id, enabled: nil, welcome_channels: nil, description: nil,
|
|
709
|
+
audit_reason: nil)
|
|
710
|
+
if args[1..-2].all?(&:nil?)
|
|
711
|
+
@logger.warn("No modifications for guild welcome screen with guild ID #{guild_id} provided. " \
|
|
712
|
+
'Skipping.')
|
|
713
|
+
return nil
|
|
714
|
+
end
|
|
678
715
|
output = {}
|
|
679
716
|
output[:enabled] = enabled unless enabled.nil?
|
|
680
717
|
output[:welcome_channels] = welcome_channels unless welcome_channels.nil?
|
|
681
718
|
output[:description] = description unless description.nil?
|
|
682
|
-
url =
|
|
719
|
+
url = "#{@base_url}/guilds/#{guild_id}/welcome-screen"
|
|
683
720
|
data = JSON.generate(output)
|
|
684
721
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
685
722
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
686
|
-
response =
|
|
687
|
-
return response unless response.
|
|
723
|
+
response = DiscordApi.patch(url, data, headers)
|
|
724
|
+
return response unless response.status != 200
|
|
688
725
|
|
|
689
726
|
@logger.error("Failed to modify guild welcome screen. Response: #{response.body}")
|
|
690
727
|
response
|
|
691
728
|
end
|
|
692
729
|
|
|
693
730
|
def get_guild_onboarding(guild_id)
|
|
694
|
-
url =
|
|
731
|
+
url = "#{@base_url}/guilds/#{guild_id}/onboarding"
|
|
695
732
|
headers = { 'Authorization': @authorization_header }
|
|
696
|
-
response =
|
|
697
|
-
return response unless response.
|
|
733
|
+
response = DiscordApi.get(url, headers)
|
|
734
|
+
return response unless response.status != 200
|
|
698
735
|
|
|
699
736
|
@logger.error("Failed to get guild onboarding. Response: #{response.body}")
|
|
700
737
|
response
|
|
701
738
|
end
|
|
702
739
|
|
|
703
|
-
def modify_guild_onboarding(guild_id, prompts, default_channel_ids, enabled, mode
|
|
740
|
+
def modify_guild_onboarding(guild_id, prompts: nil, default_channel_ids: nil, enabled: nil, mode: nil,
|
|
741
|
+
audit_reason: nil)
|
|
742
|
+
if args[1..-2].all?(&:nil?)
|
|
743
|
+
@logger.warn("No modifications for guild onboarding with guild ID #{guild_id} provided. " \
|
|
744
|
+
'Skipping.')
|
|
745
|
+
return nil
|
|
746
|
+
end
|
|
704
747
|
output = {}
|
|
705
|
-
output[:prompts] = prompts
|
|
706
|
-
output[:default_channel_ids] = default_channel_ids
|
|
707
|
-
output[:enabled] = enabled
|
|
708
|
-
output[:mode] = mode
|
|
709
|
-
url =
|
|
748
|
+
output[:prompts] = prompts unless prompts.nil?
|
|
749
|
+
output[:default_channel_ids] = default_channel_ids unless default_channel_ids.nil?
|
|
750
|
+
output[:enabled] = enabled unless enabled.nil?
|
|
751
|
+
output[:mode] = mode unless mode.nil?
|
|
752
|
+
url = "#{@base_url}/guilds/#{guild_id}/onboarding"
|
|
710
753
|
data = JSON.generate(output)
|
|
711
754
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
712
755
|
headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
|
|
713
|
-
response =
|
|
714
|
-
return response unless response.
|
|
756
|
+
response = DiscordApi.put(url, data, headers)
|
|
757
|
+
return response unless response.status != 200
|
|
715
758
|
|
|
716
759
|
@logger.error("Failed to modify guild onboarding. Response: #{response.body}")
|
|
717
760
|
response
|
|
718
761
|
end
|
|
719
762
|
|
|
720
|
-
def modify_guild_incident_actions(guild_id, invites_disabled_until
|
|
763
|
+
def modify_guild_incident_actions(guild_id, invites_disabled_until: nil, dms_disabled_until: nil)
|
|
764
|
+
if args[1..].all?(&:nil?)
|
|
765
|
+
@logger.warn("No modifications for guild incident actions with guild ID #{guild_id} provided. " \
|
|
766
|
+
'Skipping.')
|
|
767
|
+
return nil
|
|
768
|
+
end
|
|
721
769
|
output = {}
|
|
722
|
-
# if only discord wouldn't of have required to set a variable to null for some functionality
|
|
723
770
|
if invites_disabled_until == false
|
|
724
771
|
output[:invites_disabled_until] = nil
|
|
725
|
-
elsif !invites_disabled_until.nil?
|
|
772
|
+
elsif !invites_disabled_until.nil?
|
|
726
773
|
output[:invites_disabled_until] = invites_disabled_until
|
|
727
774
|
end
|
|
728
775
|
if dms_disabled_until == false
|
|
729
776
|
output[:dms_disabled_until] = nil
|
|
730
|
-
elsif !dms_disabled_until.nil?
|
|
777
|
+
elsif !dms_disabled_until.nil?
|
|
731
778
|
output[:dms_disabled_until] = dms_disabled_until
|
|
732
779
|
end
|
|
733
|
-
url =
|
|
780
|
+
url = "#{@base_url}/guilds/#{guild_id}/incident-actions"
|
|
734
781
|
data = JSON.generate(output)
|
|
735
782
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
736
|
-
response =
|
|
737
|
-
|
|
738
|
-
return response unless response.code != '200'
|
|
783
|
+
response = DiscordApi.put(url, data, headers)
|
|
784
|
+
return response unless response.status != 200
|
|
739
785
|
|
|
740
786
|
@logger.error("Failed to modify guild incident actions. Response: #{response.body}")
|
|
741
787
|
response
|