vox 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,425 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'vox/http/route'
4
+ require 'vox/http/util'
5
+
6
+ module Vox
7
+ module HTTP
8
+ module Routes
9
+ # Mixin for /channel/ routes.
10
+ module Channel
11
+ # Channel types.
12
+ TYPES = {
13
+ GUILD_TEXT: 0,
14
+ DM: 1,
15
+ GUILD_VOICE: 2,
16
+ GROUP_DM: 3,
17
+ GUILD_CATEGORY: 4,
18
+ GUILD_NEWS: 5,
19
+ GUILD_STORE: 6
20
+ }.freeze
21
+
22
+ include Util
23
+
24
+ # Get a channel by ID.
25
+ # @param channel_id [String, Integer] ID of the desired channel.
26
+ # @return [Hash<Symbol, Object>] A [channel](https://discord.com/developers/docs/resources/channel#channel-object)
27
+ # object.
28
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#get-channel
29
+ def get_channel(channel_id)
30
+ request(Route.new(:GET, '/channels/%{channel_id}', channel_id: channel_id))
31
+ end
32
+
33
+ # Update a channel's settings. Parameters other than `channel_id` are all optional.
34
+ # @param name [String] Channel name, must be between 2-100 characters.
35
+ # @param type [Integer] Channel type, only switching between `GUILD_TEXT` and `GUILD_NEWS`
36
+ # is supported on guilds which have the `NEWS` feature.
37
+ # @param position [Integer, nil] The position of the channel in the listing.
38
+ # @param topic [String, nil] Channel topic, must be between 0-1024 characters. Only usable in `GUILD_TEXT`
39
+ # and `GUILD_NEWS` channels.
40
+ # @param nsfw [true, false, nil] Whether the channel is not safe for work. Only usable on
41
+ # `GUILD_TEXT`, `GUILD_NEWS`, and `GUILD_STORE` channels.
42
+ # @param rate_limit_per_user [Integer, nil] The amount of seconds a user has to wait between sending
43
+ # messages. This value can be between 0-21600 seconds. Users and bots with `MANAGE_MESSAGES`
44
+ # or `MANAGE_CHANNEL` are unaffected by this limit. Only usable in `GUILD_TEXT` channels.
45
+ # @param bitrate [Integer, nil] The bitrate of a `GUILD_VOICE` channel. Between 8000 and 96000, or
46
+ # 128000 for VIP servers.
47
+ # @param user_limit [Integer, nil] The maximum amount of users allowed in a voice channel. 0 is no limit,
48
+ # and limiting values can be between 1-99.
49
+ # @param permission_overwrites [Array<Overwrite, Hash>] Channel or category specific permissions.
50
+ # @param parent_id [String, Integer] The ID of the new parent category for a channel. Only usable in
51
+ # `GUILD_TEXT`, `GUILD_NEWS`, `GUILD_STORE`, and `GUILD_VOICE` channels.
52
+ # @param reason [String, nil] The reason for modifying the channel.
53
+ # @return [Hash<Symbol, Object>] A [channel](https://discord.com/developers/docs/resources/channel#channel-object)
54
+ # object.
55
+ # @note Fires a channel update. In the event of modifying a category, individual
56
+ # channel updates will fire for each child that is also modified.
57
+ # @vox.permissions MANAGE_CHANNELS
58
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#modify-channel
59
+ def modify_channel(channel_id, name: :undef, type: :undef, position: :undef,
60
+ topic: :undef, nsfw: :undef, rate_limit_per_user: :undef,
61
+ bitrate: :undef, user_limit: :undef,
62
+ permission_overwrites: :undef, parent_id: :undef, reason: nil)
63
+ json = filter_undef({
64
+ name: name, type: type, position: position, topic: topic, nsfw: nsfw,
65
+ rate_limit_per_user: rate_limit_per_user, bitrate: bitrate,
66
+ user_limit: user_limit, permission_overwrites: permission_overwrites,
67
+ parent_id: parent_id
68
+ })
69
+ route = Route.new(:PATCH, '/channels/%{channel_id}', channel_id: channel_id)
70
+ request(route, json: json, reason: reason)
71
+ end
72
+
73
+ # Delete a channel by ID, or close a private message.
74
+ # @param channel_id [String, Integer] The ID of the channel to be deleted.
75
+ # @param reason [String, nil] The reason the channel is being deleted.
76
+ # @return [Hash<Symbol, Object>] The [channel](https://discord.com/developers/docs/resources/channel#channel-object)
77
+ # object of the deleted channel.
78
+ # @note Fires a channel delete event.
79
+ # @note Deleting a category will not delete its children, each child will have
80
+ # its `parent_id` field removed and a channel update will be fired for each
81
+ # of them.
82
+ # @vox.permissions MANAGE_CHANNELS
83
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#deleteclose-channel
84
+ def delete_channel(channel_id, reason: nil)
85
+ route = Route.new(:DELETE, '/channels/%{channel_id}', channel_id: channel_id)
86
+ request(route, reason: reason)
87
+ end
88
+
89
+ # Get messages from a channel, by channel ID. All parameters other than `channel_id` are
90
+ # optional.
91
+ # @param channel_id [String, Integer] The ID of the channel where the messages
92
+ # are being fetched from.
93
+ # @param around [String, Integer] Retreive messages around this ID.
94
+ # @param before [String, Integer] Retreive messages before this ID.
95
+ # @param after [String, Integer] Retreive messages after this ID.
96
+ # @param limit [Integer] Maximum number of messages to return. Can be between 1-100.
97
+ # @return [Array<Hash<Symbol, Object>>] [Message](https://discord.com/developers/docs/resources/channel#message-object)
98
+ # objects returned from the channel history.
99
+ # @note If you lack the `READ_MESSAGE_HISTORY` permission in the desired channel this
100
+ # will return no messages.
101
+ # @vox.permissions VIEW_CHANNEL
102
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#get-channel-messages
103
+ def get_channel_messages(channel_id, around: :undef, before: :undef, after: :undef, limit: :undef)
104
+ route = Route.new(:GET, '/channels/%{channel_id}/messages', channel_id: channel_id)
105
+ params = filter_undef({ around: around, before: before, after: after, limit: limit })
106
+ request(route, query: params)
107
+ end
108
+
109
+ # Get a specific message from a channel by ID.
110
+ # @param channel_id [String, Integer] The ID of the channel containing the desired message.
111
+ # @param message_id [String, Integer] The ID of the desired message.
112
+ # @return [Hash<Symbol, Object>] The [message](https://discord.com/developers/docs/resources/channel#message-object)
113
+ # object.
114
+ # @note In guild channels the `READ_MESSAGE_HISTORY` permission is requred.
115
+ # @vox.permissions READ_MESSAGE_HISTORY
116
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#get-channel-message
117
+ def get_channel_message(channel_id, message_id)
118
+ route = Route.new(:GET, '/channels/%{channel_id}/messages/%{message_id}',
119
+ channel_id: channel_id, message_id: message_id)
120
+ request(route)
121
+ end
122
+
123
+ # Create a message in a channel. All parameters other than `channel_id` are optional.
124
+ # @param channel_id [String, Integer] The ID of the target channel.
125
+ # @param content [String] Message contents, up to 2000 characters.
126
+ # @param nonce [String, Integer] A nonce used for optimistic message sending.
127
+ # @param tts [true, false] Whether this message should use TTS (text to speech).
128
+ # @param file [File, String] A File object, or path to a file, to be uploaded.
129
+ # @param embed [Hash] Embedded rich content. See [embed object](https://discord.com/developers/docs/resources/channel#embed-object).
130
+ # @param allowed_mentions [Hash<(:parse, :roles, :users), Array<:roles, :users, :everyone>>] Rules for what
131
+ # mentions are allowed in the message. See [allowed_mentions object](https://discord.com/developers/docs/resources/channel#allowed-mentions-object).
132
+ # @param attachments [Hash<String, UploadIO>, Array<UploadIO>] A hash in the form of `filename => upload_io` to
133
+ # be referenced in embeds via the `attachment://` URI, or an array of {UploadIO} who's filenames are derived
134
+ # from the existing UploadIO object. See [attachment:// docs](https://discord.com/developers/docs/resources/channel#create-message-using-attachments-within-embeds).
135
+ # @return [Hash<Symbol, Object>] The created [message](https://discord.com/developers/docs/resources/channel#message-object)
136
+ # object.
137
+ # @note You must send one of `content`, `embed`, or `file`.
138
+ # @note If `tts` is set to `true`, you also require the `SEND_TTS_MESSAGES` permission.
139
+ # @vox.permissions SEND_MESSAGES SEND_TTS_MESSAGES
140
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#create-message
141
+ def create_message(channel_id, content: :undef, nonce: :undef, tts: :undef, file: :undef, embed: :undef,
142
+ allowed_mentions: :undef, attachments: :undef)
143
+ route = Route.new(:POST, '/channels/%{channel_id}/messages', channel_id: channel_id)
144
+ json = filter_undef({ content: content, nonce: nonce, tts: tts, embed: embed,
145
+ allowed_mentions: allowed_mentions })
146
+
147
+ if file != :undef
148
+ data = { file: file, payload_json: MultiJson.dump(json) }
149
+ request(route, data: data)
150
+ elsif attachments != :undef
151
+ attachments = attachments.collect { |k, v| UploadIO.new(v.io, v.content_type, k) } if attachments.is_a? Hash
152
+ attach_hash = Array(0...attachments.size).zip(attachments).to_h
153
+ data = attach_hash.merge({ payload_json: MultiJson.dump(json) })
154
+ request(route, data: data)
155
+ else
156
+ request(route, json: json)
157
+ end
158
+ end
159
+
160
+ # Create a reaction on a message.
161
+ # @param channel_id [String, Integer] The ID of the channel that contains the target message.
162
+ # @param message_id [String, Integer] The ID of the target message.
163
+ # @param emoji [String] Either a unicode emoji, or Discord emoji in the format of `name:id`.
164
+ # @note Requires `READ_MESSAGE_HISTORY`, and `ADD_REACTIONS` if no other user has reacted with
165
+ # the emoji.
166
+ # @note If your emoji is in the wrong format you will receive error code `10014: Unknown Emoji`
167
+ # @note If the emoji name is unknown, you can provide any alphanumeric value as a placeholder.
168
+ # @vox.permissions READ_MESSAGE_HISTORY ADD_REACTIONS
169
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#create-reaction
170
+ def create_reaction(channel_id, message_id, emoji)
171
+ escaped_emoji = URI.encode_www_form_component(emoji)
172
+ route = Route.new(:PUT, '/channels/%{channel_id}/messages/%{message_id}/reactions/%{emoji}/@me',
173
+ channel_id: channel_id, message_id: message_id, emoji: escaped_emoji)
174
+ request(route)
175
+ end
176
+
177
+ # Delete a reaction from the current user on a message.
178
+ # @param channel_id [String, Integer] The ID of the channel that contains the target message.
179
+ # @param message_id [String, Integer] The ID of the target message.
180
+ # @param emoji [String] Either a unicode emoji, or Discord emoji in the format of `name:id`.
181
+ # @note If your emoji is in the wrong format you will receive error code `10014: Unknown Emoji`
182
+ # @note If the emoji name is unknown, you can provide any alphanumeric value as a placeholder.
183
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#delete-own-reaction
184
+ def delete_own_reaction(channel_id, message_id, emoji)
185
+ escaped_emoji = URI.encode_www_form_component(emoji)
186
+ route = Route.new(:DELETE, '/channels/%{channel_id}/messages/%{message_id}/reactions/%{emoji}/@me',
187
+ channel_id: channel_id, message_id: message_id, emoji: escaped_emoji)
188
+ request(route)
189
+ end
190
+
191
+ # Delete a reaction from a user on a message.
192
+ # @param channel_id [String, Integer] The ID of the channel that contains the target message.
193
+ # @param message_id [String, Integer] The ID of the target message.
194
+ # @param emoji [String] Either a unicode emoji, or Discord emoji in the format of `name:id`.
195
+ # @param user_id [String, Integer] The ID of the user to delete the reaction for.
196
+ # @vox.permissions MANAGE_MESSAGES
197
+ # @note If your emoji is in the wrong format you will receive error code `10014: Unknown Emoji`
198
+ # @note If the emoji name is unknown, you can provide any alphanumeric value as a placeholder.
199
+ # @vox.permissions MANAGE_MESSAGES
200
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#delete-user-reaction
201
+ def delete_user_reaction(channel_id, message_id, emoji, user_id)
202
+ escaped_emoji = URI.encode_www_form_component(emoji)
203
+ route = Route.new(:DELETE, '/channels/%{channel_id}/messages/%{message_id}/reactions/%{emoji}/%{user_id}',
204
+ channel_id: channel_id, message_id: message_id, emoji: escaped_emoji, user_id: user_id)
205
+ request(route)
206
+ end
207
+
208
+ # Get a list of users that have reacted with a specific emoji.
209
+ # @param channel_id [String, Integer] The ID of the channel that contains the target message.
210
+ # @param message_id [String, Integer] The ID of the target message.
211
+ # @param emoji [String] Either a unicode emoji, or Discord emoji in the format of `name:id`.
212
+ # @param before [String, Integer] Retreive users before this ID.
213
+ # @param after [String, Integer] Retreive users after this ID.
214
+ # @param limit [Integer] The maximum number of users to receive. Between 1-100.
215
+ # @note If your emoji is in the wrong format you will receive error code `10014: Unknown Emoji`
216
+ # @note If the emoji name is unknown, you can provide any alphanumeric value as a placeholder.
217
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#get-reactions
218
+ def get_reactions(channel_id, message_id, emoji, before: :undef, after: :undef, limit: :undef)
219
+ escaped_emoji = URI.encode_www_form_component(emoji)
220
+ params = filter_undef({ before: before, after: after, limit: limit })
221
+ route = Route.new(:GET, '/channels/%{channel_id}/messages/%{message_id}/reactions/%{emoji}',
222
+ channel_id: channel_id, message_id: message_id, emoji: escaped_emoji)
223
+ request(route, query: params)
224
+ end
225
+
226
+ # Delete all reactions on a message.
227
+ # @param channel_id [String, Integer] The ID of the channel that contains the target message.
228
+ # @param message_id [String, Integer] The ID of the target message.
229
+ # @vox.permissions MANAGE_MESSAGES
230
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#delete-all-reactions
231
+ def delete_all_reactions(channel_id, message_id)
232
+ route = Route.new(:DELETE, '/channels/%{channel_id}/messages/%{message_id}/reactions',
233
+ channel_id: channel_id, message_id: message_id)
234
+ request(route)
235
+ end
236
+
237
+ # Delete all reactions of a specific emoji on a message.
238
+ # @param channel_id [String, Integer] The ID of the channel that contains the target message.
239
+ # @param message_id [String, Integer] The ID of the target message.
240
+ # @param emoji [String] Either a unicode emoji, or Discord emoji in the format of `name:id`.
241
+ # @note If your emoji is in the wrong format you will receive error code `10014: Unknown Emoji`
242
+ # @note If the emoji name is unknown, you can provide any alphanumeric value as a placeholder.
243
+ # @vox.permissions MANAGE_MESSAGES
244
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#delete-all-reactions-for-emoji
245
+ def delete_all_reactions_for_emoji(channel_id, message_id, emoji)
246
+ escaped_emoji = URI.encode_www_form_component(emoji)
247
+ route = Route.new(:DELETE, '/channels/%{channel_id}/messages/%{message_id}/reactions/%{emoji}',
248
+ channel_id: channel_id, message_id: message_id, emoji: escaped_emoji)
249
+ request(route)
250
+ end
251
+
252
+ # Edit a previously sent message. All parameters other than `channel_id` and `message_id`
253
+ # are optional and nullable.
254
+ # @param channel_id [String, Integer] The ID of the channel that contains the target message.
255
+ # @param message_id [String, Integer] The ID of the target message.
256
+ # @param content [String, nil] The message content. If `nil`, existing content will be removed.
257
+ # @param embed [Hash] Embedded rich content. If `nil`, the existing embed will be removed.
258
+ # @param flags [Integer] Message flags. If `nil`, the existing flags will be removed. When setting flags be sure
259
+ # to include all previously set flags in addition to the ones you are modifying.
260
+ # See [message flags](https://discord.com/developers/docs/resources/channel#message-object-message-flags).
261
+ # @note You can only edit the flags of a message not sent by the current user, and only if the current
262
+ # user has `MANAGE_MESSAGES` permissions.
263
+ # @vox.permissions MANAGE_MESSAGES (if editing the flags of a message not sent by the current user)
264
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#edit-message
265
+ def edit_message(channel_id, message_id, content: :undef, embed: :undef, flags: :undef)
266
+ route = Route.new(:PATCH, '/channels/%{channel_id}/messages/%{message_id}',
267
+ channel_id: channel_id, message_id: message_id)
268
+ json = filter_undef({ content: content, embed: embed, flags: flags })
269
+ request(route, json: json)
270
+ end
271
+
272
+ # Delete a previously sent message.
273
+ # @param channel_id [String, Integer] The ID of the channel that contains the target message.
274
+ # @param message_id [String, Integer] The ID of the target message.
275
+ # @param reason [String] The reason for deleting this message.
276
+ # @vox.permissions MANAGE_MESSAGES (if not the message was not sent by the current user)
277
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#delete-message
278
+ def delete_message(channel_id, message_id, reason: nil)
279
+ route = Route.new(:DELETE, '/channels/%{channel_id}/messages/%{message_id}',
280
+ channel_id: channel_id, message_id: message_id)
281
+ request(route, reason: reason)
282
+ end
283
+
284
+ # Delete multiple message in a single request.
285
+ # @param channel_id [String, Integer] The ID of the channel that contains the target messages.
286
+ # @param messages [Array<String, Integer>] The IDs of the target messages.
287
+ # @param reason [String] The reason the messages are being deleted.
288
+ # @note The endpoint will not delete messages older than 2 weeks and will fail with {HTTP::Error::BadRequest}
289
+ # if any message provided is older than that, or a duplicate within the list of message IDs.
290
+ # @vox.permissions MANAGE_MESSAGES
291
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#bulk-delete-messages
292
+ def bulk_delete_messages(channel_id, messages, reason: nil)
293
+ route = Route.new(:POST, '/channels/%{channel_id}/messages/bulk-delete', channel_id: channel_id)
294
+ request(route, json: { messages: messages }, reason: reason)
295
+ end
296
+
297
+ # Edit the channel permission overwrites for a user or role in a channel.
298
+ # @param channel_id [String, Integer] The ID of the channel that contains the target overwrite.
299
+ # @param overwrite_id [String, Integer] The ID of the target user or role.
300
+ # @param allow [Integer] Bitwise value of all allowed permissions.
301
+ # @param deny [Integer] Bitwise value of all denied permissions.
302
+ # @param type [:member, :role]
303
+ # @note Only usable for guild channels.
304
+ # @vox.permissions MANAGE_ROLES
305
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#edit-channel-permissions
306
+ def edit_channel_permissions(channel_id, overwrite_id, allow:, deny:, type:, reason: nil)
307
+ route = Route.new(:PUT, '/channels/%{channel_id}/permissions/%{overwrite_id}',
308
+ channel_id: channel_id, overwrite_id: overwrite_id)
309
+ json = { allow: allow, deny: deny, type: type }
310
+ request(route, json: json, reason: reason)
311
+ end
312
+
313
+ # Get a list of invites (with invite metadata) for a channel.
314
+ # @param channel_id [String, Integer] The ID of the target channel.
315
+ # @return [Array<Hash<Symbol, Object>>] An array of [invite objects](https://discord.com/developers/docs/resources/invite#invite-object-invite-structure)
316
+ # with [invite metadata](https://discord.com/developers/docs/resources/invite#invite-metadata-object-invite-metadata-structure).
317
+ # @vox.permissions MANAGE_CHANNELS
318
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#get-channel-invites
319
+ def get_channel_invites(channel_id)
320
+ route = Route.new(:GET, '/channels/%{channel_id}/invites', channel_id: channel_id)
321
+ request(route)
322
+ end
323
+
324
+ # Create a new invite for a channel. All parameters aside from `channel_id` are optional.
325
+ # @param channel_id [String, Integer] The ID of the channel to create an invite in.
326
+ # @param max_age [Integer] Duration of invite in seconds before expiry, or 0 for never. Defaults to 24 hours.
327
+ # @param max_uses [Integer] Maximum number of uses, or 0 for unlimited uses. Defaults to 0.
328
+ # @param temporary [true, false] Whether this invite only grants temporary membership. Defaults to false.
329
+ # @param unique [true, false] Whether or not to avoid using an existing similar invite. Defaults to false.
330
+ # @param target_user [String, Integer] The ID of the user intended for this invite.
331
+ # @param target_user_type [Integer] The [target user type](https://discord.com/developers/docs/resources/invite#invite-object-target-user-types)
332
+ # of this invite.
333
+ # @param reason [String] The reason for creating this invite.
334
+ # @return [Hash<Symbol, Object>] The created [invite object](https://discord.com/developers/docs/resources/invite#invite-object-invite-structure).
335
+ # @vox.permissions CREATE_INSTANT_INVITE
336
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#create-channel-invite
337
+ def create_channel_invite(channel_id, max_age: :undef, max_uses: :undef, temporary: :undef, unique: :undef,
338
+ target_user: :undef, target_user_type: :undef, reason: nil)
339
+ route = Route.new(:POST, '/channels/%{channel_id}/invites', channel_id: channel_id)
340
+ json = filter_undef({ max_age: max_age, max_uses: max_uses, temporary: temporary, unique: unique,
341
+ target_user: target_user, target_user_type: target_user_type })
342
+ request(route, json: json, reason: reason)
343
+ end
344
+
345
+ # Delete a channel permission overwrite for a user or role in a channel.
346
+ # @param channel_id [String, Integer] The ID of the channel that contains the target overwrite.
347
+ # @param overwrite_id [String, Integer] The ID of the target user or role.
348
+ # @param reason [String] The reason this overwrite is being deleted.
349
+ # @note Only usable within guild channels.
350
+ # @vox.permissions MANAGE_ROLES
351
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#delete-channel-permission
352
+ def delete_channel_permission(channel_id, overwrite_id, reason: nil)
353
+ route = Route.new(:DELETE, '/channels/%{channel_id}/permissions/%{overwrite_id}',
354
+ channel_id: channel_id, overwrite_id: overwrite_id)
355
+ request(route, reason: reason)
356
+ end
357
+
358
+ # Post a typing indicator for a channel.
359
+ # @param channel_id [String, Integer] The ID of the channel to appear as typing in.
360
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#trigger-typing-indicator
361
+ def trigger_typing_indicator(channel_id)
362
+ route = Route.new(:POST, '/channels/%{channel_id}/typing', channel_id: channel_id)
363
+ request(route)
364
+ end
365
+
366
+ # Get all pinned messages in a channel.
367
+ # @param channel_id [String, Integer] The ID of the channel to fetch the pins of.
368
+ # @return [Array<Hash<Symbol, Object>>] An array of pinned [message objects](https://discord.com/developers/docs/resources/channel#message-object).
369
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#get-pinned-messages
370
+ def get_pinned_messages(channel_id)
371
+ route = Route.new(:GET, '/channels/%{channel_id}/pins', channel_id: channel_id)
372
+ request(route)
373
+ end
374
+
375
+ # Add a message to a channel's pins.
376
+ # @param channel_id [String, Integer] The ID of the channel to add a pinned message to.
377
+ # @param message_id [String, Integer] The ID of the message to pin.
378
+ # @param reason [String] The reason a message is being pinned.
379
+ # @vox.permissions MANAGE_MESSAGES
380
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#add-pinned-channel-message
381
+ def add_pinned_channel_message(channel_id, message_id, reason: nil)
382
+ route = Route.new(:POST, '/channels/%{channel_id}/pins/%{message_id}',
383
+ channel_id: channel_id, message_id: message_id)
384
+ request(route, reason: reason)
385
+ end
386
+
387
+ # Remove a message from a channel's pins.
388
+ # @param channel_id [String, Integer] The ID of the channel to remove a pinned message from.
389
+ # @param message_id [String, Integer] The ID of the message to unpin.
390
+ # @param reason [String] The reason a message is being unpinned.
391
+ # @vox.permissions MANAGE_MESSAGES
392
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#delete-pinned-channel-message
393
+ def delete_pinned_channel_message(channel_id, message_id, reason: nil)
394
+ route = Route.new(:DELETE, '/channels/%{channel_id}/pins/%{message_id}',
395
+ channel_id: channel_id, message_id: message_id)
396
+ request(route, reason: reason)
397
+ end
398
+
399
+ # Add a recipient to a group DM using their access token.
400
+ # @param channel_id [String, Integer] The ID of the group DM to add the user to.
401
+ # @param user_id [String, Integer] The ID of the user to add.
402
+ # @param access_token [String] The access token of a user that has granted your app
403
+ # the `gdm.join` scope.
404
+ # @param nick [String] The nickname of the user being added.
405
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#group-dm-add-recipient
406
+ def group_dm_add_recipient(channel_id, user_id, access_token:, nick: :undef)
407
+ route = Route.new(:PUT, '/channels/%{channel_id}/recipients/%{user_id}',
408
+ channel_id: channel_id, user_id: user_id)
409
+ json = filter_undef({ access_token: access_token, nick: nick })
410
+ request(route, json: json)
411
+ end
412
+
413
+ # Remove a recipient from a group DM.
414
+ # @param channel_id [String, Integer] The ID of the channel the user is being removed from.
415
+ # @param user_id [String, Integer] The ID of the user being removed from the group DM.
416
+ # @vox.api_docs https://discord.com/developers/docs/resources/channel#group-dm-remove-recipient
417
+ def group_dm_remove_recipient(channel_id, user_id)
418
+ route = Route.new(:DELETE, '/channels/%{channel_id}/recipients/%{user_id}',
419
+ channel_id: channel_id, user_id: user_id)
420
+ request(route)
421
+ end
422
+ end
423
+ end
424
+ end
425
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'base64'
4
+ require 'vox/http/route'
5
+ require 'vox/http/util'
6
+
7
+ module Vox
8
+ module HTTP
9
+ module Routes
10
+ # Mixin for emoji routes.
11
+ module Emoji
12
+ include Util
13
+
14
+ # Fetch a list of emojis for a given guild.
15
+ # @param guild_id [String, Integer] The ID of the guild this emoji belongs to.
16
+ # @return [Array<Hash<Symbol, Object>>] An array of [emoji](https://discord.com/developers/docs/resources/emoji#emoji-object)
17
+ # objects.
18
+ # @vox.api_docs https://discord.com/developers/docs/resources/emoji#list-guild-emojis
19
+ def list_guild_emojis(guild_id)
20
+ route = Route.new(:GET, '/guilds/%{guild_id}/emojis', guild_id: guild_id)
21
+ request(route)
22
+ end
23
+
24
+ # Get an emoji object by ID.
25
+ # @param guild_id [String, Integer] The ID of the guild this emoji belongs to.
26
+ # @param emoji_id [String, Integer] The ID of the desired emoji.
27
+ # @return [Hash<Symbol, Object>] An [emoji](https://discord.com/developers/docs/resources/emoji#emoji-object)
28
+ # object.
29
+ # @vox.api_docs https://discord.com/developers/docs/resources/emoji#get-guild-emoji
30
+ def get_guild_emoji(guild_id, emoji_id)
31
+ route = Route.new(:GET, '/guilds/%{guild_id}/emojis/%{emoji_id}', guild_id: guild_id, emoji_id: emoji_id)
32
+ request(route)
33
+ end
34
+
35
+ # Create an emoji in a target guild.
36
+ # @param guild_id [String, Integer] The ID of the guild to create an emoji in.
37
+ # @param image [UploadIO] {UploadIO} for the emoji image. Can be up to 256kb in size.
38
+ # @param name [String] The name for the emoji.
39
+ # @param roles [Array<String, Integer>] Roles for which the emoji will be whitelisted.
40
+ # @return [Hash<Symbol, Object>] An [emoji](https://discord.com/developers/docs/resources/emoji#emoji-object)
41
+ # object.
42
+ # @note Attempting to upload an emoji image larger than 256kb will result in a {Error::BadRequest} with
43
+ # no JSON status code.
44
+ # @vox.permissions MANAGE_EMOJIS
45
+ # @vox.api_docs https://discord.com/developers/docs/resources/emoji#create-guild-emoji
46
+ def create_guild_emoji(guild_id, image:, name: :undef, roles: :undef)
47
+ image_data = image.io.read
48
+ json = filter_undef({ name: name, roles: roles,
49
+ image: "data:#{image.content_type};base64,#{Base64.encode64(image_data)}" })
50
+
51
+ route = Route.new(:POST, '/guilds/%{guild_id}/emojis', guild_id: guild_id)
52
+ request(route, json: json)
53
+ end
54
+
55
+ # Modify a guild emoji.
56
+ # @param guild_id [String, Integer] The ID of the guild the emoji is in.
57
+ # @param emoji_id [String, Integer] The ID of the target emoji.
58
+ # @param name [String] The name for the emoji.
59
+ # @param roles [Array<String, Integer>] Roles for which the emoji will be whitelisted.
60
+ # @param reason [String] The reason this emoji is being modified.
61
+ # @return [Hash<Symbol, Object>] The updated [emoji](https://discord.com/developers/docs/resources/emoji#emoji-object)
62
+ # object.
63
+ # @vox.permissions MANAGE_EMOJIS
64
+ # @vox.api_docs https://discord.com/developers/docs/resources/emoji#modify-guild-emoji
65
+ def modify_guild_emoji(guild_id, emoji_id, name: :undef, roles: :undef, reason: nil)
66
+ json = filter_undef({ name: name, roles: roles })
67
+ route = Route.new(:PATCH, '/guilds/%{guild_id}/emojis/%{emoji_id}',
68
+ guild_id: guild_id, emoji_id: emoji_id)
69
+ request(route, json: json, reason: reason)
70
+ end
71
+
72
+ # Delete an emoji by its ID.
73
+ # @param guild_id [String, Integer] The ID of the guild that owns this emoji.
74
+ # @param emoji_id [String, Integer] The ID of the emoji to be deleted.
75
+ # @param reason [String] The reason this emoji is being deleted.
76
+ # @return [nil] Returns `nil` on success.
77
+ # @vox.permissions MANAGE_EMOJIS
78
+ # @vox.api_docs https://discord.com/developers/docs/resources/emoji#delete-guild-emoji
79
+ def delete_guild_emoji(guild_id, emoji_id, reason: nil)
80
+ route = Route.new(:DELETE, '/guilds/%{guild_id}/emojis/%{emoji_id}',
81
+ guild_id: guild_id, emoji_id: emoji_id)
82
+ request(route, reason: reason)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end