discordrb 3.2.1 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of discordrb might be problematic. Click here for more details.

Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +4 -0
  3. data/.rubocop.yml +3 -3
  4. data/.travis.yml +28 -3
  5. data/.yardopts +1 -1
  6. data/CHANGELOG.md +555 -144
  7. data/CONTRIBUTING.md +1 -1
  8. data/Gemfile +0 -4
  9. data/README.md +86 -15
  10. data/Rakefile +2 -2
  11. data/bin/travis_build_docs.sh +17 -0
  12. data/discordrb-webhooks.gemspec +2 -1
  13. data/discordrb.gemspec +12 -5
  14. data/lib/discordrb.rb +2 -2
  15. data/lib/discordrb/api.rb +94 -25
  16. data/lib/discordrb/api/channel.rb +53 -17
  17. data/lib/discordrb/api/invite.rb +7 -4
  18. data/lib/discordrb/api/server.rb +173 -36
  19. data/lib/discordrb/api/user.rb +18 -4
  20. data/lib/discordrb/api/webhook.rb +83 -0
  21. data/lib/discordrb/await.rb +1 -1
  22. data/lib/discordrb/bot.rb +191 -102
  23. data/lib/discordrb/cache.rb +39 -9
  24. data/lib/discordrb/commands/command_bot.rb +79 -24
  25. data/lib/discordrb/commands/container.rb +16 -2
  26. data/lib/discordrb/commands/parser.rb +46 -7
  27. data/lib/discordrb/commands/rate_limiter.rb +8 -6
  28. data/lib/discordrb/container.rb +51 -7
  29. data/lib/discordrb/data.rb +1729 -286
  30. data/lib/discordrb/errors.rb +34 -1
  31. data/lib/discordrb/events/generic.rb +1 -1
  32. data/lib/discordrb/events/guilds.rb +1 -0
  33. data/lib/discordrb/events/message.rb +18 -12
  34. data/lib/discordrb/events/presence.rb +7 -2
  35. data/lib/discordrb/events/reactions.rb +13 -4
  36. data/lib/discordrb/events/roles.rb +7 -6
  37. data/lib/discordrb/events/typing.rb +1 -1
  38. data/lib/discordrb/events/webhooks.rb +61 -0
  39. data/lib/discordrb/gateway.rb +85 -32
  40. data/lib/discordrb/light.rb +1 -1
  41. data/lib/discordrb/logger.rb +8 -7
  42. data/lib/discordrb/permissions.rb +41 -4
  43. data/lib/discordrb/version.rb +1 -1
  44. data/lib/discordrb/voice/encoder.rb +10 -8
  45. data/lib/discordrb/voice/voice_bot.rb +4 -4
  46. data/lib/discordrb/websocket.rb +2 -2
  47. metadata +59 -14
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # API calls for Channel
2
4
  module Discordrb::API::Channel
3
5
  module_function
@@ -16,38 +18,42 @@ module Discordrb::API::Channel
16
18
 
17
19
  # Update a channel's data
18
20
  # https://discordapp.com/developers/docs/resources/channel#modify-channel
19
- def update(token, channel_id, name, topic, position, bitrate, user_limit)
21
+ def update(token, channel_id, name, topic, position, bitrate, user_limit, nsfw, permission_overwrites = nil, parent_id = nil, rate_limit_per_user = nil, reason = nil)
22
+ data = { name: name, position: position, topic: topic, bitrate: bitrate, user_limit: user_limit, nsfw: nsfw, parent_id: parent_id, rate_limit_per_user: rate_limit_per_user }
23
+ data[:permission_overwrites] = permission_overwrites unless permission_overwrites.nil?
20
24
  Discordrb::API.request(
21
25
  :channels_cid,
22
26
  channel_id,
23
27
  :patch,
24
28
  "#{Discordrb::API.api_base}/channels/#{channel_id}",
25
- { name: name, position: position, topic: topic, bitrate: bitrate, user_limit: user_limit }.to_json,
29
+ data.to_json,
26
30
  Authorization: token,
27
- content_type: :json
31
+ content_type: :json,
32
+ 'X-Audit-Log-Reason': reason
28
33
  )
29
34
  end
30
35
 
31
36
  # Delete a channel
32
37
  # https://discordapp.com/developers/docs/resources/channel#deleteclose-channel
33
- def delete(token, channel_id)
38
+ def delete(token, channel_id, reason = nil)
34
39
  Discordrb::API.request(
35
40
  :channels_cid,
36
41
  channel_id,
37
42
  :delete,
38
43
  "#{Discordrb::API.api_base}/channels/#{channel_id}",
39
- Authorization: token
44
+ Authorization: token,
45
+ 'X-Audit-Log-Reason': reason
40
46
  )
41
47
  end
42
48
 
43
49
  # Get a list of messages from a channel's history
44
50
  # https://discordapp.com/developers/docs/resources/channel#get-channel-messages
45
- def messages(token, channel_id, amount, before = nil, after = nil)
51
+ def messages(token, channel_id, amount, before = nil, after = nil, around = nil)
46
52
  Discordrb::API.request(
47
53
  :channels_cid_messages,
48
54
  channel_id,
49
55
  :get,
50
- "#{Discordrb::API.api_base}/channels/#{channel_id}/messages?limit=#{amount}#{"&before=#{before}" if before}#{"&after=#{after}" if after}",
56
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/messages?limit=#{amount}#{"&before=#{before}" if before}#{"&after=#{after}" if after}#{"&around=#{around}" if around}",
51
57
  Authorization: token
52
58
  )
53
59
  end
@@ -66,19 +72,19 @@ module Discordrb::API::Channel
66
72
 
67
73
  # Send a message to a channel
68
74
  # https://discordapp.com/developers/docs/resources/channel#create-message
69
- def create_message(token, channel_id, message, mentions = [], tts = false, embed = nil) # send message
75
+ def create_message(token, channel_id, message, tts = false, embed = nil, nonce = nil) # send message
70
76
  Discordrb::API.request(
71
77
  :channels_cid_messages_mid,
72
78
  channel_id,
73
79
  :post,
74
80
  "#{Discordrb::API.api_base}/channels/#{channel_id}/messages",
75
- { content: message, mentions: mentions, tts: tts, embed: embed }.to_json,
81
+ { content: message, tts: tts, embed: embed, nonce: nonce }.to_json,
76
82
  Authorization: token,
77
83
  content_type: :json
78
84
  )
79
85
  rescue RestClient::BadRequest => e
80
86
  parsed = JSON.parse(e.response.body)
81
- raise Discordrb::Errors::MessageTooLong, "Message over the character limit (#{message.length} > 2000)" if parsed['content'] && parsed['content'].is_a?(Array) && parsed['content'].first == 'Must be 2000 or less characters long.'
87
+ raise Discordrb::Errors::MessageTooLong, "Message over the character limit (#{message.length} > 2000)" if parsed['content'] && parsed['content'].is_a?(Array) && parsed['content'].first == 'Must be 2000 or fewer in length.'
82
88
  raise
83
89
  end
84
90
 
@@ -203,7 +209,7 @@ module Discordrb::API::Channel
203
209
 
204
210
  # Update a channels permission for a role or member
205
211
  # https://discordapp.com/developers/docs/resources/channel#edit-channel-permissions
206
- def update_permission(token, channel_id, overwrite_id, allow, deny, type)
212
+ def update_permission(token, channel_id, overwrite_id, allow, deny, type, reason = nil)
207
213
  Discordrb::API.request(
208
214
  :channels_cid_permissions_oid,
209
215
  channel_id,
@@ -211,7 +217,8 @@ module Discordrb::API::Channel
211
217
  "#{Discordrb::API.api_base}/channels/#{channel_id}/permissions/#{overwrite_id}",
212
218
  { type: type, id: overwrite_id, allow: allow, deny: deny }.to_json,
213
219
  Authorization: token,
214
- content_type: :json
220
+ content_type: :json,
221
+ 'X-Audit-Log-Reason': reason
215
222
  )
216
223
  end
217
224
 
@@ -229,27 +236,29 @@ module Discordrb::API::Channel
229
236
 
230
237
  # Create an instant invite from a server or a channel id
231
238
  # https://discordapp.com/developers/docs/resources/channel#create-channel-invite
232
- def create_invite(token, channel_id, max_age = 0, max_uses = 0, temporary = false)
239
+ def create_invite(token, channel_id, max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil)
233
240
  Discordrb::API.request(
234
241
  :channels_cid_invites,
235
242
  channel_id,
236
243
  :post,
237
244
  "#{Discordrb::API.api_base}/channels/#{channel_id}/invites",
238
- { max_age: max_age, max_uses: max_uses, temporary: temporary }.to_json,
245
+ { max_age: max_age, max_uses: max_uses, temporary: temporary, unique: unique }.to_json,
239
246
  Authorization: token,
240
- content_type: :json
247
+ content_type: :json,
248
+ 'X-Audit-Log-Reason': reason
241
249
  )
242
250
  end
243
251
 
244
252
  # Delete channel permission
245
253
  # https://discordapp.com/developers/docs/resources/channel#delete-channel-permission
246
- def delete_permission(token, channel_id, overwrite_id)
254
+ def delete_permission(token, channel_id, overwrite_id, reason = nil)
247
255
  Discordrb::API.request(
248
256
  :channels_cid_permissions_oid,
249
257
  channel_id,
250
258
  :delete,
251
259
  "#{Discordrb::API.api_base}/channels/#{channel_id}/permissions/#{overwrite_id}",
252
- Authorization: token
260
+ Authorization: token,
261
+ 'X-Audit-Log-Reason': reason
253
262
  )
254
263
  end
255
264
 
@@ -371,4 +380,31 @@ module Discordrb::API::Channel
371
380
  content_type: :json
372
381
  )
373
382
  end
383
+
384
+ # Create a webhook
385
+ # https://discordapp.com/developers/docs/resources/webhook#create-webhook
386
+ def create_webhook(token, channel_id, name, avatar = nil, reason = nil)
387
+ Discordrb::API.request(
388
+ :channels_cid_webhooks,
389
+ channel_id,
390
+ :post,
391
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/webhooks",
392
+ { name: name, avatar: avatar }.to_json,
393
+ Authorization: token,
394
+ content_type: :json,
395
+ 'X-Audit-Log-Reason': reason
396
+ )
397
+ end
398
+
399
+ # Get channel webhooks
400
+ # https://discordapp.com/developers/docs/resources/webhook#get-channel-webhooks
401
+ def webhooks(token, channel_id)
402
+ Discordrb::API.request(
403
+ :channels_cid_webhooks,
404
+ channel_id,
405
+ :get,
406
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/webhooks",
407
+ Authorization: token
408
+ )
409
+ end
374
410
  end
@@ -1,28 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # API calls for Invite object
2
4
  module Discordrb::API::Invite
3
5
  module_function
4
6
 
5
7
  # Resolve an invite
6
8
  # https://discordapp.com/developers/docs/resources/invite#get-invite
7
- def resolve(token, invite_code)
9
+ def resolve(token, invite_code, counts = true)
8
10
  Discordrb::API.request(
9
11
  :invite_code,
10
12
  nil,
11
13
  :get,
12
- "#{Discordrb::API.api_base}/invite/#{invite_code}",
14
+ "#{Discordrb::API.api_base}/invite/#{invite_code}#{counts ? '?with_counts=true' : ''}",
13
15
  Authorization: token
14
16
  )
15
17
  end
16
18
 
17
19
  # Delete an invite by code
18
20
  # https://discordapp.com/developers/docs/resources/invite#delete-invite
19
- def delete(token, code)
21
+ def delete(token, code, reason = nil)
20
22
  Discordrb::API.request(
21
23
  :invites_code,
22
24
  nil,
23
25
  :delete,
24
26
  "#{Discordrb::API.api_base}/invites/#{code}",
25
- Authorization: token
27
+ Authorization: token,
28
+ 'X-Audit-Log-Reason': reason
26
29
  )
27
30
  end
28
31
 
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # API calls for Server
2
4
  module Discordrb::API::Server
3
5
  module_function
4
6
 
5
7
  # Create a server
6
8
  # https://discordapp.com/developers/docs/resources/guild#create-guild
7
- def create(token, name, region = :london)
9
+ def create(token, name, region = :'eu-central')
8
10
  Discordrb::API.request(
9
11
  :guilds,
10
12
  nil,
@@ -30,20 +32,21 @@ module Discordrb::API::Server
30
32
 
31
33
  # Update a server
32
34
  # https://discordapp.com/developers/docs/resources/guild#modify-guild
33
- def update(token, server_id, name, region, icon, afk_channel_id, afk_timeout)
35
+ def update(token, server_id, name, region, icon, afk_channel_id, afk_timeout, splash, default_message_notifications, verification_level, explicit_content_filter, system_channel_id, reason = nil)
34
36
  Discordrb::API.request(
35
37
  :guilds_sid,
36
38
  server_id,
37
39
  :patch,
38
40
  "#{Discordrb::API.api_base}/guilds/#{server_id}",
39
- { name: name, region: region, icon: icon, afk_channel_id: afk_channel_id, afk_timeout: afk_timeout }.to_json,
41
+ { name: name, region: region, icon: icon, afk_channel_id: afk_channel_id, afk_timeout: afk_timeout, splash: splash, default_message_notifications: default_message_notifications, verification_level: verification_level, explicit_content_filter: explicit_content_filter, system_channel_id: system_channel_id }.to_json,
40
42
  Authorization: token,
41
- content_type: :json
43
+ content_type: :json,
44
+ 'X-Audit-Log-Reason': reason
42
45
  )
43
46
  end
44
47
 
45
48
  # Transfer server ownership
46
- def transfer_ownership(token, server_id, user_id)
49
+ def transfer_ownership(token, server_id, user_id, reason = nil)
47
50
  Discordrb::API.request(
48
51
  :guilds_sid,
49
52
  server_id,
@@ -51,7 +54,8 @@ module Discordrb::API::Server
51
54
  "#{Discordrb::API.api_base}/guilds/#{server_id}",
52
55
  { owner_id: user_id }.to_json,
53
56
  Authorization: token,
54
- content_type: :json
57
+ content_type: :json,
58
+ 'X-Audit-Log-Reason': reason
55
59
  )
56
60
  end
57
61
 
@@ -81,27 +85,28 @@ module Discordrb::API::Server
81
85
 
82
86
  # Create a channel
83
87
  # https://discordapp.com/developers/docs/resources/guild#create-guild-channel
84
- def create_channel(token, server_id, name, type)
88
+ def create_channel(token, server_id, name, type, topic, bitrate, user_limit, permission_overwrites, parent_id, nsfw, rate_limit_per_user, reason = nil)
85
89
  Discordrb::API.request(
86
90
  :guilds_sid_channels,
87
91
  server_id,
88
92
  :post,
89
93
  "#{Discordrb::API.api_base}/guilds/#{server_id}/channels",
90
- { name: name, type: type }.to_json,
94
+ { name: name, type: type, topic: topic, bitrate: bitrate, user_limit: user_limit, permission_overwrites: permission_overwrites, parent_id: parent_id, nsfw: nsfw, rate_limit_per_user: rate_limit_per_user }.to_json,
91
95
  Authorization: token,
92
- content_type: :json
96
+ content_type: :json,
97
+ 'X-Audit-Log-Reason': reason
93
98
  )
94
99
  end
95
100
 
96
101
  # Update a channels position
97
- # https://discordapp.com/developers/docs/resources/guild#modify-guild-channel
98
- def update_channel(token, server_id, channel_id, position)
102
+ # https://discordapp.com/developers/docs/resources/guild#modify-guild-channel-positions
103
+ def update_channel_positions(token, server_id, positions)
99
104
  Discordrb::API.request(
100
105
  :guilds_sid_channels,
101
106
  server_id,
102
107
  :patch,
103
108
  "#{Discordrb::API.api_base}/guilds/#{server_id}/channels",
104
- { id: channel_id, position: position }.to_json,
109
+ positions.to_json,
105
110
  Authorization: token,
106
111
  content_type: :json
107
112
  )
@@ -133,7 +138,7 @@ module Discordrb::API::Server
133
138
 
134
139
  # Update a user properties
135
140
  # https://discordapp.com/developers/docs/resources/guild#modify-guild-member
136
- def update_member(token, server_id, user_id, nick: nil, roles: nil, mute: nil, deaf: nil, channel_id: nil)
141
+ def update_member(token, server_id, user_id, nick: nil, roles: nil, mute: nil, deaf: nil, channel_id: nil, reason: nil)
137
142
  Discordrb::API.request(
138
143
  :guilds_sid_members_uid,
139
144
  server_id,
@@ -146,20 +151,22 @@ module Discordrb::API::Server
146
151
  channel_id: channel_id
147
152
  }.reject { |_, v| v.nil? }.to_json,
148
153
  Authorization: token,
149
- content_type: :json
154
+ content_type: :json,
155
+ 'X-Audit-Log-Reason': reason
150
156
  )
151
157
  end
152
158
 
153
159
  # Remove user from server
154
160
  # https://discordapp.com/developers/docs/resources/guild#remove-guild-member
155
- def remove_member(token, server_id, user_id)
161
+ def remove_member(token, server_id, user_id, reason = nil)
156
162
  Discordrb::API.request(
157
163
  :guilds_sid_members_uid,
158
164
  server_id,
159
165
  :delete,
160
166
  "#{Discordrb::API.api_base}/guilds/#{server_id}/members/#{user_id}",
161
167
  Authorization: token,
162
- content_type: :json
168
+ content_type: :json,
169
+ 'X-Audit-Log-Reason': reason
163
170
  )
164
171
  end
165
172
 
@@ -177,12 +184,13 @@ module Discordrb::API::Server
177
184
 
178
185
  # Ban a user from a server and delete their messages from the last message_days days
179
186
  # https://discordapp.com/developers/docs/resources/guild#create-guild-ban
180
- def ban_user(token, server_id, user_id, message_days)
187
+ def ban_user(token, server_id, user_id, message_days, reason = nil)
188
+ reason = URI.encode(reason) if reason
181
189
  Discordrb::API.request(
182
190
  :guilds_sid_bans_uid,
183
191
  server_id,
184
192
  :put,
185
- "#{Discordrb::API.api_base}/guilds/#{server_id}/bans/#{user_id}?delete-message-days=#{message_days}",
193
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/bans/#{user_id}?delete-message-days=#{message_days}&reason=#{reason}",
186
194
  nil,
187
195
  Authorization: token
188
196
  )
@@ -190,13 +198,14 @@ module Discordrb::API::Server
190
198
 
191
199
  # Unban a user from a server
192
200
  # https://discordapp.com/developers/docs/resources/guild#remove-guild-ban
193
- def unban_user(token, server_id, user_id)
201
+ def unban_user(token, server_id, user_id, reason = nil)
194
202
  Discordrb::API.request(
195
203
  :guilds_sid_bans_uid,
196
204
  server_id,
197
205
  :delete,
198
206
  "#{Discordrb::API.api_base}/guilds/#{server_id}/bans/#{user_id}",
199
- Authorization: token
207
+ Authorization: token,
208
+ 'X-Audit-Log-Reason': reason
200
209
  )
201
210
  end
202
211
 
@@ -212,16 +221,21 @@ module Discordrb::API::Server
212
221
  )
213
222
  end
214
223
 
215
- # Create a role (parameters such as name and colour will have to be set by update_role afterwards)
224
+ # Create a role (parameters such as name and colour if not set can be set by update_role afterwards)
225
+ # Permissions are the Discord defaults; allowed: invite creation, reading/sending messages,
226
+ # sending TTS messages, embedding links, sending files, reading the history, mentioning everybody,
227
+ # connecting to voice, speaking and voice activity (push-to-talk isn't mandatory)
216
228
  # https://discordapp.com/developers/docs/resources/guild#get-guild-roles
217
- def create_role(token, server_id)
229
+ def create_role(token, server_id, name, colour, hoist, mentionable, packed_permissions, reason = nil)
218
230
  Discordrb::API.request(
219
231
  :guilds_sid_roles,
220
232
  server_id,
221
233
  :post,
222
234
  "#{Discordrb::API.api_base}/guilds/#{server_id}/roles",
223
- nil,
224
- Authorization: token
235
+ { color: colour, name: name, hoist: hoist, mentionable: mentionable, permissions: packed_permissions }.to_json,
236
+ Authorization: token,
237
+ content_type: :json,
238
+ 'X-Audit-Log-Reason': reason
225
239
  )
226
240
  end
227
241
 
@@ -230,7 +244,7 @@ module Discordrb::API::Server
230
244
  # sending TTS messages, embedding links, sending files, reading the history, mentioning everybody,
231
245
  # connecting to voice, speaking and voice activity (push-to-talk isn't mandatory)
232
246
  # https://discordapp.com/developers/docs/resources/guild#batch-modify-guild-role
233
- def update_role(token, server_id, role_id, name, colour, hoist = false, mentionable = false, packed_permissions = 36_953_089)
247
+ def update_role(token, server_id, role_id, name, colour, hoist = false, mentionable = false, packed_permissions = 104_324_161, reason = nil)
234
248
  Discordrb::API.request(
235
249
  :guilds_sid_roles_rid,
236
250
  server_id,
@@ -238,44 +252,88 @@ module Discordrb::API::Server
238
252
  "#{Discordrb::API.api_base}/guilds/#{server_id}/roles/#{role_id}",
239
253
  { color: colour, name: name, hoist: hoist, mentionable: mentionable, permissions: packed_permissions }.to_json,
240
254
  Authorization: token,
255
+ content_type: :json,
256
+ 'X-Audit-Log-Reason': reason
257
+ )
258
+ end
259
+
260
+ # Update role positions
261
+ # https://discordapp.com/developers/docs/resources/guild#modify-guild-role-positions
262
+ def update_role_positions(token, server_id, roles)
263
+ Discordrb::API.request(
264
+ :guilds_sid_roles,
265
+ server_id,
266
+ :patch,
267
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/roles",
268
+ roles.to_json,
269
+ Authorization: token,
241
270
  content_type: :json
242
271
  )
243
272
  end
244
273
 
245
274
  # Delete a role
246
275
  # https://discordapp.com/developers/docs/resources/guild#delete-guild-role
247
- def delete_role(token, server_id, role_id)
276
+ def delete_role(token, server_id, role_id, reason = nil)
248
277
  Discordrb::API.request(
249
278
  :guilds_sid_roles_rid,
250
279
  server_id,
251
280
  :delete,
252
281
  "#{Discordrb::API.api_base}/guilds/#{server_id}/roles/#{role_id}",
253
- Authorization: token
282
+ Authorization: token,
283
+ 'X-Audit-Log-Reason': reason
284
+ )
285
+ end
286
+
287
+ # Adds a single role to a member
288
+ # https://discordapp.com/developers/docs/resources/guild#add-guild-member-role
289
+ def add_member_role(token, server_id, user_id, role_id, reason = nil)
290
+ Discordrb::API.request(
291
+ :guilds_sid_members_uid_roles_rid,
292
+ server_id,
293
+ :put,
294
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/members/#{user_id}/roles/#{role_id}",
295
+ nil,
296
+ Authorization: token,
297
+ 'X-Audit-Log-Reason': reason
298
+ )
299
+ end
300
+
301
+ # Removes a single role from a member
302
+ # https://discordapp.com/developers/docs/resources/guild#remove-guild-member-role
303
+ def remove_member_role(token, server_id, user_id, role_id, reason = nil)
304
+ Discordrb::API.request(
305
+ :guilds_sid_members_uid_roles_rid,
306
+ server_id,
307
+ :delete,
308
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/members/#{user_id}/roles/#{role_id}",
309
+ Authorization: token,
310
+ 'X-Audit-Log-Reason': reason
254
311
  )
255
312
  end
256
313
 
257
314
  # Get server prune count
258
315
  # https://discordapp.com/developers/docs/resources/guild#get-guild-prune-count
259
- def prune_count(token, server_id)
316
+ def prune_count(token, server_id, days)
260
317
  Discordrb::API.request(
261
318
  :guilds_sid_prune,
262
319
  server_id,
263
320
  :get,
264
- "#{Discordrb::API.api_base}/guilds/#{server_id}/prune",
321
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/prune?days=#{days}",
265
322
  Authorization: token
266
323
  )
267
324
  end
268
325
 
269
326
  # Begin server prune
270
327
  # https://discordapp.com/developers/docs/resources/guild#begin-guild-prune
271
- def begin_prune(token, server_id, days)
328
+ def begin_prune(token, server_id, days, reason = nil)
272
329
  Discordrb::API.request(
273
330
  :guilds_sid_prune,
274
331
  server_id,
275
332
  :post,
276
333
  "#{Discordrb::API.api_base}/guilds/#{server_id}/prune",
277
334
  { days: days },
278
- Authorization: token
335
+ Authorization: token,
336
+ 'X-Audit-Log-Reason': reason
279
337
  )
280
338
  end
281
339
 
@@ -291,6 +349,18 @@ module Discordrb::API::Server
291
349
  )
292
350
  end
293
351
 
352
+ # Gets a server's audit logs
353
+ # https://discordapp.com/developers/docs/resources/audit-log#get-guild-audit-log
354
+ def audit_logs(token, server_id, limit, userid = nil, actiontype = nil, before = nil)
355
+ Discordrb::API.request(
356
+ :guilds_sid_auditlogs,
357
+ server_id,
358
+ :get,
359
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/audit-logs?limit=#{limit}#{"&user_id=#{userid}" if userid}#{"&action_type=#{actiontype}" if actiontype}#{"&before=#{before}" if before}",
360
+ Authorization: token
361
+ )
362
+ end
363
+
294
364
  # Get server integrations
295
365
  # https://discordapp.com/developers/docs/resources/guild#get-guild-integrations
296
366
  def integrations(token, server_id)
@@ -355,8 +425,35 @@ module Discordrb::API::Server
355
425
  )
356
426
  end
357
427
 
428
+ # Retrieves a server's embed information
429
+ # https://discordapp.com/developers/docs/resources/guild#get-guild-embed
430
+ def embed(token, server_id)
431
+ Discordrb::API.request(
432
+ :guilds_sid_embed,
433
+ server_id,
434
+ :get,
435
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/embed",
436
+ Authorization: token
437
+ )
438
+ end
439
+
440
+ # Modify a server's embed settings
441
+ # https://discordapp.com/developers/docs/resources/guild#modify-guild-embed
442
+ def modify_embed(token, server_id, enabled, channel_id, reason = nil)
443
+ Discordrb::API.request(
444
+ :guilds_sid_embed,
445
+ server_id,
446
+ :patch,
447
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/embed",
448
+ { enabled: enabled, channel_id: channel_id }.to_json,
449
+ Authorization: token,
450
+ 'X-Audit-Log-Reason': reason,
451
+ content_type: :json
452
+ )
453
+ end
454
+
358
455
  # Adds a custom emoji
359
- def add_emoji(token, server_id, image, name)
456
+ def add_emoji(token, server_id, image, name, reason = nil)
360
457
  Discordrb::API.request(
361
458
  :guilds_sid_emojis,
362
459
  server_id,
@@ -364,12 +461,13 @@ module Discordrb::API::Server
364
461
  "#{Discordrb::API.api_base}/guilds/#{server_id}/emojis",
365
462
  { image: image, name: name }.to_json,
366
463
  Authorization: token,
367
- content_type: :json
464
+ content_type: :json,
465
+ 'X-Audit-Log-Reason': reason
368
466
  )
369
467
  end
370
468
 
371
469
  # Changes an emoji name
372
- def edit_emoji(token, server_id, emoji_id, name)
470
+ def edit_emoji(token, server_id, emoji_id, name, reason = nil)
373
471
  Discordrb::API.request(
374
472
  :guilds_sid_emojis_eid,
375
473
  server_id,
@@ -377,17 +475,56 @@ module Discordrb::API::Server
377
475
  "#{Discordrb::API.api_base}/guilds/#{server_id}/emojis/#{emoji_id}",
378
476
  { name: name }.to_json,
379
477
  Authorization: token,
380
- content_type: :json
478
+ content_type: :json,
479
+ 'X-Audit-Log-Reason': reason
381
480
  )
382
481
  end
383
482
 
384
483
  # Deletes a custom emoji
385
- def delete_emoji(token, server_id, emoji_id)
484
+ def delete_emoji(token, server_id, emoji_id, reason = nil)
386
485
  Discordrb::API.request(
387
486
  :guilds_sid_emojis_eid,
388
487
  server_id,
389
488
  :delete,
390
489
  "#{Discordrb::API.api_base}/guilds/#{server_id}/emojis/#{emoji_id}",
490
+ Authorization: token,
491
+ 'X-Audit-Log-Reason': reason
492
+ )
493
+ end
494
+
495
+ # Available voice regions for this server
496
+ def regions(token, server_id)
497
+ Discordrb::API.request(
498
+ :guilds_sid_regions,
499
+ server_id,
500
+ :get,
501
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/regions",
502
+ Authorization: token
503
+ )
504
+ end
505
+
506
+ # Get server webhooks
507
+ # https://discordapp.com/developers/docs/resources/webhook#get-guild-webhooks
508
+ def webhooks(token, server_id)
509
+ Discordrb::API.request(
510
+ :guilds_sid_webhooks,
511
+ server_id,
512
+ :get,
513
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/webhooks",
514
+ Authorization: token
515
+ )
516
+ end
517
+
518
+ # Adds a member to a server with an OAuth2 Bearer token that has been granted `guilds.join`
519
+ # https://discordapp.com/developers/docs/resources/guild#add-guild-member
520
+ def add_member(token, server_id, user_id, access_token, nick = nil, roles = [], mute = false, deaf = false)
521
+ Discordrb::API.request(
522
+ :guilds_sid_members_uid,
523
+ server_id,
524
+ :put,
525
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/members/#{user_id}",
526
+ { access_token: access_token, nick: nick, roles: roles, mute: mute, deaf: deaf }.to_json,
527
+ content_type: :json,
391
528
  Authorization: token
392
529
  )
393
530
  end