discordrb 3.1.1 → 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 (91) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +126 -0
  3. data/.codeclimate.yml +16 -0
  4. data/.github/CONTRIBUTING.md +13 -0
  5. data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
  6. data/.github/ISSUE_TEMPLATE/feature_request.md +25 -0
  7. data/.github/pull_request_template.md +37 -0
  8. data/.gitignore +5 -0
  9. data/.rubocop.yml +39 -33
  10. data/.travis.yml +27 -2
  11. data/.yardopts +1 -1
  12. data/CHANGELOG.md +808 -208
  13. data/Gemfile +4 -1
  14. data/LICENSE.txt +1 -1
  15. data/README.md +108 -53
  16. data/Rakefile +14 -1
  17. data/bin/console +1 -0
  18. data/bin/travis_build_docs.sh +17 -0
  19. data/discordrb-webhooks.gemspec +26 -0
  20. data/discordrb.gemspec +24 -15
  21. data/lib/discordrb.rb +75 -2
  22. data/lib/discordrb/allowed_mentions.rb +36 -0
  23. data/lib/discordrb/api.rb +126 -27
  24. data/lib/discordrb/api/channel.rb +165 -43
  25. data/lib/discordrb/api/invite.rb +10 -7
  26. data/lib/discordrb/api/server.rb +240 -61
  27. data/lib/discordrb/api/user.rb +26 -24
  28. data/lib/discordrb/api/webhook.rb +83 -0
  29. data/lib/discordrb/await.rb +1 -2
  30. data/lib/discordrb/bot.rb +417 -149
  31. data/lib/discordrb/cache.rb +42 -10
  32. data/lib/discordrb/colour_rgb.rb +43 -0
  33. data/lib/discordrb/commands/command_bot.rb +186 -31
  34. data/lib/discordrb/commands/container.rb +30 -16
  35. data/lib/discordrb/commands/parser.rb +102 -47
  36. data/lib/discordrb/commands/rate_limiter.rb +18 -17
  37. data/lib/discordrb/container.rb +245 -41
  38. data/lib/discordrb/data.rb +27 -2511
  39. data/lib/discordrb/data/activity.rb +264 -0
  40. data/lib/discordrb/data/application.rb +50 -0
  41. data/lib/discordrb/data/attachment.rb +56 -0
  42. data/lib/discordrb/data/audit_logs.rb +345 -0
  43. data/lib/discordrb/data/channel.rb +849 -0
  44. data/lib/discordrb/data/embed.rb +251 -0
  45. data/lib/discordrb/data/emoji.rb +82 -0
  46. data/lib/discordrb/data/integration.rb +83 -0
  47. data/lib/discordrb/data/invite.rb +137 -0
  48. data/lib/discordrb/data/member.rb +297 -0
  49. data/lib/discordrb/data/message.rb +334 -0
  50. data/lib/discordrb/data/overwrite.rb +102 -0
  51. data/lib/discordrb/data/profile.rb +91 -0
  52. data/lib/discordrb/data/reaction.rb +33 -0
  53. data/lib/discordrb/data/recipient.rb +34 -0
  54. data/lib/discordrb/data/role.rb +191 -0
  55. data/lib/discordrb/data/server.rb +1002 -0
  56. data/lib/discordrb/data/user.rb +204 -0
  57. data/lib/discordrb/data/voice_region.rb +45 -0
  58. data/lib/discordrb/data/voice_state.rb +41 -0
  59. data/lib/discordrb/data/webhook.rb +145 -0
  60. data/lib/discordrb/errors.rb +36 -2
  61. data/lib/discordrb/events/bans.rb +7 -5
  62. data/lib/discordrb/events/channels.rb +2 -0
  63. data/lib/discordrb/events/generic.rb +19 -3
  64. data/lib/discordrb/events/guilds.rb +129 -6
  65. data/lib/discordrb/events/invites.rb +125 -0
  66. data/lib/discordrb/events/members.rb +6 -2
  67. data/lib/discordrb/events/message.rb +86 -36
  68. data/lib/discordrb/events/presence.rb +23 -16
  69. data/lib/discordrb/events/raw.rb +47 -0
  70. data/lib/discordrb/events/reactions.rb +159 -0
  71. data/lib/discordrb/events/roles.rb +7 -6
  72. data/lib/discordrb/events/typing.rb +9 -5
  73. data/lib/discordrb/events/voice_server_update.rb +47 -0
  74. data/lib/discordrb/events/voice_state_update.rb +29 -9
  75. data/lib/discordrb/events/webhooks.rb +64 -0
  76. data/lib/discordrb/gateway.rb +219 -88
  77. data/lib/discordrb/id_object.rb +39 -0
  78. data/lib/discordrb/light.rb +1 -1
  79. data/lib/discordrb/light/integrations.rb +1 -1
  80. data/lib/discordrb/light/light_bot.rb +1 -1
  81. data/lib/discordrb/logger.rb +12 -11
  82. data/lib/discordrb/paginator.rb +57 -0
  83. data/lib/discordrb/permissions.rb +148 -14
  84. data/lib/discordrb/version.rb +1 -1
  85. data/lib/discordrb/voice/encoder.rb +14 -15
  86. data/lib/discordrb/voice/network.rb +86 -45
  87. data/lib/discordrb/voice/sodium.rb +96 -0
  88. data/lib/discordrb/voice/voice_bot.rb +52 -40
  89. data/lib/discordrb/webhooks.rb +12 -0
  90. data/lib/discordrb/websocket.rb +2 -2
  91. metadata +137 -34
@@ -1,33 +1,36 @@
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
- # https://discordapp.com/developers/docs/resources/invite#get-invite
7
- def resolve(token, invite_code)
8
+ # https://discord.com/developers/docs/resources/invite#get-invite
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
- # https://discordapp.com/developers/docs/resources/invite#delete-invite
19
- def delete(token, code)
20
+ # https://discord.com/developers/docs/resources/invite#delete-invite
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
 
29
32
  # Join a server using an invite
30
- # https://discordapp.com/developers/docs/resources/invite#accept-invite
33
+ # https://discord.com/developers/docs/resources/invite#accept-invite
31
34
  def accept(token, invite_code)
32
35
  Discordrb::API.request(
33
36
  :invite_code,
@@ -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
- # https://discordapp.com/developers/docs/resources/guild#create-guild
7
- def create(token, name, region = :london)
8
+ # https://discord.com/developers/docs/resources/guild#create-guild
9
+ def create(token, name, region = :'eu-central')
8
10
  Discordrb::API.request(
9
11
  :guilds,
10
12
  nil,
@@ -17,33 +19,34 @@ module Discordrb::API::Server
17
19
  end
18
20
 
19
21
  # Get a server's data
20
- # https://discordapp.com/developers/docs/resources/guild#get-guild
21
- def resolve(token, server_id)
22
+ # https://discord.com/developers/docs/resources/guild#get-guild
23
+ def resolve(token, server_id, with_counts = nil)
22
24
  Discordrb::API.request(
23
25
  :guilds_sid,
24
26
  server_id,
25
27
  :get,
26
- "#{Discordrb::API.api_base}/guilds/#{server_id}",
28
+ "#{Discordrb::API.api_base}/guilds/#{server_id}#{'?with_counts=true' if with_counts}",
27
29
  Authorization: token
28
30
  )
29
31
  end
30
32
 
31
33
  # Update a server
32
- # https://discordapp.com/developers/docs/resources/guild#modify-guild
33
- def update(token, server_id, name, region, icon, afk_channel_id, afk_timeout)
34
+ # https://discord.com/developers/docs/resources/guild#modify-guild
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,12 +54,13 @@ 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
 
58
62
  # Delete a server
59
- # https://discordapp.com/developers/docs/resources/guild#delete-guild
63
+ # https://discord.com/developers/docs/resources/guild#delete-guild
60
64
  def delete(token, server_id)
61
65
  Discordrb::API.request(
62
66
  :guilds_sid,
@@ -68,7 +72,7 @@ module Discordrb::API::Server
68
72
  end
69
73
 
70
74
  # Get a server's channels list
71
- # https://discordapp.com/developers/docs/resources/guild#get-guild-channels
75
+ # https://discord.com/developers/docs/resources/guild#get-guild-channels
72
76
  def channels(token, server_id)
73
77
  Discordrb::API.request(
74
78
  :guilds_sid_channels,
@@ -80,35 +84,36 @@ module Discordrb::API::Server
80
84
  end
81
85
 
82
86
  # Create a channel
83
- # https://discordapp.com/developers/docs/resources/guild#create-guild-channel
84
- def create_channel(token, server_id, name, type)
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)
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, position: position }.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://discord.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
  )
108
113
  end
109
114
 
110
115
  # Get a member's data
111
- # https://discordapp.com/developers/docs/resources/guild#get-guild-member
116
+ # https://discord.com/developers/docs/resources/guild#get-guild-member
112
117
  def resolve_member(token, server_id, user_id)
113
118
  Discordrb::API.request(
114
119
  :guilds_sid_members_uid,
@@ -120,7 +125,7 @@ module Discordrb::API::Server
120
125
  end
121
126
 
122
127
  # Gets members from the server
123
- # https://discordapp.com/developers/docs/resources/guild#list-guild-members
128
+ # https://discord.com/developers/docs/resources/guild#list-guild-members
124
129
  def resolve_members(token, server_id, limit, after = nil)
125
130
  Discordrb::API.request(
126
131
  :guilds_sid_members,
@@ -132,8 +137,8 @@ module Discordrb::API::Server
132
137
  end
133
138
 
134
139
  # Update a user properties
135
- # 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)
140
+ # https://discord.com/developers/docs/resources/guild#modify-guild-member
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,
@@ -144,27 +149,29 @@ module Discordrb::API::Server
144
149
  mute: mute,
145
150
  deaf: deaf,
146
151
  channel_id: channel_id
147
- }.reject { |_, v| v.nil? }.to_json,
152
+ }.compact.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
- # https://discordapp.com/developers/docs/resources/guild#remove-guild-member
155
- def remove_member(token, server_id, user_id)
160
+ # https://discord.com/developers/docs/resources/guild#remove-guild-member
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
 
166
173
  # Get a server's banned users
167
- # https://discordapp.com/developers/docs/resources/guild#get-guild-bans
174
+ # https://discord.com/developers/docs/resources/guild#get-guild-bans
168
175
  def bans(token, server_id)
169
176
  Discordrb::API.request(
170
177
  :guilds_sid_bans,
@@ -176,32 +183,34 @@ module Discordrb::API::Server
176
183
  end
177
184
 
178
185
  # Ban a user from a server and delete their messages from the last message_days days
179
- # https://discordapp.com/developers/docs/resources/guild#create-guild-ban
180
- def ban_user(token, server_id, user_id, message_days)
186
+ # https://discord.com/developers/docs/resources/guild#create-guild-ban
187
+ def ban_user(token, server_id, user_id, message_days, reason = nil)
188
+ reason = URI.encode_www_form_component(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
  )
189
197
  end
190
198
 
191
199
  # Unban a user from a server
192
- # https://discordapp.com/developers/docs/resources/guild#remove-guild-ban
193
- def unban_user(token, server_id, user_id)
200
+ # https://discord.com/developers/docs/resources/guild#remove-guild-ban
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
 
203
212
  # Get server roles
204
- # https://discordapp.com/developers/docs/resources/guild#get-guild-roles
213
+ # https://discord.com/developers/docs/resources/guild#get-guild-roles
205
214
  def roles(token, server_id)
206
215
  Discordrb::API.request(
207
216
  :guilds_sid_roles,
@@ -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)
216
- # https://discordapp.com/developers/docs/resources/guild#get-guild-roles
217
- def create_role(token, server_id)
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)
228
+ # https://discord.com/developers/docs/resources/guild#get-guild-roles
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
 
@@ -229,8 +243,8 @@ module Discordrb::API::Server
229
243
  # Permissions are the Discord defaults; allowed: invite creation, reading/sending messages,
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
- # 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)
246
+ # https://discord.com/developers/docs/resources/guild#batch-modify-guild-role
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,49 +252,93 @@ 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://discord.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
- # https://discordapp.com/developers/docs/resources/guild#delete-guild-role
247
- def delete_role(token, server_id, role_id)
275
+ # https://discord.com/developers/docs/resources/guild#delete-guild-role
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://discord.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://discord.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
- # https://discordapp.com/developers/docs/resources/guild#get-guild-prune-count
259
- def prune_count(token, server_id)
315
+ # https://discord.com/developers/docs/resources/guild#get-guild-prune-count
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
- # https://discordapp.com/developers/docs/resources/guild#begin-guild-prune
271
- def begin_prune(token, server_id, days)
327
+ # https://discord.com/developers/docs/resources/guild#begin-guild-prune
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
 
282
340
  # Get invites from server
283
- # https://discordapp.com/developers/docs/resources/guild#get-guild-invites
341
+ # https://discord.com/developers/docs/resources/guild#get-guild-invites
284
342
  def invites(token, server_id)
285
343
  Discordrb::API.request(
286
344
  :guilds_sid_invites,
@@ -291,8 +349,20 @@ module Discordrb::API::Server
291
349
  )
292
350
  end
293
351
 
352
+ # Gets a server's audit logs
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
+ 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=#{user_id}" if user_id}#{"&action_type=#{action_type}" if action_type}#{"&before=#{before}" if before}",
360
+ Authorization: token
361
+ )
362
+ end
363
+
294
364
  # Get server integrations
295
- # https://discordapp.com/developers/docs/resources/guild#get-guild-integrations
365
+ # https://discord.com/developers/docs/resources/guild#get-guild-integrations
296
366
  def integrations(token, server_id)
297
367
  Discordrb::API.request(
298
368
  :guilds_sid_integrations,
@@ -305,19 +375,20 @@ module Discordrb::API::Server
305
375
 
306
376
  # Create a server integration
307
377
  # https://discordapp.com/developers/docs/resources/guild#create-guild-integration
308
- def create_integration(token, server_id, type, id)
378
+ def create_integration(token, server_id, type, id, reason = nil)
309
379
  Discordrb::API.request(
310
380
  :guilds_sid_integrations,
311
381
  server_id,
312
382
  :post,
313
383
  "#{Discordrb::API.api_base}/guilds/#{server_id}/integrations",
314
384
  { type: type, id: id },
315
- Authorization: token
385
+ Authorization: token,
386
+ 'X-Audit-Log-Reason': reason
316
387
  )
317
388
  end
318
389
 
319
390
  # Update integration from server
320
- # https://discordapp.com/developers/docs/resources/guild#modify-guild-integration
391
+ # https://discord.com/developers/docs/resources/guild#modify-guild-integration
321
392
  def update_integration(token, server_id, integration_id, expire_behavior, expire_grace_period, enable_emoticons)
322
393
  Discordrb::API.request(
323
394
  :guilds_sid_integrations_iid,
@@ -332,18 +403,19 @@ module Discordrb::API::Server
332
403
 
333
404
  # Delete a server integration
334
405
  # https://discordapp.com/developers/docs/resources/guild#delete-guild-integration
335
- def delete_integration(token, server_id, integration_id)
406
+ def delete_integration(token, server_id, integration_id, reason = nil)
336
407
  Discordrb::API.request(
337
408
  :guilds_sid_integrations_iid,
338
409
  server_id,
339
410
  :delete,
340
411
  "#{Discordrb::API.api_base}/guilds/#{server_id}/integrations/#{integration_id}",
341
- Authorization: token
412
+ Authorization: token,
413
+ 'X-Audit-Log-Reason': reason
342
414
  )
343
415
  end
344
416
 
345
417
  # Sync an integration
346
- # https://discordapp.com/developers/docs/resources/guild#sync-guild-integration
418
+ # https://discord.com/developers/docs/resources/guild#sync-guild-integration
347
419
  def sync_integration(token, server_id, integration_id)
348
420
  Discordrb::API.request(
349
421
  :guilds_sid_integrations_iid_sync,
@@ -354,4 +426,111 @@ module Discordrb::API::Server
354
426
  Authorization: token
355
427
  )
356
428
  end
429
+
430
+ # Retrieves a server's embed information
431
+ # https://discord.com/developers/docs/resources/guild#get-guild-embed
432
+ def embed(token, server_id)
433
+ Discordrb::API.request(
434
+ :guilds_sid_embed,
435
+ server_id,
436
+ :get,
437
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/embed",
438
+ Authorization: token
439
+ )
440
+ end
441
+
442
+ # Modify a server's embed settings
443
+ # https://discord.com/developers/docs/resources/guild#modify-guild-embed
444
+ def modify_embed(token, server_id, enabled, channel_id, reason = nil)
445
+ Discordrb::API.request(
446
+ :guilds_sid_embed,
447
+ server_id,
448
+ :patch,
449
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/embed",
450
+ { enabled: enabled, channel_id: channel_id }.to_json,
451
+ Authorization: token,
452
+ 'X-Audit-Log-Reason': reason,
453
+ content_type: :json
454
+ )
455
+ end
456
+
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)
460
+ Discordrb::API.request(
461
+ :guilds_sid_emojis,
462
+ server_id,
463
+ :post,
464
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/emojis",
465
+ { image: image, name: name, roles: roles }.to_json,
466
+ Authorization: token,
467
+ content_type: :json,
468
+ 'X-Audit-Log-Reason': reason
469
+ )
470
+ end
471
+
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)
475
+ Discordrb::API.request(
476
+ :guilds_sid_emojis_eid,
477
+ server_id,
478
+ :patch,
479
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/emojis/#{emoji_id}",
480
+ { name: name, roles: roles }.to_json,
481
+ Authorization: token,
482
+ content_type: :json,
483
+ 'X-Audit-Log-Reason': reason
484
+ )
485
+ end
486
+
487
+ # Deletes a custom emoji
488
+ # https://discord.com/developers/docs/resources/emoji#delete-guild-emoji
489
+ def delete_emoji(token, server_id, emoji_id, reason = nil)
490
+ Discordrb::API.request(
491
+ :guilds_sid_emojis_eid,
492
+ server_id,
493
+ :delete,
494
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/emojis/#{emoji_id}",
495
+ Authorization: token,
496
+ 'X-Audit-Log-Reason': reason
497
+ )
498
+ end
499
+
500
+ # Available voice regions for this server
501
+ def regions(token, server_id)
502
+ Discordrb::API.request(
503
+ :guilds_sid_regions,
504
+ server_id,
505
+ :get,
506
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/regions",
507
+ Authorization: token
508
+ )
509
+ end
510
+
511
+ # Get server webhooks
512
+ # https://discord.com/developers/docs/resources/webhook#get-guild-webhooks
513
+ def webhooks(token, server_id)
514
+ Discordrb::API.request(
515
+ :guilds_sid_webhooks,
516
+ server_id,
517
+ :get,
518
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/webhooks",
519
+ Authorization: token
520
+ )
521
+ end
522
+
523
+ # Adds a member to a server with an OAuth2 Bearer token that has been granted `guilds.join`
524
+ # https://discord.com/developers/docs/resources/guild#add-guild-member
525
+ def add_member(token, server_id, user_id, access_token, nick = nil, roles = [], mute = false, deaf = false)
526
+ Discordrb::API.request(
527
+ :guilds_sid_members_uid,
528
+ server_id,
529
+ :put,
530
+ "#{Discordrb::API.api_base}/guilds/#{server_id}/members/#{user_id}",
531
+ { access_token: access_token, nick: nick, roles: roles, mute: mute, deaf: deaf }.to_json,
532
+ content_type: :json,
533
+ Authorization: token
534
+ )
535
+ end
357
536
  end