discordrb 2.1.3 → 3.0.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +76 -0
- data/README.md +4 -2
- data/discordrb.gemspec +1 -1
- data/examples/commands.rb +2 -0
- data/examples/data/music.dca +0 -0
- data/examples/data/music.mp3 +0 -0
- data/examples/eval.rb +6 -3
- data/examples/ping.rb +14 -1
- data/examples/ping_with_respond_time.rb +6 -4
- data/examples/pm_send.rb +3 -0
- data/examples/shutdown.rb +7 -2
- data/examples/voice_send.rb +51 -0
- data/lib/discordrb/api.rb +66 -460
- data/lib/discordrb/api/channel.rb +306 -0
- data/lib/discordrb/api/invite.rb +41 -0
- data/lib/discordrb/api/server.rb +357 -0
- data/lib/discordrb/api/user.rb +134 -0
- data/lib/discordrb/bot.rb +266 -576
- data/lib/discordrb/cache.rb +27 -28
- data/lib/discordrb/commands/command_bot.rb +44 -15
- data/lib/discordrb/commands/container.rb +3 -2
- data/lib/discordrb/commands/parser.rb +14 -6
- data/lib/discordrb/container.rb +30 -3
- data/lib/discordrb/data.rb +823 -189
- data/lib/discordrb/errors.rb +145 -0
- data/lib/discordrb/events/channels.rb +63 -3
- data/lib/discordrb/events/members.rb +1 -2
- data/lib/discordrb/events/message.rb +96 -17
- data/lib/discordrb/events/presence.rb +15 -0
- data/lib/discordrb/events/typing.rb +7 -1
- data/lib/discordrb/gateway.rb +724 -0
- data/lib/discordrb/light/light_bot.rb +6 -4
- data/lib/discordrb/logger.rb +26 -9
- data/lib/discordrb/permissions.rb +6 -3
- data/lib/discordrb/version.rb +1 -1
- data/lib/discordrb/voice/voice_bot.rb +29 -6
- metadata +12 -5
- data/lib/discordrb/token_cache.rb +0 -181
@@ -0,0 +1,306 @@
|
|
1
|
+
# API calls for Channel
|
2
|
+
module Discordrb::API::Channel
|
3
|
+
module_function
|
4
|
+
|
5
|
+
# Get a channel's data
|
6
|
+
# https://discordapp.com/developers/docs/resources/channel#get-channel
|
7
|
+
def resolve(token, channel_id)
|
8
|
+
Discordrb::API.request(
|
9
|
+
:channels_cid,
|
10
|
+
channel_id,
|
11
|
+
:get,
|
12
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}",
|
13
|
+
Authorization: token
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Update a channel's data
|
18
|
+
# https://discordapp.com/developers/docs/resources/channel#modify-channel
|
19
|
+
def update(token, channel_id, name, topic, position = 0)
|
20
|
+
Discordrb::API.request(
|
21
|
+
:channels_cid,
|
22
|
+
channel_id,
|
23
|
+
:patch,
|
24
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}",
|
25
|
+
{ name: name, position: position, topic: topic }.to_json,
|
26
|
+
Authorization: token,
|
27
|
+
content_type: :json
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Delete a channel
|
32
|
+
# https://discordapp.com/developers/docs/resources/channel#deleteclose-channel
|
33
|
+
def delete(token, channel_id)
|
34
|
+
Discordrb::API.request(
|
35
|
+
:channels_cid,
|
36
|
+
channel_id,
|
37
|
+
:delete,
|
38
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}",
|
39
|
+
Authorization: token
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Get a list of messages from a channel's history
|
44
|
+
# https://discordapp.com/developers/docs/resources/channel#get-channel-messages
|
45
|
+
def messages(token, channel_id, amount, before = nil, after = nil)
|
46
|
+
Discordrb::API.request(
|
47
|
+
:channels_cid_messages,
|
48
|
+
channel_id,
|
49
|
+
:get,
|
50
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages?limit=#{amount}#{"&before=#{before}" if before}#{"&after=#{after}" if after}",
|
51
|
+
Authorization: token
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Get a single message from a channel's history by id
|
56
|
+
# https://discordapp.com/developers/docs/resources/channel#get-channel-message
|
57
|
+
def message(token, channel_id, message_id)
|
58
|
+
Discordrb::API.request(
|
59
|
+
:channels_cid_messages_mid,
|
60
|
+
channel_id,
|
61
|
+
:get,
|
62
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}",
|
63
|
+
Authorization: token
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Send a message to a channel
|
68
|
+
# https://discordapp.com/developers/docs/resources/channel#create-message
|
69
|
+
def create_message(token, channel_id, message, mentions = [], tts = false, _server_id = nil) # send message
|
70
|
+
Discordrb::API.request(
|
71
|
+
:channels_cid_messages_mid,
|
72
|
+
channel_id,
|
73
|
+
:post,
|
74
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages",
|
75
|
+
{ content: message, mentions: mentions, tts: tts }.to_json,
|
76
|
+
Authorization: token,
|
77
|
+
content_type: :json
|
78
|
+
)
|
79
|
+
rescue RestClient::InternalServerError
|
80
|
+
raise Discordrb::Errors::MessageTooLong, "Message over the character limit (#{message.length} > 2000)"
|
81
|
+
end
|
82
|
+
|
83
|
+
# Send a file as a message to a channel
|
84
|
+
# https://discordapp.com/developers/docs/resources/channel#upload-file
|
85
|
+
def upload_file(token, channel_id, file, caption: nil, tts: false)
|
86
|
+
Discordrb::API.request(
|
87
|
+
:channels_cid_messages_mid,
|
88
|
+
channel_id,
|
89
|
+
:post,
|
90
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages",
|
91
|
+
{ file: file, content: caption, tts: tts },
|
92
|
+
Authorization: token
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Edit a message
|
97
|
+
# https://discordapp.com/developers/docs/resources/channel#edit-message
|
98
|
+
def edit_message(token, channel_id, message_id, message, mentions = [])
|
99
|
+
Discordrb::API.request(
|
100
|
+
:channels_cid_messages_mid,
|
101
|
+
channel_id,
|
102
|
+
:patch,
|
103
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}",
|
104
|
+
{ content: message, mentions: mentions }.to_json,
|
105
|
+
Authorization: token,
|
106
|
+
content_type: :json
|
107
|
+
)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Delete a message
|
111
|
+
# https://discordapp.com/developers/docs/resources/channel#delete-message
|
112
|
+
def delete_message(token, channel_id, message_id)
|
113
|
+
Discordrb::API.request(
|
114
|
+
:channels_cid_messages_mid,
|
115
|
+
channel_id,
|
116
|
+
:delete,
|
117
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}",
|
118
|
+
Authorization: token
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
# Delete messages in bulk
|
123
|
+
# https://discordapp.com/developers/docs/resources/channel#bulk-delete-messages
|
124
|
+
def bulk_delete_messages(token, channel_id, messages = [])
|
125
|
+
Discordrb::API.request(
|
126
|
+
:channels_cid_messages_bulk_delete,
|
127
|
+
channel_id,
|
128
|
+
:post,
|
129
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/bulk_delete",
|
130
|
+
{ messages: messages }.to_json,
|
131
|
+
Authorization: token,
|
132
|
+
content_type: :json
|
133
|
+
)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Update a channels permission for a role or member
|
137
|
+
# https://discordapp.com/developers/docs/resources/channel#edit-channel-permissions
|
138
|
+
def update_permission(token, channel_id, overwrite_id, allow, deny, type)
|
139
|
+
Discordrb::API.request(
|
140
|
+
:channels_cid_permissions_oid,
|
141
|
+
channel_id,
|
142
|
+
:put,
|
143
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/permissions/#{overwrite_id}",
|
144
|
+
{ type: type, id: overwrite_id, allow: allow, deny: deny }.to_json,
|
145
|
+
Authorization: token,
|
146
|
+
content_type: :json
|
147
|
+
)
|
148
|
+
end
|
149
|
+
|
150
|
+
# Get a channel's invite list
|
151
|
+
# https://discordapp.com/developers/docs/resources/channel#get-channel-invites
|
152
|
+
def invites(token, channel_id)
|
153
|
+
Discordrb::API.request(
|
154
|
+
:channels_cid_invites,
|
155
|
+
channel_id,
|
156
|
+
:get,
|
157
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/invites",
|
158
|
+
Authorization: token
|
159
|
+
)
|
160
|
+
end
|
161
|
+
|
162
|
+
# Create an instant invite from a server or a channel id
|
163
|
+
# https://discordapp.com/developers/docs/resources/channel#create-channel-invite
|
164
|
+
def create_invite(token, channel_id, max_age = 0, max_uses = 0, temporary = false)
|
165
|
+
Discordrb::API.request(
|
166
|
+
:channels_cid_invites,
|
167
|
+
channel_id,
|
168
|
+
:post,
|
169
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/invites",
|
170
|
+
{ max_age: max_age, max_uses: max_uses, temporary: temporary }.to_json,
|
171
|
+
Authorization: token,
|
172
|
+
content_type: :json
|
173
|
+
)
|
174
|
+
end
|
175
|
+
|
176
|
+
# Delete channel permission
|
177
|
+
# https://discordapp.com/developers/docs/resources/channel#delete-channel-permission
|
178
|
+
def delete_permission(token, channel_id, overwrite_id)
|
179
|
+
Discordrb::API.request(
|
180
|
+
:channels_cid_permissions_oid,
|
181
|
+
channel_id,
|
182
|
+
:delete,
|
183
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/permissions/#{overwrite_id}",
|
184
|
+
Authorization: token
|
185
|
+
)
|
186
|
+
end
|
187
|
+
|
188
|
+
# Start typing (needs to be resent every 5 seconds to keep up the typing)
|
189
|
+
# https://discordapp.com/developers/docs/resources/channel#trigger-typing-indicator
|
190
|
+
def start_typing(token, channel_id)
|
191
|
+
Discordrb::API.request(
|
192
|
+
:channels_cid_typing,
|
193
|
+
channel_id,
|
194
|
+
:post,
|
195
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/typing",
|
196
|
+
nil,
|
197
|
+
Authorization: token
|
198
|
+
)
|
199
|
+
end
|
200
|
+
|
201
|
+
# Get a list of pinned messages in a channel
|
202
|
+
# https://discordapp.com/developers/docs/resources/channel#get-pinned-messages
|
203
|
+
def pinned_messages(token, channel_id)
|
204
|
+
Discordrb::API.request(
|
205
|
+
:channels_cid_pins,
|
206
|
+
channel_id,
|
207
|
+
:get,
|
208
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/pins",
|
209
|
+
Authorization: token
|
210
|
+
)
|
211
|
+
end
|
212
|
+
|
213
|
+
# Pin a message
|
214
|
+
# https://discordapp.com/developers/docs/resources/channel#add-pinned-channel-message
|
215
|
+
def pin_message(token, channel_id, message_id)
|
216
|
+
Discordrb::API.request(
|
217
|
+
:channels_cid_pins_mid,
|
218
|
+
channel_id,
|
219
|
+
:put,
|
220
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{message_id}",
|
221
|
+
nil,
|
222
|
+
Authorization: token
|
223
|
+
)
|
224
|
+
end
|
225
|
+
|
226
|
+
# Unpin a message
|
227
|
+
# https://discordapp.com/developers/docs/resources/channel#delete-pinned-channel-message
|
228
|
+
def unpin_message(token, channel_id, message_id)
|
229
|
+
Discordrb::API.request(
|
230
|
+
:channels_cid_pins_mid,
|
231
|
+
channel_id,
|
232
|
+
:delete,
|
233
|
+
"#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{message_id}",
|
234
|
+
Authorization: token
|
235
|
+
)
|
236
|
+
end
|
237
|
+
|
238
|
+
# Create an empty group channel.
|
239
|
+
def create_empty_group(token, bot_user_id)
|
240
|
+
Discordrb::API.request(
|
241
|
+
:users_uid_channels,
|
242
|
+
nil,
|
243
|
+
:post,
|
244
|
+
"#{Discordrb::API.api_base}/users/#{bot_user_id}/channels",
|
245
|
+
{}.to_json,
|
246
|
+
Authorization: token,
|
247
|
+
content_type: :json
|
248
|
+
)
|
249
|
+
end
|
250
|
+
|
251
|
+
# Create a group channel.
|
252
|
+
def create_group(token, pm_channel_id, user_id)
|
253
|
+
Discordrb::API.request(
|
254
|
+
:channels_cid_recipients_uid,
|
255
|
+
nil,
|
256
|
+
:put,
|
257
|
+
"#{Discordrb::API.api_base}/channels/#{pm_channel_id}/recipients/#{user_id}",
|
258
|
+
{}.to_json,
|
259
|
+
Authorization: token,
|
260
|
+
content_type: :json
|
261
|
+
)
|
262
|
+
rescue RestClient::InternalServerError
|
263
|
+
raise 'Attempted to add self as a new group channel recipient!'
|
264
|
+
rescue RestClient::NoContent
|
265
|
+
raise 'Attempted to create a group channel with the PM channel recipient!'
|
266
|
+
rescue RestClient::Forbidden
|
267
|
+
raise 'Attempted to add a user to group channel without permission!'
|
268
|
+
end
|
269
|
+
|
270
|
+
# Add a user to a group channel.
|
271
|
+
def add_group_user(token, group_channel_id, user_id)
|
272
|
+
Discordrb::API.request(
|
273
|
+
:channels_cid_recipients_uid,
|
274
|
+
nil,
|
275
|
+
:put,
|
276
|
+
"#{Discordrb::API.api_base}/channels/#{group_channel_id}/recipients/#{user_id}",
|
277
|
+
{}.to_json,
|
278
|
+
Authorization: token,
|
279
|
+
content_type: :json
|
280
|
+
)
|
281
|
+
end
|
282
|
+
|
283
|
+
# Remove a user from a group channel.
|
284
|
+
def remove_group_user(token, group_channel_id, user_id)
|
285
|
+
Discordrb::API.request(
|
286
|
+
:channels_cid_recipients_uid,
|
287
|
+
nil,
|
288
|
+
:delete,
|
289
|
+
"#{Discordrb::API.api_base}/channels/#{group_channel_id}/recipients/#{user_id}",
|
290
|
+
Authorization: token,
|
291
|
+
content_type: :json
|
292
|
+
)
|
293
|
+
end
|
294
|
+
|
295
|
+
# Leave a group channel.
|
296
|
+
def leave_group(token, group_channel_id)
|
297
|
+
Discordrb::API.request(
|
298
|
+
:channels_cid,
|
299
|
+
nil,
|
300
|
+
:delete,
|
301
|
+
"#{Discordrb::API.api_base}/channels/#{group_channel_id}",
|
302
|
+
Authorization: token,
|
303
|
+
content_type: :json
|
304
|
+
)
|
305
|
+
end
|
306
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# API calls for Invite object
|
2
|
+
module Discordrb::API::Invite
|
3
|
+
module_function
|
4
|
+
|
5
|
+
# Resolve an invite
|
6
|
+
# https://discordapp.com/developers/docs/resources/invite#get-invite
|
7
|
+
def resolve(token, invite_code)
|
8
|
+
Discordrb::API.request(
|
9
|
+
:invite_code,
|
10
|
+
nil,
|
11
|
+
:get,
|
12
|
+
"#{Discordrb::API.api_base}/invite/#{invite_code}",
|
13
|
+
Authorization: token
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Delete an invite by code
|
18
|
+
# https://discordapp.com/developers/docs/resources/invite#delete-invite
|
19
|
+
def delete(token, code)
|
20
|
+
Discordrb::API.request(
|
21
|
+
:invites_code,
|
22
|
+
nil,
|
23
|
+
:delete,
|
24
|
+
"#{Discordrb::API.api_base}/invites/#{code}",
|
25
|
+
Authorization: token
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Join a server using an invite
|
30
|
+
# https://discordapp.com/developers/docs/resources/invite#accept-invite
|
31
|
+
def accept(token, invite_code)
|
32
|
+
Discordrb::API.request(
|
33
|
+
:invite_code,
|
34
|
+
nil,
|
35
|
+
:post,
|
36
|
+
"#{Discordrb::API.api_base}/invite/#{invite_code}",
|
37
|
+
nil,
|
38
|
+
Authorization: token
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,357 @@
|
|
1
|
+
# API calls for Server
|
2
|
+
module Discordrb::API::Server
|
3
|
+
module_function
|
4
|
+
|
5
|
+
# Create a server
|
6
|
+
# https://discordapp.com/developers/docs/resources/guild#create-guild
|
7
|
+
def create(token, name, region = :london)
|
8
|
+
Discordrb::API.request(
|
9
|
+
:guilds,
|
10
|
+
nil,
|
11
|
+
:post,
|
12
|
+
"#{Discordrb::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://discordapp.com/developers/docs/resources/guild#get-guild
|
21
|
+
def resolve(token, server_id)
|
22
|
+
Discordrb::API.request(
|
23
|
+
:guilds_sid,
|
24
|
+
server_id,
|
25
|
+
:get,
|
26
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}",
|
27
|
+
Authorization: token
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
# 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
|
+
Discordrb::API.request(
|
35
|
+
:guilds_sid,
|
36
|
+
server_id,
|
37
|
+
:patch,
|
38
|
+
"#{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,
|
40
|
+
Authorization: token,
|
41
|
+
content_type: :json
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Transfer server ownership
|
46
|
+
def transfer_ownership(token, server_id, user_id)
|
47
|
+
Discordrb::API.request(
|
48
|
+
:guilds_sid,
|
49
|
+
server_id,
|
50
|
+
:patch,
|
51
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}",
|
52
|
+
{ owner_id: user_id }.to_json,
|
53
|
+
Authorization: token,
|
54
|
+
content_type: :json
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Delete a server
|
59
|
+
# https://discordapp.com/developers/docs/resources/guild#delete-guild
|
60
|
+
def delete(token, server_id)
|
61
|
+
Discordrb::API.request(
|
62
|
+
:guilds_sid,
|
63
|
+
server_id,
|
64
|
+
:delete,
|
65
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}",
|
66
|
+
Authorization: token
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Get a server's channels list
|
71
|
+
# https://discordapp.com/developers/docs/resources/guild#get-guild-channels
|
72
|
+
def channels(token, server_id)
|
73
|
+
Discordrb::API.request(
|
74
|
+
:guilds_sid_channels,
|
75
|
+
server_id,
|
76
|
+
:get,
|
77
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/channels",
|
78
|
+
Authorization: token
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Create a channel
|
83
|
+
# https://discordapp.com/developers/docs/resources/guild#create-guild-channel
|
84
|
+
def create_channel(token, server_id, name, type)
|
85
|
+
Discordrb::API.request(
|
86
|
+
:guilds_sid_channels,
|
87
|
+
server_id,
|
88
|
+
:post,
|
89
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/channels",
|
90
|
+
{ name: name, type: type }.to_json,
|
91
|
+
Authorization: token,
|
92
|
+
content_type: :json
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
# 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)
|
99
|
+
Discordrb::API.request(
|
100
|
+
:guilds_sid_channels,
|
101
|
+
server_id,
|
102
|
+
:patch,
|
103
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/channels",
|
104
|
+
{ id: channel_id, position: position }.to_json,
|
105
|
+
Authorization: token,
|
106
|
+
content_type: :json
|
107
|
+
)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Get a member's data
|
111
|
+
# https://discordapp.com/developers/docs/resources/guild#get-guild-member
|
112
|
+
def resolve_member(token, server_id, user_id)
|
113
|
+
Discordrb::API.request(
|
114
|
+
:guilds_sid_members_uid,
|
115
|
+
server_id,
|
116
|
+
:get,
|
117
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/members/#{user_id}",
|
118
|
+
Authorization: token
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
# Gets members from the server
|
123
|
+
# https://discordapp.com/developers/docs/resources/guild#list-guild-members
|
124
|
+
def resolve_members(token, server_id, limit, after = nil)
|
125
|
+
Discordrb::API.request(
|
126
|
+
:guilds_sid_members,
|
127
|
+
server_id,
|
128
|
+
:get,
|
129
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/members?limit=#{limit}#{"&after=#{after}" if after}",
|
130
|
+
Authorization: token
|
131
|
+
)
|
132
|
+
end
|
133
|
+
|
134
|
+
# 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)
|
137
|
+
Discordrb::API.request(
|
138
|
+
:guilds_sid_members_uid,
|
139
|
+
server_id,
|
140
|
+
:patch,
|
141
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/members/#{user_id}", {
|
142
|
+
roles: roles,
|
143
|
+
nick: nick,
|
144
|
+
mute: mute,
|
145
|
+
deaf: deaf,
|
146
|
+
channel_id: channel_id
|
147
|
+
}.reject { |_, v| v.nil? }.to_json,
|
148
|
+
Authorization: token,
|
149
|
+
content_type: :json
|
150
|
+
)
|
151
|
+
end
|
152
|
+
|
153
|
+
# Remove user from server
|
154
|
+
# https://discordapp.com/developers/docs/resources/guild#remove-guild-member
|
155
|
+
def remove_member(token, server_id, user_id)
|
156
|
+
Discordrb::API.request(
|
157
|
+
:guilds_sid_members_uid,
|
158
|
+
server_id,
|
159
|
+
:delete,
|
160
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/members/#{user_id}",
|
161
|
+
Authorization: token,
|
162
|
+
content_type: :json
|
163
|
+
)
|
164
|
+
end
|
165
|
+
|
166
|
+
# Get a server's banned users
|
167
|
+
# https://discordapp.com/developers/docs/resources/guild#get-guild-bans
|
168
|
+
def bans(token, server_id)
|
169
|
+
Discordrb::API.request(
|
170
|
+
:guilds_sid_bans,
|
171
|
+
server_id,
|
172
|
+
:get,
|
173
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/bans",
|
174
|
+
Authorization: token
|
175
|
+
)
|
176
|
+
end
|
177
|
+
|
178
|
+
# 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)
|
181
|
+
Discordrb::API.request(
|
182
|
+
:guilds_sid_bans_uid,
|
183
|
+
server_id,
|
184
|
+
:put,
|
185
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/bans/#{user_id}?delete-message-days=#{message_days}",
|
186
|
+
nil,
|
187
|
+
Authorization: token
|
188
|
+
)
|
189
|
+
end
|
190
|
+
|
191
|
+
# 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)
|
194
|
+
Discordrb::API.request(
|
195
|
+
:guilds_sid_bans_uid,
|
196
|
+
server_id,
|
197
|
+
:delete,
|
198
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/bans/#{user_id}",
|
199
|
+
Authorization: token
|
200
|
+
)
|
201
|
+
end
|
202
|
+
|
203
|
+
# Get server roles
|
204
|
+
# https://discordapp.com/developers/docs/resources/guild#get-guild-roles
|
205
|
+
def roles(token, server_id)
|
206
|
+
Discordrb::API.request(
|
207
|
+
:guilds_sid_roles,
|
208
|
+
server_id,
|
209
|
+
:get,
|
210
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/roles",
|
211
|
+
Authorization: token
|
212
|
+
)
|
213
|
+
end
|
214
|
+
|
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)
|
218
|
+
Discordrb::API.request(
|
219
|
+
:guilds_sid_roles,
|
220
|
+
server_id,
|
221
|
+
:post,
|
222
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/roles",
|
223
|
+
nil,
|
224
|
+
Authorization: token
|
225
|
+
)
|
226
|
+
end
|
227
|
+
|
228
|
+
# Update a role
|
229
|
+
# Permissions are the Discord defaults; allowed: invite creation, reading/sending messages,
|
230
|
+
# sending TTS messages, embedding links, sending files, reading the history, mentioning everybody,
|
231
|
+
# 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)
|
234
|
+
Discordrb::API.request(
|
235
|
+
:guilds_sid_roles_rid,
|
236
|
+
server_id,
|
237
|
+
:patch,
|
238
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/roles/#{role_id}",
|
239
|
+
{ color: colour, name: name, hoist: hoist, mentionable: mentionable, permissions: packed_permissions }.to_json,
|
240
|
+
Authorization: token,
|
241
|
+
content_type: :json
|
242
|
+
)
|
243
|
+
end
|
244
|
+
|
245
|
+
# Delete a role
|
246
|
+
# https://discordapp.com/developers/docs/resources/guild#delete-guild-role
|
247
|
+
def delete_role(token, server_id, role_id)
|
248
|
+
Discordrb::API.request(
|
249
|
+
:guilds_sid_roles_rid,
|
250
|
+
server_id,
|
251
|
+
:delete,
|
252
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/roles/#{role_id}",
|
253
|
+
Authorization: token
|
254
|
+
)
|
255
|
+
end
|
256
|
+
|
257
|
+
# Get server prune count
|
258
|
+
# https://discordapp.com/developers/docs/resources/guild#get-guild-prune-count
|
259
|
+
def prune_count(token, server_id)
|
260
|
+
Discordrb::API.request(
|
261
|
+
:guilds_sid_prune,
|
262
|
+
server_id,
|
263
|
+
:get,
|
264
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/prune",
|
265
|
+
Authorization: token
|
266
|
+
)
|
267
|
+
end
|
268
|
+
|
269
|
+
# Begin server prune
|
270
|
+
# https://discordapp.com/developers/docs/resources/guild#begin-guild-prune
|
271
|
+
def begin_prune(token, server_id, days)
|
272
|
+
Discordrb::API.request(
|
273
|
+
:guilds_sid_prune,
|
274
|
+
server_id,
|
275
|
+
:post,
|
276
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/prune",
|
277
|
+
{ days: days },
|
278
|
+
Authorization: token
|
279
|
+
)
|
280
|
+
end
|
281
|
+
|
282
|
+
# Get invites from server
|
283
|
+
# https://discordapp.com/developers/docs/resources/guild#get-guild-invites
|
284
|
+
def invites(token, server_id)
|
285
|
+
Discordrb::API.request(
|
286
|
+
:guilds_sid_invites,
|
287
|
+
server_id,
|
288
|
+
:get,
|
289
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/invites",
|
290
|
+
Authorization: token
|
291
|
+
)
|
292
|
+
end
|
293
|
+
|
294
|
+
# Get server integrations
|
295
|
+
# https://discordapp.com/developers/docs/resources/guild#get-guild-integrations
|
296
|
+
def integrations(token, server_id)
|
297
|
+
Discordrb::API.request(
|
298
|
+
:guilds_sid_integrations,
|
299
|
+
server_id,
|
300
|
+
:get,
|
301
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/integrations",
|
302
|
+
Authorization: token
|
303
|
+
)
|
304
|
+
end
|
305
|
+
|
306
|
+
# Create a server integration
|
307
|
+
# https://discordapp.com/developers/docs/resources/guild#create-guild-integration
|
308
|
+
def create_integration(token, server_id, type, id)
|
309
|
+
Discordrb::API.request(
|
310
|
+
:guilds_sid_integrations,
|
311
|
+
server_id,
|
312
|
+
:post,
|
313
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/integrations",
|
314
|
+
{ type: type, id: id },
|
315
|
+
Authorization: token
|
316
|
+
)
|
317
|
+
end
|
318
|
+
|
319
|
+
# Update integration from server
|
320
|
+
# https://discordapp.com/developers/docs/resources/guild#modify-guild-integration
|
321
|
+
def update_integration(token, server_id, integration_id, expire_behavior, expire_grace_period, enable_emoticons)
|
322
|
+
Discordrb::API.request(
|
323
|
+
:guilds_sid_integrations_iid,
|
324
|
+
server_id,
|
325
|
+
:patch,
|
326
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/integrations/#{integration_id}",
|
327
|
+
{ expire_behavior: expire_behavior, expire_grace_period: expire_grace_period, enable_emoticons: enable_emoticons }.to_json,
|
328
|
+
Authorization: token,
|
329
|
+
content_type: :json
|
330
|
+
)
|
331
|
+
end
|
332
|
+
|
333
|
+
# Delete a server integration
|
334
|
+
# https://discordapp.com/developers/docs/resources/guild#delete-guild-integration
|
335
|
+
def delete_integration(token, server_id, integration_id)
|
336
|
+
Discordrb::API.request(
|
337
|
+
:guilds_sid_integrations_iid,
|
338
|
+
server_id,
|
339
|
+
:delete,
|
340
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/integrations/#{integration_id}",
|
341
|
+
Authorization: token
|
342
|
+
)
|
343
|
+
end
|
344
|
+
|
345
|
+
# Sync an integration
|
346
|
+
# https://discordapp.com/developers/docs/resources/guild#sync-guild-integration
|
347
|
+
def sync_integration(token, server_id, integration_id)
|
348
|
+
Discordrb::API.request(
|
349
|
+
:guilds_sid_integrations_iid_sync,
|
350
|
+
server_id,
|
351
|
+
:post,
|
352
|
+
"#{Discordrb::API.api_base}/guilds/#{server_id}/integrations/#{integration_id}/sync",
|
353
|
+
nil,
|
354
|
+
Authorization: token
|
355
|
+
)
|
356
|
+
end
|
357
|
+
end
|