rubycord 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/rubycord/allowed_mentions.rb +34 -0
- data/lib/rubycord/api/application.rb +200 -0
- data/lib/rubycord/api/channel.rb +597 -0
- data/lib/rubycord/api/interaction.rb +52 -0
- data/lib/rubycord/api/invite.rb +42 -0
- data/lib/rubycord/api/server.rb +557 -0
- data/lib/rubycord/api/user.rb +153 -0
- data/lib/rubycord/api/webhook.rb +138 -0
- data/lib/rubycord/api.rb +356 -0
- data/lib/rubycord/await.rb +49 -0
- data/lib/rubycord/bot.rb +1757 -0
- data/lib/rubycord/cache.rb +259 -0
- data/lib/rubycord/colour_rgb.rb +41 -0
- data/lib/rubycord/commands/command_bot.rb +519 -0
- data/lib/rubycord/commands/container.rb +110 -0
- data/lib/rubycord/commands/events.rb +9 -0
- data/lib/rubycord/commands/parser.rb +325 -0
- data/lib/rubycord/commands/rate_limiter.rb +142 -0
- data/lib/rubycord/container.rb +753 -0
- data/lib/rubycord/data/activity.rb +269 -0
- data/lib/rubycord/data/application.rb +48 -0
- data/lib/rubycord/data/attachment.rb +109 -0
- data/lib/rubycord/data/audit_logs.rb +343 -0
- data/lib/rubycord/data/channel.rb +996 -0
- data/lib/rubycord/data/component.rb +227 -0
- data/lib/rubycord/data/embed.rb +249 -0
- data/lib/rubycord/data/emoji.rb +80 -0
- data/lib/rubycord/data/integration.rb +120 -0
- data/lib/rubycord/data/interaction.rb +798 -0
- data/lib/rubycord/data/invite.rb +135 -0
- data/lib/rubycord/data/member.rb +370 -0
- data/lib/rubycord/data/message.rb +412 -0
- data/lib/rubycord/data/overwrite.rb +106 -0
- data/lib/rubycord/data/profile.rb +89 -0
- data/lib/rubycord/data/reaction.rb +31 -0
- data/lib/rubycord/data/recipient.rb +32 -0
- data/lib/rubycord/data/role.rb +246 -0
- data/lib/rubycord/data/server.rb +1002 -0
- data/lib/rubycord/data/user.rb +261 -0
- data/lib/rubycord/data/voice_region.rb +43 -0
- data/lib/rubycord/data/voice_state.rb +39 -0
- data/lib/rubycord/data/webhook.rb +232 -0
- data/lib/rubycord/data.rb +40 -0
- data/lib/rubycord/errors.rb +737 -0
- data/lib/rubycord/events/await.rb +46 -0
- data/lib/rubycord/events/bans.rb +58 -0
- data/lib/rubycord/events/channels.rb +186 -0
- data/lib/rubycord/events/generic.rb +126 -0
- data/lib/rubycord/events/guilds.rb +191 -0
- data/lib/rubycord/events/interactions.rb +480 -0
- data/lib/rubycord/events/invites.rb +123 -0
- data/lib/rubycord/events/lifetime.rb +29 -0
- data/lib/rubycord/events/members.rb +91 -0
- data/lib/rubycord/events/message.rb +337 -0
- data/lib/rubycord/events/presence.rb +127 -0
- data/lib/rubycord/events/raw.rb +45 -0
- data/lib/rubycord/events/reactions.rb +156 -0
- data/lib/rubycord/events/roles.rb +86 -0
- data/lib/rubycord/events/threads.rb +94 -0
- data/lib/rubycord/events/typing.rb +70 -0
- data/lib/rubycord/events/voice_server_update.rb +45 -0
- data/lib/rubycord/events/voice_state_update.rb +103 -0
- data/lib/rubycord/events/webhooks.rb +62 -0
- data/lib/rubycord/gateway.rb +867 -0
- data/lib/rubycord/id_object.rb +37 -0
- data/lib/rubycord/light/data.rb +60 -0
- data/lib/rubycord/light/integrations.rb +71 -0
- data/lib/rubycord/light/light_bot.rb +56 -0
- data/lib/rubycord/light.rb +6 -0
- data/lib/rubycord/logger.rb +118 -0
- data/lib/rubycord/paginator.rb +55 -0
- data/lib/rubycord/permissions.rb +251 -0
- data/lib/rubycord/version.rb +5 -0
- data/lib/rubycord/voice/encoder.rb +113 -0
- data/lib/rubycord/voice/network.rb +366 -0
- data/lib/rubycord/voice/sodium.rb +96 -0
- data/lib/rubycord/voice/voice_bot.rb +408 -0
- data/lib/rubycord/webhooks/builder.rb +100 -0
- data/lib/rubycord/webhooks/client.rb +132 -0
- data/lib/rubycord/webhooks/embeds.rb +248 -0
- data/lib/rubycord/webhooks/modal.rb +78 -0
- data/lib/rubycord/webhooks/version.rb +7 -0
- data/lib/rubycord/webhooks/view.rb +192 -0
- data/lib/rubycord/webhooks.rb +12 -0
- data/lib/rubycord/websocket.rb +70 -0
- data/lib/rubycord.rb +140 -0
- metadata +231 -0
@@ -0,0 +1,557 @@
|
|
1
|
+
# API calls for Server
|
2
|
+
module Rubycord::API::Server
|
3
|
+
module_function
|
4
|
+
|
5
|
+
# Create a server
|
6
|
+
# https://discord.com/developers/docs/resources/guild#create-guild
|
7
|
+
def create(token, name, region = :"eu-central")
|
8
|
+
Rubycord::API.request(
|
9
|
+
:guilds,
|
10
|
+
nil,
|
11
|
+
:post,
|
12
|
+
"#{Rubycord::API.api_base}/guilds",
|
13
|
+
{name: name, region: region.to_s}.to_json,
|
14
|
+
Authorization: token,
|
15
|
+
content_type: :json
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Get a server's data
|
20
|
+
# https://discord.com/developers/docs/resources/guild#get-guild
|
21
|
+
def resolve(token, server_id, with_counts = nil)
|
22
|
+
Rubycord::API.request(
|
23
|
+
:guilds_sid,
|
24
|
+
server_id,
|
25
|
+
:get,
|
26
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}#{"?with_counts=true" if with_counts}",
|
27
|
+
Authorization: token
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Update a server
|
32
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild
|
33
|
+
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
|
+
Rubycord::API.request(
|
35
|
+
:guilds_sid,
|
36
|
+
server_id,
|
37
|
+
:patch,
|
38
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}",
|
39
|
+
{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
|
+
Authorization: token,
|
41
|
+
content_type: :json,
|
42
|
+
"X-Audit-Log-Reason": reason
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Transfer server ownership
|
47
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild
|
48
|
+
def transfer_ownership(token, server_id, user_id, reason = nil)
|
49
|
+
Rubycord::API.request(
|
50
|
+
:guilds_sid,
|
51
|
+
server_id,
|
52
|
+
:patch,
|
53
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}",
|
54
|
+
{owner_id: user_id}.to_json,
|
55
|
+
Authorization: token,
|
56
|
+
content_type: :json,
|
57
|
+
"X-Audit-Log-Reason": reason
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Delete a server
|
62
|
+
# https://discord.com/developers/docs/resources/guild#delete-guild
|
63
|
+
def delete(token, server_id)
|
64
|
+
Rubycord::API.request(
|
65
|
+
:guilds_sid,
|
66
|
+
server_id,
|
67
|
+
:delete,
|
68
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}",
|
69
|
+
Authorization: token
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Get a server's channels list
|
74
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-channels
|
75
|
+
def channels(token, server_id)
|
76
|
+
Rubycord::API.request(
|
77
|
+
:guilds_sid_channels,
|
78
|
+
server_id,
|
79
|
+
:get,
|
80
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/channels",
|
81
|
+
Authorization: token
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Create a channel
|
86
|
+
# https://discord.com/developers/docs/resources/guild#create-guild-channel
|
87
|
+
def create_channel(token, server_id, name, type, topic, bitrate, user_limit, permission_overwrites, parent_id, nsfw, rate_limit_per_user, position, reason = nil)
|
88
|
+
Rubycord::API.request(
|
89
|
+
:guilds_sid_channels,
|
90
|
+
server_id,
|
91
|
+
:post,
|
92
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/channels",
|
93
|
+
{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,
|
94
|
+
Authorization: token,
|
95
|
+
content_type: :json,
|
96
|
+
"X-Audit-Log-Reason": reason
|
97
|
+
)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Update a channels position
|
101
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild-channel-positions
|
102
|
+
def update_channel_positions(token, server_id, positions)
|
103
|
+
Rubycord::API.request(
|
104
|
+
:guilds_sid_channels,
|
105
|
+
server_id,
|
106
|
+
:patch,
|
107
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/channels",
|
108
|
+
positions.to_json,
|
109
|
+
Authorization: token,
|
110
|
+
content_type: :json
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Get a member's data
|
115
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-member
|
116
|
+
def resolve_member(token, server_id, user_id)
|
117
|
+
Rubycord::API.request(
|
118
|
+
:guilds_sid_members_uid,
|
119
|
+
server_id,
|
120
|
+
:get,
|
121
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/members/#{user_id}",
|
122
|
+
Authorization: token
|
123
|
+
)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Gets members from the server
|
127
|
+
# https://discord.com/developers/docs/resources/guild#list-guild-members
|
128
|
+
def resolve_members(token, server_id, limit, after = nil)
|
129
|
+
query_string = URI.encode_www_form({limit: limit, after: after}.compact)
|
130
|
+
Rubycord::API.request(
|
131
|
+
:guilds_sid_members,
|
132
|
+
server_id,
|
133
|
+
:get,
|
134
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/members?#{query_string}",
|
135
|
+
Authorization: token
|
136
|
+
)
|
137
|
+
end
|
138
|
+
|
139
|
+
# Update a user properties
|
140
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild-member
|
141
|
+
def update_member(token, server_id, user_id, nick: :undef, roles: :undef, mute: :undef, deaf: :undef, channel_id: :undef,
|
142
|
+
communication_disabled_until: :undef, reason: nil)
|
143
|
+
Rubycord::API.request(
|
144
|
+
:guilds_sid_members_uid,
|
145
|
+
server_id,
|
146
|
+
:patch,
|
147
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/members/#{user_id}", {
|
148
|
+
roles: roles,
|
149
|
+
nick: nick,
|
150
|
+
mute: mute,
|
151
|
+
deaf: deaf,
|
152
|
+
channel_id: channel_id,
|
153
|
+
communication_disabled_until: communication_disabled_until
|
154
|
+
}.reject { |_, v| v == :undef }.to_json,
|
155
|
+
Authorization: token,
|
156
|
+
content_type: :json,
|
157
|
+
"X-Audit-Log-Reason": reason
|
158
|
+
)
|
159
|
+
end
|
160
|
+
|
161
|
+
# Remove user from server
|
162
|
+
# https://discord.com/developers/docs/resources/guild#remove-guild-member
|
163
|
+
def remove_member(token, server_id, user_id, reason = nil)
|
164
|
+
Rubycord::API.request(
|
165
|
+
:guilds_sid_members_uid,
|
166
|
+
server_id,
|
167
|
+
:delete,
|
168
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/members/#{user_id}",
|
169
|
+
Authorization: token,
|
170
|
+
content_type: :json,
|
171
|
+
"X-Audit-Log-Reason": reason
|
172
|
+
)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Get a server's banned users
|
176
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-bans
|
177
|
+
def bans(token, server_id, limit = nil, before = nil, after = nil)
|
178
|
+
query_string = URI.encode_www_form({limit: limit, before: before, after: after}.compact)
|
179
|
+
Rubycord::API.request(
|
180
|
+
:guilds_sid_bans,
|
181
|
+
server_id,
|
182
|
+
:get,
|
183
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/bans?#{query_string}",
|
184
|
+
Authorization: token
|
185
|
+
)
|
186
|
+
end
|
187
|
+
|
188
|
+
# Ban a user from a server and delete their messages from the last message_days days
|
189
|
+
# https://discord.com/developers/docs/resources/guild#create-guild-ban
|
190
|
+
def ban_user(token, server_id, user_id, message_days, reason = nil)
|
191
|
+
reason = URI.encode_www_form_component(reason) if reason
|
192
|
+
Rubycord::API.request(
|
193
|
+
:guilds_sid_bans_uid,
|
194
|
+
server_id,
|
195
|
+
:put,
|
196
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/bans/#{user_id}?delete_message_days=#{message_days}&reason=#{reason}",
|
197
|
+
nil,
|
198
|
+
Authorization: token
|
199
|
+
)
|
200
|
+
end
|
201
|
+
|
202
|
+
# Unban a user from a server
|
203
|
+
# https://discord.com/developers/docs/resources/guild#remove-guild-ban
|
204
|
+
def unban_user(token, server_id, user_id, reason = nil)
|
205
|
+
Rubycord::API.request(
|
206
|
+
:guilds_sid_bans_uid,
|
207
|
+
server_id,
|
208
|
+
:delete,
|
209
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/bans/#{user_id}",
|
210
|
+
Authorization: token,
|
211
|
+
"X-Audit-Log-Reason": reason
|
212
|
+
)
|
213
|
+
end
|
214
|
+
|
215
|
+
# Get server roles
|
216
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-roles
|
217
|
+
def roles(token, server_id)
|
218
|
+
Rubycord::API.request(
|
219
|
+
:guilds_sid_roles,
|
220
|
+
server_id,
|
221
|
+
:get,
|
222
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/roles",
|
223
|
+
Authorization: token
|
224
|
+
)
|
225
|
+
end
|
226
|
+
|
227
|
+
# Create a role (parameters such as name and colour if not set can be set by update_role afterwards)
|
228
|
+
# Permissions are the Discord defaults; allowed: invite creation, reading/sending messages,
|
229
|
+
# sending TTS messages, embedding links, sending files, reading the history, mentioning everybody,
|
230
|
+
# connecting to voice, speaking and voice activity (push-to-talk isn't mandatory)
|
231
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-roles
|
232
|
+
def create_role(token, server_id, name, colour, hoist, mentionable, packed_permissions, reason = nil)
|
233
|
+
Rubycord::API.request(
|
234
|
+
:guilds_sid_roles,
|
235
|
+
server_id,
|
236
|
+
:post,
|
237
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/roles",
|
238
|
+
{color: colour, name: name, hoist: hoist, mentionable: mentionable, permissions: packed_permissions}.to_json,
|
239
|
+
Authorization: token,
|
240
|
+
content_type: :json,
|
241
|
+
"X-Audit-Log-Reason": reason
|
242
|
+
)
|
243
|
+
end
|
244
|
+
|
245
|
+
# Update a role
|
246
|
+
# Permissions are the Discord defaults; allowed: invite creation, reading/sending messages,
|
247
|
+
# sending TTS messages, embedding links, sending files, reading the history, mentioning everybody,
|
248
|
+
# connecting to voice, speaking and voice activity (push-to-talk isn't mandatory)
|
249
|
+
# https://discord.com/developers/docs/resources/guild#batch-modify-guild-role
|
250
|
+
# @param icon [:undef, File]
|
251
|
+
def update_role(token, server_id, role_id, name, colour, hoist = false, mentionable = false, packed_permissions = 104_324_161, reason = nil, icon = :undef)
|
252
|
+
data = {color: colour, name: name, hoist: hoist, mentionable: mentionable, permissions: packed_permissions}
|
253
|
+
|
254
|
+
if icon != :undef && icon
|
255
|
+
path_method = %i[original_filename path local_path].find { |meth| icon.respond_to?(meth) }
|
256
|
+
|
257
|
+
raise ArgumentError, "File object must respond to original_filename, path, or local path." unless path_method
|
258
|
+
raise ArgumentError, "File must respond to read" unless icon.respond_to? :read
|
259
|
+
|
260
|
+
mime_type = MIME::Types.type_for(icon.__send__(path_method)).first&.to_s || "image/jpeg"
|
261
|
+
data[:icon] = "data:#{mime_type};base64,#{Base64.encode64(icon.read).strip}"
|
262
|
+
elsif icon.nil?
|
263
|
+
data[:icon] = nil
|
264
|
+
end
|
265
|
+
|
266
|
+
Rubycord::API.request(
|
267
|
+
:guilds_sid_roles_rid,
|
268
|
+
server_id,
|
269
|
+
:patch,
|
270
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/roles/#{role_id}",
|
271
|
+
data.to_json,
|
272
|
+
Authorization: token,
|
273
|
+
content_type: :json,
|
274
|
+
"X-Audit-Log-Reason": reason
|
275
|
+
)
|
276
|
+
end
|
277
|
+
|
278
|
+
# Update role positions
|
279
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild-role-positions
|
280
|
+
def update_role_positions(token, server_id, roles)
|
281
|
+
Rubycord::API.request(
|
282
|
+
:guilds_sid_roles,
|
283
|
+
server_id,
|
284
|
+
:patch,
|
285
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/roles",
|
286
|
+
roles.to_json,
|
287
|
+
Authorization: token,
|
288
|
+
content_type: :json
|
289
|
+
)
|
290
|
+
end
|
291
|
+
|
292
|
+
# Delete a role
|
293
|
+
# https://discord.com/developers/docs/resources/guild#delete-guild-role
|
294
|
+
def delete_role(token, server_id, role_id, reason = nil)
|
295
|
+
Rubycord::API.request(
|
296
|
+
:guilds_sid_roles_rid,
|
297
|
+
server_id,
|
298
|
+
:delete,
|
299
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/roles/#{role_id}",
|
300
|
+
Authorization: token,
|
301
|
+
"X-Audit-Log-Reason": reason
|
302
|
+
)
|
303
|
+
end
|
304
|
+
|
305
|
+
# Adds a single role to a member
|
306
|
+
# https://discord.com/developers/docs/resources/guild#add-guild-member-role
|
307
|
+
def add_member_role(token, server_id, user_id, role_id, reason = nil)
|
308
|
+
Rubycord::API.request(
|
309
|
+
:guilds_sid_members_uid_roles_rid,
|
310
|
+
server_id,
|
311
|
+
:put,
|
312
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/members/#{user_id}/roles/#{role_id}",
|
313
|
+
nil,
|
314
|
+
Authorization: token,
|
315
|
+
"X-Audit-Log-Reason": reason
|
316
|
+
)
|
317
|
+
end
|
318
|
+
|
319
|
+
# Removes a single role from a member
|
320
|
+
# https://discord.com/developers/docs/resources/guild#remove-guild-member-role
|
321
|
+
def remove_member_role(token, server_id, user_id, role_id, reason = nil)
|
322
|
+
Rubycord::API.request(
|
323
|
+
:guilds_sid_members_uid_roles_rid,
|
324
|
+
server_id,
|
325
|
+
:delete,
|
326
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/members/#{user_id}/roles/#{role_id}",
|
327
|
+
Authorization: token,
|
328
|
+
"X-Audit-Log-Reason": reason
|
329
|
+
)
|
330
|
+
end
|
331
|
+
|
332
|
+
# Get server prune count
|
333
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-prune-count
|
334
|
+
def prune_count(token, server_id, days)
|
335
|
+
Rubycord::API.request(
|
336
|
+
:guilds_sid_prune,
|
337
|
+
server_id,
|
338
|
+
:get,
|
339
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/prune?days=#{days}",
|
340
|
+
Authorization: token
|
341
|
+
)
|
342
|
+
end
|
343
|
+
|
344
|
+
# Begin server prune
|
345
|
+
# https://discord.com/developers/docs/resources/guild#begin-guild-prune
|
346
|
+
def begin_prune(token, server_id, days, reason = nil)
|
347
|
+
Rubycord::API.request(
|
348
|
+
:guilds_sid_prune,
|
349
|
+
server_id,
|
350
|
+
:post,
|
351
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/prune",
|
352
|
+
{days: days},
|
353
|
+
Authorization: token,
|
354
|
+
"X-Audit-Log-Reason": reason
|
355
|
+
)
|
356
|
+
end
|
357
|
+
|
358
|
+
# Get invites from server
|
359
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-invites
|
360
|
+
def invites(token, server_id)
|
361
|
+
Rubycord::API.request(
|
362
|
+
:guilds_sid_invites,
|
363
|
+
server_id,
|
364
|
+
:get,
|
365
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/invites",
|
366
|
+
Authorization: token
|
367
|
+
)
|
368
|
+
end
|
369
|
+
|
370
|
+
# Gets a server's audit logs
|
371
|
+
# https://discord.com/developers/docs/resources/audit-log#get-guild-audit-log
|
372
|
+
def audit_logs(token, server_id, limit, user_id = nil, action_type = nil, before = nil)
|
373
|
+
Rubycord::API.request(
|
374
|
+
:guilds_sid_auditlogs,
|
375
|
+
server_id,
|
376
|
+
:get,
|
377
|
+
"#{Rubycord::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}",
|
378
|
+
Authorization: token
|
379
|
+
)
|
380
|
+
end
|
381
|
+
|
382
|
+
# Get server integrations
|
383
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-integrations
|
384
|
+
def integrations(token, server_id)
|
385
|
+
Rubycord::API.request(
|
386
|
+
:guilds_sid_integrations,
|
387
|
+
server_id,
|
388
|
+
:get,
|
389
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/integrations",
|
390
|
+
Authorization: token
|
391
|
+
)
|
392
|
+
end
|
393
|
+
|
394
|
+
# Create a server integration
|
395
|
+
# https://discord.com/developers/docs/resources/guild#create-guild-integration
|
396
|
+
def create_integration(token, server_id, type, id, reason = nil)
|
397
|
+
Rubycord::API.request(
|
398
|
+
:guilds_sid_integrations,
|
399
|
+
server_id,
|
400
|
+
:post,
|
401
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/integrations",
|
402
|
+
{type: type, id: id},
|
403
|
+
Authorization: token,
|
404
|
+
"X-Audit-Log-Reason": reason
|
405
|
+
)
|
406
|
+
end
|
407
|
+
|
408
|
+
# Update integration from server
|
409
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild-integration
|
410
|
+
def update_integration(token, server_id, integration_id, expire_behavior, expire_grace_period, enable_emoticons)
|
411
|
+
Rubycord::API.request(
|
412
|
+
:guilds_sid_integrations_iid,
|
413
|
+
server_id,
|
414
|
+
:patch,
|
415
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/integrations/#{integration_id}",
|
416
|
+
{expire_behavior: expire_behavior, expire_grace_period: expire_grace_period, enable_emoticons: enable_emoticons}.to_json,
|
417
|
+
Authorization: token,
|
418
|
+
content_type: :json
|
419
|
+
)
|
420
|
+
end
|
421
|
+
|
422
|
+
# Delete a server integration
|
423
|
+
# https://discord.com/developers/docs/resources/guild#delete-guild-integration
|
424
|
+
def delete_integration(token, server_id, integration_id, reason = nil)
|
425
|
+
Rubycord::API.request(
|
426
|
+
:guilds_sid_integrations_iid,
|
427
|
+
server_id,
|
428
|
+
:delete,
|
429
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/integrations/#{integration_id}",
|
430
|
+
Authorization: token,
|
431
|
+
"X-Audit-Log-Reason": reason
|
432
|
+
)
|
433
|
+
end
|
434
|
+
|
435
|
+
# Sync an integration
|
436
|
+
# https://discord.com/developers/docs/resources/guild#sync-guild-integration
|
437
|
+
def sync_integration(token, server_id, integration_id)
|
438
|
+
Rubycord::API.request(
|
439
|
+
:guilds_sid_integrations_iid_sync,
|
440
|
+
server_id,
|
441
|
+
:post,
|
442
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/integrations/#{integration_id}/sync",
|
443
|
+
nil,
|
444
|
+
Authorization: token
|
445
|
+
)
|
446
|
+
end
|
447
|
+
|
448
|
+
# Retrieves a server's widget information
|
449
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-widget
|
450
|
+
def widget(token, server_id)
|
451
|
+
Rubycord::API.request(
|
452
|
+
:guilds_sid_embed,
|
453
|
+
server_id,
|
454
|
+
:get,
|
455
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/widget",
|
456
|
+
Authorization: token
|
457
|
+
)
|
458
|
+
end
|
459
|
+
alias_method :embed, :widget
|
460
|
+
|
461
|
+
# Modify a server's widget settings
|
462
|
+
# https://discord.com/developers/docs/resources/guild#modify-guild-widget
|
463
|
+
def modify_widget(token, server_id, enabled, channel_id, reason = nil)
|
464
|
+
Rubycord::API.request(
|
465
|
+
:guilds_sid_embed,
|
466
|
+
server_id,
|
467
|
+
:patch,
|
468
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/widget",
|
469
|
+
{enabled: enabled, channel_id: channel_id}.to_json,
|
470
|
+
Authorization: token,
|
471
|
+
"X-Audit-Log-Reason": reason,
|
472
|
+
content_type: :json
|
473
|
+
)
|
474
|
+
end
|
475
|
+
alias_method :modify_embed, :modify_widget
|
476
|
+
|
477
|
+
# Adds a custom emoji.
|
478
|
+
# https://discord.com/developers/docs/resources/emoji#create-guild-emoji
|
479
|
+
def add_emoji(token, server_id, image, name, roles = [], reason = nil)
|
480
|
+
Rubycord::API.request(
|
481
|
+
:guilds_sid_emojis,
|
482
|
+
server_id,
|
483
|
+
:post,
|
484
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/emojis",
|
485
|
+
{image: image, name: name, roles: roles}.to_json,
|
486
|
+
Authorization: token,
|
487
|
+
content_type: :json,
|
488
|
+
"X-Audit-Log-Reason": reason
|
489
|
+
)
|
490
|
+
end
|
491
|
+
|
492
|
+
# Changes an emoji name and/or roles.
|
493
|
+
# https://discord.com/developers/docs/resources/emoji#modify-guild-emoji
|
494
|
+
def edit_emoji(token, server_id, emoji_id, name, roles = nil, reason = nil)
|
495
|
+
Rubycord::API.request(
|
496
|
+
:guilds_sid_emojis_eid,
|
497
|
+
server_id,
|
498
|
+
:patch,
|
499
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/emojis/#{emoji_id}",
|
500
|
+
{name: name, roles: roles}.to_json,
|
501
|
+
Authorization: token,
|
502
|
+
content_type: :json,
|
503
|
+
"X-Audit-Log-Reason": reason
|
504
|
+
)
|
505
|
+
end
|
506
|
+
|
507
|
+
# Deletes a custom emoji
|
508
|
+
# https://discord.com/developers/docs/resources/emoji#delete-guild-emoji
|
509
|
+
def delete_emoji(token, server_id, emoji_id, reason = nil)
|
510
|
+
Rubycord::API.request(
|
511
|
+
:guilds_sid_emojis_eid,
|
512
|
+
server_id,
|
513
|
+
:delete,
|
514
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/emojis/#{emoji_id}",
|
515
|
+
Authorization: token,
|
516
|
+
"X-Audit-Log-Reason": reason
|
517
|
+
)
|
518
|
+
end
|
519
|
+
|
520
|
+
# Available voice regions for this server
|
521
|
+
# https://discord.com/developers/docs/resources/guild#get-guild-voice-regions
|
522
|
+
def regions(token, server_id)
|
523
|
+
Rubycord::API.request(
|
524
|
+
:guilds_sid_regions,
|
525
|
+
server_id,
|
526
|
+
:get,
|
527
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/regions",
|
528
|
+
Authorization: token
|
529
|
+
)
|
530
|
+
end
|
531
|
+
|
532
|
+
# Get server webhooks
|
533
|
+
# https://discord.com/developers/docs/resources/webhook#get-guild-webhooks
|
534
|
+
def webhooks(token, server_id)
|
535
|
+
Rubycord::API.request(
|
536
|
+
:guilds_sid_webhooks,
|
537
|
+
server_id,
|
538
|
+
:get,
|
539
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/webhooks",
|
540
|
+
Authorization: token
|
541
|
+
)
|
542
|
+
end
|
543
|
+
|
544
|
+
# Adds a member to a server with an OAuth2 Bearer token that has been granted `guilds.join`
|
545
|
+
# https://discord.com/developers/docs/resources/guild#add-guild-member
|
546
|
+
def add_member(token, server_id, user_id, access_token, nick = nil, roles = [], mute = false, deaf = false)
|
547
|
+
Rubycord::API.request(
|
548
|
+
:guilds_sid_members_uid,
|
549
|
+
server_id,
|
550
|
+
:put,
|
551
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/members/#{user_id}",
|
552
|
+
{access_token: access_token, nick: nick, roles: roles, mute: mute, deaf: deaf}.to_json,
|
553
|
+
content_type: :json,
|
554
|
+
Authorization: token
|
555
|
+
)
|
556
|
+
end
|
557
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
# API calls for User object
|
2
|
+
module Rubycord::API::User
|
3
|
+
module_function
|
4
|
+
|
5
|
+
# Get user data
|
6
|
+
# https://discord.com/developers/docs/resources/user#get-user
|
7
|
+
def resolve(token, user_id)
|
8
|
+
Rubycord::API.request(
|
9
|
+
:users_uid,
|
10
|
+
nil,
|
11
|
+
:get,
|
12
|
+
"#{Rubycord::API.api_base}/users/#{user_id}",
|
13
|
+
Authorization: token
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Get profile data
|
18
|
+
# https://discord.com/developers/docs/resources/user#get-current-user
|
19
|
+
def profile(token)
|
20
|
+
Rubycord::API.request(
|
21
|
+
:users_me,
|
22
|
+
nil,
|
23
|
+
:get,
|
24
|
+
"#{Rubycord::API.api_base}/users/@me",
|
25
|
+
Authorization: token
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Change the current bot's nickname on a server
|
30
|
+
# https://discord.com/developers/docs/resources/user#modify-current-user
|
31
|
+
def change_own_nickname(token, server_id, nick, reason = nil)
|
32
|
+
Rubycord::API.request(
|
33
|
+
:guilds_sid_members_me_nick,
|
34
|
+
server_id, # This is technically a guild endpoint
|
35
|
+
:patch,
|
36
|
+
"#{Rubycord::API.api_base}/guilds/#{server_id}/members/@me/nick",
|
37
|
+
{nick: nick}.to_json,
|
38
|
+
Authorization: token,
|
39
|
+
content_type: :json,
|
40
|
+
"X-Audit-Log-Reason": reason
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Update user data
|
45
|
+
# https://discord.com/developers/docs/resources/user#modify-current-user
|
46
|
+
def update_profile(token, email, password, new_username, avatar, new_password = nil)
|
47
|
+
Rubycord::API.request(
|
48
|
+
:users_me,
|
49
|
+
nil,
|
50
|
+
:patch,
|
51
|
+
"#{Rubycord::API.api_base}/users/@me",
|
52
|
+
{avatar: avatar, email: email, new_password: new_password, password: password, username: new_username}.to_json,
|
53
|
+
Authorization: token,
|
54
|
+
content_type: :json
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Get the servers a user is connected to
|
59
|
+
# https://discord.com/developers/docs/resources/user#get-current-user-guilds
|
60
|
+
def servers(token)
|
61
|
+
Rubycord::API.request(
|
62
|
+
:users_me_guilds,
|
63
|
+
nil,
|
64
|
+
:get,
|
65
|
+
"#{Rubycord::API.api_base}/users/@me/guilds",
|
66
|
+
Authorization: token
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Leave a server
|
71
|
+
# https://discord.com/developers/docs/resources/user#leave-guild
|
72
|
+
def leave_server(token, server_id)
|
73
|
+
Rubycord::API.request(
|
74
|
+
:users_me_guilds_sid,
|
75
|
+
nil,
|
76
|
+
:delete,
|
77
|
+
"#{Rubycord::API.api_base}/users/@me/guilds/#{server_id}",
|
78
|
+
Authorization: token
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Get the DMs for the current user
|
83
|
+
# https://discord.com/developers/docs/resources/user#get-user-dms
|
84
|
+
def user_dms(token)
|
85
|
+
Rubycord::API.request(
|
86
|
+
:users_me_channels,
|
87
|
+
nil,
|
88
|
+
:get,
|
89
|
+
"#{Rubycord::API.api_base}/users/@me/channels",
|
90
|
+
Authorization: token
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Create a DM to another user
|
95
|
+
# https://discord.com/developers/docs/resources/user#create-dm
|
96
|
+
def create_pm(token, recipient_id)
|
97
|
+
Rubycord::API.request(
|
98
|
+
:users_me_channels,
|
99
|
+
nil,
|
100
|
+
:post,
|
101
|
+
"#{Rubycord::API.api_base}/users/@me/channels",
|
102
|
+
{recipient_id: recipient_id}.to_json,
|
103
|
+
Authorization: token,
|
104
|
+
content_type: :json
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Get information about a user's connections
|
109
|
+
# https://discord.com/developers/docs/resources/user#get-users-connections
|
110
|
+
def connections(token)
|
111
|
+
Rubycord::API.request(
|
112
|
+
:users_me_connections,
|
113
|
+
nil,
|
114
|
+
:get,
|
115
|
+
"#{Rubycord::API.api_base}/users/@me/connections",
|
116
|
+
Authorization: token
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
# Change user status setting
|
121
|
+
def change_status_setting(token, status)
|
122
|
+
Rubycord::API.request(
|
123
|
+
:users_me_settings,
|
124
|
+
nil,
|
125
|
+
:patch,
|
126
|
+
"#{Rubycord::API.api_base}/users/@me/settings",
|
127
|
+
{status: status}.to_json,
|
128
|
+
Authorization: token,
|
129
|
+
content_type: :json
|
130
|
+
)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Returns one of the "default" discord avatars from the CDN given a discriminator or id since new usernames
|
134
|
+
# TODO: Maybe change this method again after discriminator removal ?
|
135
|
+
def default_avatar(discrim_id = 0, legacy: false)
|
136
|
+
index = if legacy
|
137
|
+
discrim_id.to_i % 5
|
138
|
+
else
|
139
|
+
(discrim_id.to_i >> 22) % 5
|
140
|
+
end
|
141
|
+
"#{Rubycord::API.cdn_url}/embed/avatars/#{index}.png"
|
142
|
+
end
|
143
|
+
|
144
|
+
# Make an avatar URL from the user and avatar IDs
|
145
|
+
def avatar_url(user_id, avatar_id, format = nil)
|
146
|
+
format ||= if avatar_id.start_with?("a_")
|
147
|
+
"gif"
|
148
|
+
else
|
149
|
+
"webp"
|
150
|
+
end
|
151
|
+
"#{Rubycord::API.cdn_url}/avatars/#{user_id}/#{avatar_id}.#{format}"
|
152
|
+
end
|
153
|
+
end
|