discordrb 3.3.0 → 3.4.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 (82) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +126 -0
  3. data/{CONTRIBUTING.md → .github/CONTRIBUTING.md} +0 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +25 -0
  6. data/.github/pull_request_template.md +37 -0
  7. data/.rubocop.yml +34 -37
  8. data/.travis.yml +5 -6
  9. data/CHANGELOG.md +472 -347
  10. data/Gemfile +2 -0
  11. data/LICENSE.txt +1 -1
  12. data/README.md +61 -79
  13. data/Rakefile +2 -0
  14. data/bin/console +1 -0
  15. data/discordrb-webhooks.gemspec +6 -6
  16. data/discordrb.gemspec +17 -17
  17. data/lib/discordrb.rb +73 -0
  18. data/lib/discordrb/allowed_mentions.rb +36 -0
  19. data/lib/discordrb/api.rb +40 -15
  20. data/lib/discordrb/api/channel.rb +57 -39
  21. data/lib/discordrb/api/invite.rb +3 -3
  22. data/lib/discordrb/api/server.rb +55 -50
  23. data/lib/discordrb/api/user.rb +8 -8
  24. data/lib/discordrb/api/webhook.rb +6 -6
  25. data/lib/discordrb/await.rb +0 -1
  26. data/lib/discordrb/bot.rb +164 -72
  27. data/lib/discordrb/cache.rb +4 -2
  28. data/lib/discordrb/colour_rgb.rb +43 -0
  29. data/lib/discordrb/commands/command_bot.rb +22 -6
  30. data/lib/discordrb/commands/container.rb +20 -23
  31. data/lib/discordrb/commands/parser.rb +18 -18
  32. data/lib/discordrb/commands/rate_limiter.rb +3 -2
  33. data/lib/discordrb/container.rb +77 -17
  34. data/lib/discordrb/data.rb +25 -4180
  35. data/lib/discordrb/data/activity.rb +264 -0
  36. data/lib/discordrb/data/application.rb +50 -0
  37. data/lib/discordrb/data/attachment.rb +56 -0
  38. data/lib/discordrb/data/audit_logs.rb +345 -0
  39. data/lib/discordrb/data/channel.rb +849 -0
  40. data/lib/discordrb/data/embed.rb +251 -0
  41. data/lib/discordrb/data/emoji.rb +82 -0
  42. data/lib/discordrb/data/integration.rb +83 -0
  43. data/lib/discordrb/data/invite.rb +137 -0
  44. data/lib/discordrb/data/member.rb +297 -0
  45. data/lib/discordrb/data/message.rb +334 -0
  46. data/lib/discordrb/data/overwrite.rb +102 -0
  47. data/lib/discordrb/data/profile.rb +91 -0
  48. data/lib/discordrb/data/reaction.rb +33 -0
  49. data/lib/discordrb/data/recipient.rb +34 -0
  50. data/lib/discordrb/data/role.rb +191 -0
  51. data/lib/discordrb/data/server.rb +1002 -0
  52. data/lib/discordrb/data/user.rb +204 -0
  53. data/lib/discordrb/data/voice_region.rb +45 -0
  54. data/lib/discordrb/data/voice_state.rb +41 -0
  55. data/lib/discordrb/data/webhook.rb +145 -0
  56. data/lib/discordrb/errors.rb +2 -1
  57. data/lib/discordrb/events/bans.rb +7 -5
  58. data/lib/discordrb/events/channels.rb +2 -0
  59. data/lib/discordrb/events/guilds.rb +16 -9
  60. data/lib/discordrb/events/invites.rb +125 -0
  61. data/lib/discordrb/events/members.rb +6 -2
  62. data/lib/discordrb/events/message.rb +69 -27
  63. data/lib/discordrb/events/presence.rb +14 -4
  64. data/lib/discordrb/events/raw.rb +1 -3
  65. data/lib/discordrb/events/reactions.rb +49 -3
  66. data/lib/discordrb/events/typing.rb +6 -4
  67. data/lib/discordrb/events/voice_server_update.rb +47 -0
  68. data/lib/discordrb/events/voice_state_update.rb +15 -10
  69. data/lib/discordrb/events/webhooks.rb +9 -6
  70. data/lib/discordrb/gateway.rb +72 -57
  71. data/lib/discordrb/id_object.rb +39 -0
  72. data/lib/discordrb/light/integrations.rb +1 -1
  73. data/lib/discordrb/light/light_bot.rb +1 -1
  74. data/lib/discordrb/logger.rb +4 -4
  75. data/lib/discordrb/paginator.rb +57 -0
  76. data/lib/discordrb/permissions.rb +103 -8
  77. data/lib/discordrb/version.rb +1 -1
  78. data/lib/discordrb/voice/encoder.rb +3 -3
  79. data/lib/discordrb/voice/network.rb +84 -43
  80. data/lib/discordrb/voice/sodium.rb +96 -0
  81. data/lib/discordrb/voice/voice_bot.rb +34 -26
  82. metadata +93 -55
@@ -9,10 +9,10 @@ require 'discordrb/errors'
9
9
  # List of methods representing endpoints in Discord's API
10
10
  module Discordrb::API
11
11
  # The base URL of the Discord REST API.
12
- APIBASE = 'https://discordapp.com/api/v6'.freeze
12
+ APIBASE = 'https://discord.com/api/v6'
13
13
 
14
14
  # The URL of Discord's CDN
15
- CDN_URL = 'https://cdn.discordapp.com'.freeze
15
+ CDN_URL = 'https://cdn.discordapp.com'
16
16
 
17
17
  module_function
18
18
 
@@ -31,12 +31,12 @@ module Discordrb::API
31
31
  @cdn_url || CDN_URL
32
32
  end
33
33
 
34
- # @return [String] the bot name, previously specified using #bot_name=.
34
+ # @return [String] the bot name, previously specified using {.bot_name=}.
35
35
  def bot_name
36
36
  @bot_name
37
37
  end
38
38
 
39
- # Sets the bot name to something.
39
+ # Sets the bot name to something. Used in {.user_agent}. For the bot's username, see {Profile#username=}.
40
40
  def bot_name=(value)
41
41
  @bot_name = value
42
42
  end
@@ -51,7 +51,7 @@ module Discordrb::API
51
51
  # Generate a user agent identifying this requester as discordrb.
52
52
  def user_agent
53
53
  # This particular string is required by the Discord devs.
54
- required = "DiscordBot (https://github.com/meew0/discordrb, v#{Discordrb::VERSION})"
54
+ required = "DiscordBot (https://github.com/shardlab/discordrb, v#{Discordrb::VERSION})"
55
55
  @bot_name ||= ''
56
56
 
57
57
  "#{required} rest-client/#{RestClient::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION}p#{RUBY_PATCHLEVEL} discordrb/#{Discordrb::VERSION} #{@bot_name}"
@@ -80,7 +80,7 @@ module Discordrb::API
80
80
  def raw_request(type, attributes)
81
81
  RestClient.send(type, *attributes)
82
82
  rescue RestClient::Forbidden => e
83
- # HACK: for #request, dynamically inject restclient's response into NoPermission - this allows us to ratelimit
83
+ # HACK: for #request, dynamically inject restclient's response into NoPermission - this allows us to rate limit
84
84
  noprm = Discordrb::Errors::NoPermission.new
85
85
  noprm.define_singleton_method(:_rc_response) { e.response }
86
86
  raise noprm, "The bot doesn't have the required permission to do this!"
@@ -94,6 +94,9 @@ module Discordrb::API
94
94
  # Add a custom user agent
95
95
  attributes.last[:user_agent] = user_agent if attributes.last.is_a? Hash
96
96
 
97
+ # Specify RateLimit precision
98
+ attributes.last[:x_ratelimit_precision] = 'millisecond'
99
+
97
100
  # The most recent Discord rate limit requirements require the support of major parameters, where a particular route
98
101
  # and major parameter combination (*not* the HTTP method) uniquely identifies a RL bucket.
99
102
  key = [key, major_parameter].freeze
@@ -149,17 +152,12 @@ module Discordrb::API
149
152
  response
150
153
  end
151
154
 
152
- # Handles premeptive ratelimiting by waiting the given mutex by the difference of the Date header to the
155
+ # Handles pre-emptive rate limiting by waiting the given mutex by the difference of the Date header to the
153
156
  # X-Ratelimit-Reset header, thus making sure we don't get 429'd in any subsequent requests.
154
157
  def handle_preemptive_rl(headers, mutex, key)
155
158
  Discordrb::LOGGER.ratelimit "RL bucket depletion detected! Date: #{headers[:date]} Reset: #{headers[:x_ratelimit_reset]}"
156
-
157
- now = Time.rfc2822(headers[:date])
158
- reset = Time.at(headers[:x_ratelimit_reset].to_i)
159
-
160
- delta = reset - now
161
-
162
- Discordrb::LOGGER.warn("Locking RL mutex (key: #{key}) for #{delta} seconds preemptively")
159
+ delta = headers[:x_ratelimit_reset_after].to_f
160
+ Discordrb::LOGGER.warn("Locking RL mutex (key: #{key}) for #{delta} seconds pre-emptively")
163
161
  sync_wait(delta, mutex)
164
162
  end
165
163
 
@@ -175,7 +173,7 @@ module Discordrb::API
175
173
  Discordrb::LOGGER.ratelimit("Trace (#{reason}):")
176
174
 
177
175
  caller.each do |str|
178
- Discordrb::LOGGER.ratelimit(' ' + str)
176
+ Discordrb::LOGGER.ratelimit(" #{str}")
179
177
  end
180
178
  end
181
179
 
@@ -199,11 +197,26 @@ module Discordrb::API
199
197
  "#{cdn_url}/splashes/#{server_id}/#{splash_id}.#{format}"
200
198
  end
201
199
 
200
+ # Make a banner URL from server and banner IDs
201
+ def banner_url(server_id, banner_id, format = 'webp')
202
+ "#{cdn_url}/banners/#{server_id}/#{banner_id}.#{format}"
203
+ end
204
+
202
205
  # Make an emoji icon URL from emoji ID
203
206
  def emoji_icon_url(emoji_id, format = 'webp')
204
207
  "#{cdn_url}/emojis/#{emoji_id}.#{format}"
205
208
  end
206
209
 
210
+ # Make an asset URL from application and asset IDs
211
+ def asset_url(application_id, asset_id, format = 'webp')
212
+ "#{cdn_url}/app-assets/#{application_id}/#{asset_id}.#{format}"
213
+ end
214
+
215
+ # Make an achievement icon URL from application ID, achievement ID, and icon hash
216
+ def achievement_icon_url(application_id, achievement_id, icon_hash, format = 'webp')
217
+ "#{cdn_url}/app-assets/#{application_id}/achievements/#{achievement_id}/icons/#{icon_hash}.#{format}"
218
+ end
219
+
207
220
  # Login to the server
208
221
  def login(email, password)
209
222
  request(
@@ -290,6 +303,18 @@ module Discordrb::API
290
303
  )
291
304
  end
292
305
 
306
+ # Get the gateway to be used, with additional information for sharding and
307
+ # session start limits
308
+ def gateway_bot(token)
309
+ request(
310
+ :gateway_bot,
311
+ nil,
312
+ :get,
313
+ "#{api_base}/gateway/bot",
314
+ Authorization: token
315
+ )
316
+ end
317
+
293
318
  # Validate a token (this request will fail if the token is invalid)
294
319
  def validate_token(token)
295
320
  request(
@@ -5,7 +5,7 @@ module Discordrb::API::Channel
5
5
  module_function
6
6
 
7
7
  # Get a channel's data
8
- # https://discordapp.com/developers/docs/resources/channel#get-channel
8
+ # https://discord.com/developers/docs/resources/channel#get-channel
9
9
  def resolve(token, channel_id)
10
10
  Discordrb::API.request(
11
11
  :channels_cid,
@@ -17,7 +17,7 @@ module Discordrb::API::Channel
17
17
  end
18
18
 
19
19
  # Update a channel's data
20
- # https://discordapp.com/developers/docs/resources/channel#modify-channel
20
+ # https://discord.com/developers/docs/resources/channel#modify-channel
21
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
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
23
  data[:permission_overwrites] = permission_overwrites unless permission_overwrites.nil?
@@ -34,7 +34,7 @@ module Discordrb::API::Channel
34
34
  end
35
35
 
36
36
  # Delete a channel
37
- # https://discordapp.com/developers/docs/resources/channel#deleteclose-channel
37
+ # https://discord.com/developers/docs/resources/channel#deleteclose-channel
38
38
  def delete(token, channel_id, reason = nil)
39
39
  Discordrb::API.request(
40
40
  :channels_cid,
@@ -47,7 +47,7 @@ module Discordrb::API::Channel
47
47
  end
48
48
 
49
49
  # Get a list of messages from a channel's history
50
- # https://discordapp.com/developers/docs/resources/channel#get-channel-messages
50
+ # https://discord.com/developers/docs/resources/channel#get-channel-messages
51
51
  def messages(token, channel_id, amount, before = nil, after = nil, around = nil)
52
52
  Discordrb::API.request(
53
53
  :channels_cid_messages,
@@ -59,7 +59,7 @@ module Discordrb::API::Channel
59
59
  end
60
60
 
61
61
  # Get a single message from a channel's history by id
62
- # https://discordapp.com/developers/docs/resources/channel#get-channel-message
62
+ # https://discord.com/developers/docs/resources/channel#get-channel-message
63
63
  def message(token, channel_id, message_id)
64
64
  Discordrb::API.request(
65
65
  :channels_cid_messages_mid,
@@ -72,24 +72,37 @@ module Discordrb::API::Channel
72
72
 
73
73
  # Send a message to a channel
74
74
  # https://discordapp.com/developers/docs/resources/channel#create-message
75
- def create_message(token, channel_id, message, tts = false, embed = nil, nonce = nil) # send message
75
+ # @param attachments [Array<File>, nil] Attachments to use with `attachment://` in embeds. See
76
+ # https://discord.com/developers/docs/resources/channel#create-message-using-attachments-within-embeds
77
+ def create_message(token, channel_id, message, tts = false, embed = nil, nonce = nil, attachments = nil, allowed_mentions = nil, message_reference = nil)
78
+ body = { content: message, tts: tts, embed: embed, nonce: nonce, allowed_mentions: allowed_mentions, message_reference: message_reference }
79
+ body = if attachments
80
+ files = [*0...attachments.size].zip(attachments).to_h
81
+ { **files, payload_json: body.to_json }
82
+ else
83
+ body.to_json
84
+ end
85
+
86
+ headers = { Authorization: token }
87
+ headers[:content_type] = :json unless attachments
88
+
76
89
  Discordrb::API.request(
77
90
  :channels_cid_messages_mid,
78
91
  channel_id,
79
92
  :post,
80
93
  "#{Discordrb::API.api_base}/channels/#{channel_id}/messages",
81
- { content: message, tts: tts, embed: embed, nonce: nonce }.to_json,
82
- Authorization: token,
83
- content_type: :json
94
+ body,
95
+ **headers
84
96
  )
85
97
  rescue RestClient::BadRequest => e
86
98
  parsed = JSON.parse(e.response.body)
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.'
99
+ raise Discordrb::Errors::MessageTooLong, "Message over the character limit (#{message.length} > 2000)" if parsed['content'].is_a?(Array) && parsed['content'].first == 'Must be 2000 or fewer in length.'
100
+
88
101
  raise
89
102
  end
90
103
 
91
104
  # Send a file as a message to a channel
92
- # https://discordapp.com/developers/docs/resources/channel#upload-file
105
+ # https://discord.com/developers/docs/resources/channel#upload-file
93
106
  def upload_file(token, channel_id, file, caption: nil, tts: false)
94
107
  Discordrb::API.request(
95
108
  :channels_cid_messages_mid,
@@ -102,7 +115,7 @@ module Discordrb::API::Channel
102
115
  end
103
116
 
104
117
  # Edit a message
105
- # https://discordapp.com/developers/docs/resources/channel#edit-message
118
+ # https://discord.com/developers/docs/resources/channel#edit-message
106
119
  def edit_message(token, channel_id, message_id, message, mentions = [], embed = nil)
107
120
  Discordrb::API.request(
108
121
  :channels_cid_messages_mid,
@@ -117,19 +130,20 @@ module Discordrb::API::Channel
117
130
 
118
131
  # Delete a message
119
132
  # https://discordapp.com/developers/docs/resources/channel#delete-message
120
- def delete_message(token, channel_id, message_id)
133
+ def delete_message(token, channel_id, message_id, reason = nil)
121
134
  Discordrb::API.request(
122
135
  :channels_cid_messages_mid,
123
136
  channel_id,
124
137
  :delete,
125
138
  "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}",
126
- Authorization: token
139
+ Authorization: token,
140
+ 'X-Audit-Log-Reason': reason
127
141
  )
128
142
  end
129
143
 
130
144
  # Delete messages in bulk
131
145
  # https://discordapp.com/developers/docs/resources/channel#bulk-delete-messages
132
- def bulk_delete_messages(token, channel_id, messages = [])
146
+ def bulk_delete_messages(token, channel_id, messages = [], reason = nil)
133
147
  Discordrb::API.request(
134
148
  :channels_cid_messages_bulk_delete,
135
149
  channel_id,
@@ -137,14 +151,15 @@ module Discordrb::API::Channel
137
151
  "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/bulk-delete",
138
152
  { messages: messages }.to_json,
139
153
  Authorization: token,
140
- content_type: :json
154
+ content_type: :json,
155
+ 'X-Audit-Log-Reason': reason
141
156
  )
142
157
  end
143
158
 
144
159
  # Create a reaction on a message using this client
145
- # https://discordapp.com/developers/docs/resources/channel#create-reaction
160
+ # https://discord.com/developers/docs/resources/channel#create-reaction
146
161
  def create_reaction(token, channel_id, message_id, emoji)
147
- emoji = URI.encode(emoji) unless emoji.ascii_only?
162
+ emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
148
163
  Discordrb::API.request(
149
164
  :channels_cid_messages_mid_reactions_emoji_me,
150
165
  channel_id,
@@ -157,9 +172,9 @@ module Discordrb::API::Channel
157
172
  end
158
173
 
159
174
  # Delete this client's own reaction on a message
160
- # https://discordapp.com/developers/docs/resources/channel#delete-own-reaction
175
+ # https://discord.com/developers/docs/resources/channel#delete-own-reaction
161
176
  def delete_own_reaction(token, channel_id, message_id, emoji)
162
- emoji = URI.encode(emoji) unless emoji.ascii_only?
177
+ emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
163
178
  Discordrb::API.request(
164
179
  :channels_cid_messages_mid_reactions_emoji_me,
165
180
  channel_id,
@@ -170,9 +185,9 @@ module Discordrb::API::Channel
170
185
  end
171
186
 
172
187
  # Delete another client's reaction on a message
173
- # https://discordapp.com/developers/docs/resources/channel#delete-user-reaction
188
+ # https://discord.com/developers/docs/resources/channel#delete-user-reaction
174
189
  def delete_user_reaction(token, channel_id, message_id, emoji, user_id)
175
- emoji = URI.encode(emoji) unless emoji.ascii_only?
190
+ emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
176
191
  Discordrb::API.request(
177
192
  :channels_cid_messages_mid_reactions_emoji_uid,
178
193
  channel_id,
@@ -183,20 +198,21 @@ module Discordrb::API::Channel
183
198
  end
184
199
 
185
200
  # Get a list of clients who reacted with a specific reaction on a message
186
- # https://discordapp.com/developers/docs/resources/channel#get-reactions
187
- def get_reactions(token, channel_id, message_id, emoji)
188
- emoji = URI.encode(emoji) unless emoji.ascii_only?
201
+ # https://discord.com/developers/docs/resources/channel#get-reactions
202
+ def get_reactions(token, channel_id, message_id, emoji, before_id, after_id, limit = 100)
203
+ emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
204
+ query_string = "limit=#{limit}#{"&before=#{before_id}" if before_id}#{"&after=#{after_id}" if after_id}"
189
205
  Discordrb::API.request(
190
206
  :channels_cid_messages_mid_reactions_emoji,
191
207
  channel_id,
192
208
  :get,
193
- "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}",
209
+ "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}?#{query_string}",
194
210
  Authorization: token
195
211
  )
196
212
  end
197
213
 
198
214
  # Deletes all reactions on a message from all clients
199
- # https://discordapp.com/developers/docs/resources/channel#delete-all-reactions
215
+ # https://discord.com/developers/docs/resources/channel#delete-all-reactions
200
216
  def delete_all_reactions(token, channel_id, message_id)
201
217
  Discordrb::API.request(
202
218
  :channels_cid_messages_mid_reactions,
@@ -208,7 +224,7 @@ module Discordrb::API::Channel
208
224
  end
209
225
 
210
226
  # Update a channels permission for a role or member
211
- # https://discordapp.com/developers/docs/resources/channel#edit-channel-permissions
227
+ # https://discord.com/developers/docs/resources/channel#edit-channel-permissions
212
228
  def update_permission(token, channel_id, overwrite_id, allow, deny, type, reason = nil)
213
229
  Discordrb::API.request(
214
230
  :channels_cid_permissions_oid,
@@ -223,7 +239,7 @@ module Discordrb::API::Channel
223
239
  end
224
240
 
225
241
  # Get a channel's invite list
226
- # https://discordapp.com/developers/docs/resources/channel#get-channel-invites
242
+ # https://discord.com/developers/docs/resources/channel#get-channel-invites
227
243
  def invites(token, channel_id)
228
244
  Discordrb::API.request(
229
245
  :channels_cid_invites,
@@ -235,7 +251,7 @@ module Discordrb::API::Channel
235
251
  end
236
252
 
237
253
  # Create an instant invite from a server or a channel id
238
- # https://discordapp.com/developers/docs/resources/channel#create-channel-invite
254
+ # https://discord.com/developers/docs/resources/channel#create-channel-invite
239
255
  def create_invite(token, channel_id, max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil)
240
256
  Discordrb::API.request(
241
257
  :channels_cid_invites,
@@ -250,7 +266,7 @@ module Discordrb::API::Channel
250
266
  end
251
267
 
252
268
  # Delete channel permission
253
- # https://discordapp.com/developers/docs/resources/channel#delete-channel-permission
269
+ # https://discord.com/developers/docs/resources/channel#delete-channel-permission
254
270
  def delete_permission(token, channel_id, overwrite_id, reason = nil)
255
271
  Discordrb::API.request(
256
272
  :channels_cid_permissions_oid,
@@ -263,7 +279,7 @@ module Discordrb::API::Channel
263
279
  end
264
280
 
265
281
  # Start typing (needs to be resent every 5 seconds to keep up the typing)
266
- # https://discordapp.com/developers/docs/resources/channel#trigger-typing-indicator
282
+ # https://discord.com/developers/docs/resources/channel#trigger-typing-indicator
267
283
  def start_typing(token, channel_id)
268
284
  Discordrb::API.request(
269
285
  :channels_cid_typing,
@@ -276,7 +292,7 @@ module Discordrb::API::Channel
276
292
  end
277
293
 
278
294
  # Get a list of pinned messages in a channel
279
- # https://discordapp.com/developers/docs/resources/channel#get-pinned-messages
295
+ # https://discord.com/developers/docs/resources/channel#get-pinned-messages
280
296
  def pinned_messages(token, channel_id)
281
297
  Discordrb::API.request(
282
298
  :channels_cid_pins,
@@ -289,26 +305,28 @@ module Discordrb::API::Channel
289
305
 
290
306
  # Pin a message
291
307
  # https://discordapp.com/developers/docs/resources/channel#add-pinned-channel-message
292
- def pin_message(token, channel_id, message_id)
308
+ def pin_message(token, channel_id, message_id, reason = nil)
293
309
  Discordrb::API.request(
294
310
  :channels_cid_pins_mid,
295
311
  channel_id,
296
312
  :put,
297
313
  "#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{message_id}",
298
314
  nil,
299
- Authorization: token
315
+ Authorization: token,
316
+ 'X-Audit-Log-Reason': reason
300
317
  )
301
318
  end
302
319
 
303
320
  # Unpin a message
304
321
  # https://discordapp.com/developers/docs/resources/channel#delete-pinned-channel-message
305
- def unpin_message(token, channel_id, message_id)
322
+ def unpin_message(token, channel_id, message_id, reason = nil)
306
323
  Discordrb::API.request(
307
324
  :channels_cid_pins_mid,
308
325
  channel_id,
309
326
  :delete,
310
327
  "#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{message_id}",
311
- Authorization: token
328
+ Authorization: token,
329
+ 'X-Audit-Log-Reason': reason
312
330
  )
313
331
  end
314
332
 
@@ -382,7 +400,7 @@ module Discordrb::API::Channel
382
400
  end
383
401
 
384
402
  # Create a webhook
385
- # https://discordapp.com/developers/docs/resources/webhook#create-webhook
403
+ # https://discord.com/developers/docs/resources/webhook#create-webhook
386
404
  def create_webhook(token, channel_id, name, avatar = nil, reason = nil)
387
405
  Discordrb::API.request(
388
406
  :channels_cid_webhooks,
@@ -397,7 +415,7 @@ module Discordrb::API::Channel
397
415
  end
398
416
 
399
417
  # Get channel webhooks
400
- # https://discordapp.com/developers/docs/resources/webhook#get-channel-webhooks
418
+ # https://discord.com/developers/docs/resources/webhook#get-channel-webhooks
401
419
  def webhooks(token, channel_id)
402
420
  Discordrb::API.request(
403
421
  :channels_cid_webhooks,
@@ -5,7 +5,7 @@ module Discordrb::API::Invite
5
5
  module_function
6
6
 
7
7
  # Resolve an invite
8
- # https://discordapp.com/developers/docs/resources/invite#get-invite
8
+ # https://discord.com/developers/docs/resources/invite#get-invite
9
9
  def resolve(token, invite_code, counts = true)
10
10
  Discordrb::API.request(
11
11
  :invite_code,
@@ -17,7 +17,7 @@ module Discordrb::API::Invite
17
17
  end
18
18
 
19
19
  # Delete an invite by code
20
- # https://discordapp.com/developers/docs/resources/invite#delete-invite
20
+ # https://discord.com/developers/docs/resources/invite#delete-invite
21
21
  def delete(token, code, reason = nil)
22
22
  Discordrb::API.request(
23
23
  :invites_code,
@@ -30,7 +30,7 @@ module Discordrb::API::Invite
30
30
  end
31
31
 
32
32
  # Join a server using an invite
33
- # https://discordapp.com/developers/docs/resources/invite#accept-invite
33
+ # https://discord.com/developers/docs/resources/invite#accept-invite
34
34
  def accept(token, invite_code)
35
35
  Discordrb::API.request(
36
36
  :invite_code,
@@ -5,7 +5,7 @@ module Discordrb::API::Server
5
5
  module_function
6
6
 
7
7
  # Create a server
8
- # https://discordapp.com/developers/docs/resources/guild#create-guild
8
+ # https://discord.com/developers/docs/resources/guild#create-guild
9
9
  def create(token, name, region = :'eu-central')
10
10
  Discordrb::API.request(
11
11
  :guilds,
@@ -19,19 +19,19 @@ module Discordrb::API::Server
19
19
  end
20
20
 
21
21
  # Get a server's data
22
- # https://discordapp.com/developers/docs/resources/guild#get-guild
23
- def resolve(token, server_id)
22
+ # https://discord.com/developers/docs/resources/guild#get-guild
23
+ def resolve(token, server_id, with_counts = nil)
24
24
  Discordrb::API.request(
25
25
  :guilds_sid,
26
26
  server_id,
27
27
  :get,
28
- "#{Discordrb::API.api_base}/guilds/#{server_id}",
28
+ "#{Discordrb::API.api_base}/guilds/#{server_id}#{'?with_counts=true' if with_counts}",
29
29
  Authorization: token
30
30
  )
31
31
  end
32
32
 
33
33
  # Update a server
34
- # https://discordapp.com/developers/docs/resources/guild#modify-guild
34
+ # https://discord.com/developers/docs/resources/guild#modify-guild
35
35
  def update(token, server_id, name, region, icon, afk_channel_id, afk_timeout, splash, default_message_notifications, verification_level, explicit_content_filter, system_channel_id, reason = nil)
36
36
  Discordrb::API.request(
37
37
  :guilds_sid,
@@ -60,7 +60,7 @@ module Discordrb::API::Server
60
60
  end
61
61
 
62
62
  # Delete a server
63
- # https://discordapp.com/developers/docs/resources/guild#delete-guild
63
+ # https://discord.com/developers/docs/resources/guild#delete-guild
64
64
  def delete(token, server_id)
65
65
  Discordrb::API.request(
66
66
  :guilds_sid,
@@ -72,7 +72,7 @@ module Discordrb::API::Server
72
72
  end
73
73
 
74
74
  # Get a server's channels list
75
- # https://discordapp.com/developers/docs/resources/guild#get-guild-channels
75
+ # https://discord.com/developers/docs/resources/guild#get-guild-channels
76
76
  def channels(token, server_id)
77
77
  Discordrb::API.request(
78
78
  :guilds_sid_channels,
@@ -84,14 +84,14 @@ module Discordrb::API::Server
84
84
  end
85
85
 
86
86
  # Create a channel
87
- # https://discordapp.com/developers/docs/resources/guild#create-guild-channel
88
- def create_channel(token, server_id, name, type, topic, bitrate, user_limit, permission_overwrites, parent_id, nsfw, rate_limit_per_user, reason = nil)
87
+ # https://discord.com/developers/docs/resources/guild#create-guild-channel
88
+ def create_channel(token, server_id, name, type, topic, bitrate, user_limit, permission_overwrites, parent_id, nsfw, rate_limit_per_user, position, reason = nil)
89
89
  Discordrb::API.request(
90
90
  :guilds_sid_channels,
91
91
  server_id,
92
92
  :post,
93
93
  "#{Discordrb::API.api_base}/guilds/#{server_id}/channels",
94
- { name: name, type: type, topic: topic, bitrate: bitrate, user_limit: user_limit, permission_overwrites: permission_overwrites, parent_id: parent_id, nsfw: nsfw, rate_limit_per_user: rate_limit_per_user }.to_json,
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, position: position }.to_json,
95
95
  Authorization: token,
96
96
  content_type: :json,
97
97
  'X-Audit-Log-Reason': reason
@@ -99,7 +99,7 @@ module Discordrb::API::Server
99
99
  end
100
100
 
101
101
  # Update a channels position
102
- # https://discordapp.com/developers/docs/resources/guild#modify-guild-channel-positions
102
+ # https://discord.com/developers/docs/resources/guild#modify-guild-channel-positions
103
103
  def update_channel_positions(token, server_id, positions)
104
104
  Discordrb::API.request(
105
105
  :guilds_sid_channels,
@@ -113,7 +113,7 @@ module Discordrb::API::Server
113
113
  end
114
114
 
115
115
  # Get a member's data
116
- # https://discordapp.com/developers/docs/resources/guild#get-guild-member
116
+ # https://discord.com/developers/docs/resources/guild#get-guild-member
117
117
  def resolve_member(token, server_id, user_id)
118
118
  Discordrb::API.request(
119
119
  :guilds_sid_members_uid,
@@ -125,7 +125,7 @@ module Discordrb::API::Server
125
125
  end
126
126
 
127
127
  # Gets members from the server
128
- # https://discordapp.com/developers/docs/resources/guild#list-guild-members
128
+ # https://discord.com/developers/docs/resources/guild#list-guild-members
129
129
  def resolve_members(token, server_id, limit, after = nil)
130
130
  Discordrb::API.request(
131
131
  :guilds_sid_members,
@@ -137,7 +137,7 @@ module Discordrb::API::Server
137
137
  end
138
138
 
139
139
  # Update a user properties
140
- # https://discordapp.com/developers/docs/resources/guild#modify-guild-member
140
+ # https://discord.com/developers/docs/resources/guild#modify-guild-member
141
141
  def update_member(token, server_id, user_id, nick: nil, roles: nil, mute: nil, deaf: nil, channel_id: nil, reason: nil)
142
142
  Discordrb::API.request(
143
143
  :guilds_sid_members_uid,
@@ -149,7 +149,7 @@ module Discordrb::API::Server
149
149
  mute: mute,
150
150
  deaf: deaf,
151
151
  channel_id: channel_id
152
- }.reject { |_, v| v.nil? }.to_json,
152
+ }.compact.to_json,
153
153
  Authorization: token,
154
154
  content_type: :json,
155
155
  'X-Audit-Log-Reason': reason
@@ -157,7 +157,7 @@ module Discordrb::API::Server
157
157
  end
158
158
 
159
159
  # Remove user from server
160
- # https://discordapp.com/developers/docs/resources/guild#remove-guild-member
160
+ # https://discord.com/developers/docs/resources/guild#remove-guild-member
161
161
  def remove_member(token, server_id, user_id, reason = nil)
162
162
  Discordrb::API.request(
163
163
  :guilds_sid_members_uid,
@@ -171,7 +171,7 @@ module Discordrb::API::Server
171
171
  end
172
172
 
173
173
  # Get a server's banned users
174
- # https://discordapp.com/developers/docs/resources/guild#get-guild-bans
174
+ # https://discord.com/developers/docs/resources/guild#get-guild-bans
175
175
  def bans(token, server_id)
176
176
  Discordrb::API.request(
177
177
  :guilds_sid_bans,
@@ -183,9 +183,9 @@ module Discordrb::API::Server
183
183
  end
184
184
 
185
185
  # Ban a user from a server and delete their messages from the last message_days days
186
- # https://discordapp.com/developers/docs/resources/guild#create-guild-ban
186
+ # https://discord.com/developers/docs/resources/guild#create-guild-ban
187
187
  def ban_user(token, server_id, user_id, message_days, reason = nil)
188
- reason = URI.encode(reason) if reason
188
+ reason = URI.encode_www_form_component(reason) if reason
189
189
  Discordrb::API.request(
190
190
  :guilds_sid_bans_uid,
191
191
  server_id,
@@ -197,7 +197,7 @@ module Discordrb::API::Server
197
197
  end
198
198
 
199
199
  # Unban a user from a server
200
- # https://discordapp.com/developers/docs/resources/guild#remove-guild-ban
200
+ # https://discord.com/developers/docs/resources/guild#remove-guild-ban
201
201
  def unban_user(token, server_id, user_id, reason = nil)
202
202
  Discordrb::API.request(
203
203
  :guilds_sid_bans_uid,
@@ -210,7 +210,7 @@ module Discordrb::API::Server
210
210
  end
211
211
 
212
212
  # Get server roles
213
- # https://discordapp.com/developers/docs/resources/guild#get-guild-roles
213
+ # https://discord.com/developers/docs/resources/guild#get-guild-roles
214
214
  def roles(token, server_id)
215
215
  Discordrb::API.request(
216
216
  :guilds_sid_roles,
@@ -225,7 +225,7 @@ module Discordrb::API::Server
225
225
  # Permissions are the Discord defaults; allowed: invite creation, reading/sending messages,
226
226
  # sending TTS messages, embedding links, sending files, reading the history, mentioning everybody,
227
227
  # connecting to voice, speaking and voice activity (push-to-talk isn't mandatory)
228
- # https://discordapp.com/developers/docs/resources/guild#get-guild-roles
228
+ # https://discord.com/developers/docs/resources/guild#get-guild-roles
229
229
  def create_role(token, server_id, name, colour, hoist, mentionable, packed_permissions, reason = nil)
230
230
  Discordrb::API.request(
231
231
  :guilds_sid_roles,
@@ -243,7 +243,7 @@ module Discordrb::API::Server
243
243
  # Permissions are the Discord defaults; allowed: invite creation, reading/sending messages,
244
244
  # sending TTS messages, embedding links, sending files, reading the history, mentioning everybody,
245
245
  # connecting to voice, speaking and voice activity (push-to-talk isn't mandatory)
246
- # https://discordapp.com/developers/docs/resources/guild#batch-modify-guild-role
246
+ # https://discord.com/developers/docs/resources/guild#batch-modify-guild-role
247
247
  def update_role(token, server_id, role_id, name, colour, hoist = false, mentionable = false, packed_permissions = 104_324_161, reason = nil)
248
248
  Discordrb::API.request(
249
249
  :guilds_sid_roles_rid,
@@ -258,7 +258,7 @@ module Discordrb::API::Server
258
258
  end
259
259
 
260
260
  # Update role positions
261
- # https://discordapp.com/developers/docs/resources/guild#modify-guild-role-positions
261
+ # https://discord.com/developers/docs/resources/guild#modify-guild-role-positions
262
262
  def update_role_positions(token, server_id, roles)
263
263
  Discordrb::API.request(
264
264
  :guilds_sid_roles,
@@ -272,7 +272,7 @@ module Discordrb::API::Server
272
272
  end
273
273
 
274
274
  # Delete a role
275
- # https://discordapp.com/developers/docs/resources/guild#delete-guild-role
275
+ # https://discord.com/developers/docs/resources/guild#delete-guild-role
276
276
  def delete_role(token, server_id, role_id, reason = nil)
277
277
  Discordrb::API.request(
278
278
  :guilds_sid_roles_rid,
@@ -285,7 +285,7 @@ module Discordrb::API::Server
285
285
  end
286
286
 
287
287
  # Adds a single role to a member
288
- # https://discordapp.com/developers/docs/resources/guild#add-guild-member-role
288
+ # https://discord.com/developers/docs/resources/guild#add-guild-member-role
289
289
  def add_member_role(token, server_id, user_id, role_id, reason = nil)
290
290
  Discordrb::API.request(
291
291
  :guilds_sid_members_uid_roles_rid,
@@ -299,7 +299,7 @@ module Discordrb::API::Server
299
299
  end
300
300
 
301
301
  # Removes a single role from a member
302
- # https://discordapp.com/developers/docs/resources/guild#remove-guild-member-role
302
+ # https://discord.com/developers/docs/resources/guild#remove-guild-member-role
303
303
  def remove_member_role(token, server_id, user_id, role_id, reason = nil)
304
304
  Discordrb::API.request(
305
305
  :guilds_sid_members_uid_roles_rid,
@@ -312,7 +312,7 @@ module Discordrb::API::Server
312
312
  end
313
313
 
314
314
  # Get server prune count
315
- # https://discordapp.com/developers/docs/resources/guild#get-guild-prune-count
315
+ # https://discord.com/developers/docs/resources/guild#get-guild-prune-count
316
316
  def prune_count(token, server_id, days)
317
317
  Discordrb::API.request(
318
318
  :guilds_sid_prune,
@@ -324,7 +324,7 @@ module Discordrb::API::Server
324
324
  end
325
325
 
326
326
  # Begin server prune
327
- # https://discordapp.com/developers/docs/resources/guild#begin-guild-prune
327
+ # https://discord.com/developers/docs/resources/guild#begin-guild-prune
328
328
  def begin_prune(token, server_id, days, reason = nil)
329
329
  Discordrb::API.request(
330
330
  :guilds_sid_prune,
@@ -338,7 +338,7 @@ module Discordrb::API::Server
338
338
  end
339
339
 
340
340
  # Get invites from server
341
- # https://discordapp.com/developers/docs/resources/guild#get-guild-invites
341
+ # https://discord.com/developers/docs/resources/guild#get-guild-invites
342
342
  def invites(token, server_id)
343
343
  Discordrb::API.request(
344
344
  :guilds_sid_invites,
@@ -350,19 +350,19 @@ module Discordrb::API::Server
350
350
  end
351
351
 
352
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)
353
+ # https://discord.com/developers/docs/resources/audit-log#get-guild-audit-log
354
+ def audit_logs(token, server_id, limit, user_id = nil, action_type = nil, before = nil)
355
355
  Discordrb::API.request(
356
356
  :guilds_sid_auditlogs,
357
357
  server_id,
358
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}",
359
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/audit-logs?limit=#{limit}#{"&user_id=#{user_id}" if user_id}#{"&action_type=#{action_type}" if action_type}#{"&before=#{before}" if before}",
360
360
  Authorization: token
361
361
  )
362
362
  end
363
363
 
364
364
  # Get server integrations
365
- # https://discordapp.com/developers/docs/resources/guild#get-guild-integrations
365
+ # https://discord.com/developers/docs/resources/guild#get-guild-integrations
366
366
  def integrations(token, server_id)
367
367
  Discordrb::API.request(
368
368
  :guilds_sid_integrations,
@@ -375,19 +375,20 @@ module Discordrb::API::Server
375
375
 
376
376
  # Create a server integration
377
377
  # https://discordapp.com/developers/docs/resources/guild#create-guild-integration
378
- def create_integration(token, server_id, type, id)
378
+ def create_integration(token, server_id, type, id, reason = nil)
379
379
  Discordrb::API.request(
380
380
  :guilds_sid_integrations,
381
381
  server_id,
382
382
  :post,
383
383
  "#{Discordrb::API.api_base}/guilds/#{server_id}/integrations",
384
384
  { type: type, id: id },
385
- Authorization: token
385
+ Authorization: token,
386
+ 'X-Audit-Log-Reason': reason
386
387
  )
387
388
  end
388
389
 
389
390
  # Update integration from server
390
- # https://discordapp.com/developers/docs/resources/guild#modify-guild-integration
391
+ # https://discord.com/developers/docs/resources/guild#modify-guild-integration
391
392
  def update_integration(token, server_id, integration_id, expire_behavior, expire_grace_period, enable_emoticons)
392
393
  Discordrb::API.request(
393
394
  :guilds_sid_integrations_iid,
@@ -402,18 +403,19 @@ module Discordrb::API::Server
402
403
 
403
404
  # Delete a server integration
404
405
  # https://discordapp.com/developers/docs/resources/guild#delete-guild-integration
405
- def delete_integration(token, server_id, integration_id)
406
+ def delete_integration(token, server_id, integration_id, reason = nil)
406
407
  Discordrb::API.request(
407
408
  :guilds_sid_integrations_iid,
408
409
  server_id,
409
410
  :delete,
410
411
  "#{Discordrb::API.api_base}/guilds/#{server_id}/integrations/#{integration_id}",
411
- Authorization: token
412
+ Authorization: token,
413
+ 'X-Audit-Log-Reason': reason
412
414
  )
413
415
  end
414
416
 
415
417
  # Sync an integration
416
- # https://discordapp.com/developers/docs/resources/guild#sync-guild-integration
418
+ # https://discord.com/developers/docs/resources/guild#sync-guild-integration
417
419
  def sync_integration(token, server_id, integration_id)
418
420
  Discordrb::API.request(
419
421
  :guilds_sid_integrations_iid_sync,
@@ -426,7 +428,7 @@ module Discordrb::API::Server
426
428
  end
427
429
 
428
430
  # Retrieves a server's embed information
429
- # https://discordapp.com/developers/docs/resources/guild#get-guild-embed
431
+ # https://discord.com/developers/docs/resources/guild#get-guild-embed
430
432
  def embed(token, server_id)
431
433
  Discordrb::API.request(
432
434
  :guilds_sid_embed,
@@ -438,7 +440,7 @@ module Discordrb::API::Server
438
440
  end
439
441
 
440
442
  # Modify a server's embed settings
441
- # https://discordapp.com/developers/docs/resources/guild#modify-guild-embed
443
+ # https://discord.com/developers/docs/resources/guild#modify-guild-embed
442
444
  def modify_embed(token, server_id, enabled, channel_id, reason = nil)
443
445
  Discordrb::API.request(
444
446
  :guilds_sid_embed,
@@ -452,28 +454,30 @@ module Discordrb::API::Server
452
454
  )
453
455
  end
454
456
 
455
- # Adds a custom emoji
456
- def add_emoji(token, server_id, image, name, reason = nil)
457
+ # Adds a custom emoji.
458
+ # https://discord.com/developers/docs/resources/emoji#create-guild-emoji
459
+ def add_emoji(token, server_id, image, name, roles = [], reason = nil)
457
460
  Discordrb::API.request(
458
461
  :guilds_sid_emojis,
459
462
  server_id,
460
463
  :post,
461
464
  "#{Discordrb::API.api_base}/guilds/#{server_id}/emojis",
462
- { image: image, name: name }.to_json,
465
+ { image: image, name: name, roles: roles }.to_json,
463
466
  Authorization: token,
464
467
  content_type: :json,
465
468
  'X-Audit-Log-Reason': reason
466
469
  )
467
470
  end
468
471
 
469
- # Changes an emoji name
470
- def edit_emoji(token, server_id, emoji_id, name, reason = nil)
472
+ # Changes an emoji name and/or roles.
473
+ # https://discord.com/developers/docs/resources/emoji#modify-guild-emoji
474
+ def edit_emoji(token, server_id, emoji_id, name, roles = nil, reason = nil)
471
475
  Discordrb::API.request(
472
476
  :guilds_sid_emojis_eid,
473
477
  server_id,
474
478
  :patch,
475
479
  "#{Discordrb::API.api_base}/guilds/#{server_id}/emojis/#{emoji_id}",
476
- { name: name }.to_json,
480
+ { name: name, roles: roles }.to_json,
477
481
  Authorization: token,
478
482
  content_type: :json,
479
483
  'X-Audit-Log-Reason': reason
@@ -481,6 +485,7 @@ module Discordrb::API::Server
481
485
  end
482
486
 
483
487
  # Deletes a custom emoji
488
+ # https://discord.com/developers/docs/resources/emoji#delete-guild-emoji
484
489
  def delete_emoji(token, server_id, emoji_id, reason = nil)
485
490
  Discordrb::API.request(
486
491
  :guilds_sid_emojis_eid,
@@ -504,7 +509,7 @@ module Discordrb::API::Server
504
509
  end
505
510
 
506
511
  # Get server webhooks
507
- # https://discordapp.com/developers/docs/resources/webhook#get-guild-webhooks
512
+ # https://discord.com/developers/docs/resources/webhook#get-guild-webhooks
508
513
  def webhooks(token, server_id)
509
514
  Discordrb::API.request(
510
515
  :guilds_sid_webhooks,
@@ -516,7 +521,7 @@ module Discordrb::API::Server
516
521
  end
517
522
 
518
523
  # 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
524
+ # https://discord.com/developers/docs/resources/guild#add-guild-member
520
525
  def add_member(token, server_id, user_id, access_token, nick = nil, roles = [], mute = false, deaf = false)
521
526
  Discordrb::API.request(
522
527
  :guilds_sid_members_uid,