Module: MijDiscord::Core::API::Channel
- Defined in:
- lib/mij-discord/core/api/channel.rb
Class Method Summary collapse
-
.add_group_user(auth, group_channel_id, user_id) ⇒ Object
Add a user to a group channel.
-
.bulk_delete_messages(auth, channel_id, messages = []) ⇒ Object
Delete messages in bulk discordapp.com/developers/docs/resources/channel#bulk-delete-messages.
-
.create_empty_group(auth, bot_user_id) ⇒ Object
Create an empty group channel.
-
.create_group(auth, pm_channel_id, user_id) ⇒ Object
Create a group channel.
-
.create_invite(auth, channel_id, max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil) ⇒ Object
Create an instant invite from a server or a channel id discordapp.com/developers/docs/resources/channel#create-channel-invite.
-
.create_message(auth, channel_id, message, tts = false, embed = nil, mentions = []) ⇒ Object
Send a message to a channel discordapp.com/developers/docs/resources/channel#create-message.
-
.create_reaction(auth, channel_id, message_id, emoji) ⇒ Object
Create a reaction on a message using this client discordapp.com/developers/docs/resources/channel#create-reaction.
-
.create_webhook(auth, channel_id, name, avatar = nil, reason = nil) ⇒ Object
Create a webhook discordapp.com/developers/docs/resources/webhook#create-webhook.
-
.delete(auth, channel_id, reason = nil) ⇒ Object
Delete a channel discordapp.com/developers/docs/resources/channel#deleteclose-channel.
-
.delete_all_reactions(auth, channel_id, message_id) ⇒ Object
Deletes all reactions on a message from all clients discordapp.com/developers/docs/resources/channel#delete-all-reactions.
-
.delete_message(auth, channel_id, message_id) ⇒ Object
Delete a message discordapp.com/developers/docs/resources/channel#delete-message.
-
.delete_own_reaction(auth, channel_id, message_id, emoji) ⇒ Object
Delete this client’s own reaction on a message discordapp.com/developers/docs/resources/channel#delete-own-reaction.
-
.delete_permission(auth, channel_id, overwrite_id, reason = nil) ⇒ Object
Delete channel permission discordapp.com/developers/docs/resources/channel#delete-channel-permission.
-
.delete_user_reaction(auth, channel_id, message_id, emoji, user_id) ⇒ Object
Delete another client’s reaction on a message discordapp.com/developers/docs/resources/channel#delete-user-reaction.
-
.edit_message(auth, channel_id, message_id, message, mentions = [], embed = nil) ⇒ Object
Edit a message discordapp.com/developers/docs/resources/channel#edit-message.
-
.get_reactions(auth, channel_id, message_id, emoji) ⇒ Object
Get a list of clients who reacted with a specific reaction on a message discordapp.com/developers/docs/resources/channel#get-reactions.
-
.invites(auth, channel_id) ⇒ Object
Get a channel’s invite list discordapp.com/developers/docs/resources/channel#get-channel-invites.
-
.leave_group(auth, group_channel_id) ⇒ Object
Leave a group channel.
-
.message(auth, channel_id, message_id) ⇒ Object
Get a single message from a channel’s history by id discordapp.com/developers/docs/resources/channel#get-channel-message.
-
.messages(auth, channel_id, amount, before = nil, after = nil, around = nil) ⇒ Object
Get a list of messages from a channel’s history discordapp.com/developers/docs/resources/channel#get-channel-messages.
- .pin_message(auth, channel_id, message_id) ⇒ Object
-
.pinned_messages(auth, channel_id) ⇒ Object
Get a list of pinned messages in a channel discordapp.com/developers/docs/resources/channel#get-pinned-messages.
-
.remove_group_user(auth, group_channel_id, user_id) ⇒ Object
Remove a user from a group channel.
-
.resolve(auth, channel_id) ⇒ Object
Get a channel’s data discordapp.com/developers/docs/resources/channel#get-channel.
-
.start_typing(auth, channel_id) ⇒ Object
Start typing (needs to be resent every 5 seconds to keep up the typing) discordapp.com/developers/docs/resources/channel#trigger-typing-indicator.
- .unpin_message(auth, channel_id, message_id) ⇒ Object
-
.update(auth, channel_id, name, topic, nsfw, parent_id, position, bitrate, user_limit, overwrites, reason = nil) ⇒ Object
Update a channel’s data discordapp.com/developers/docs/resources/channel#modify-channel.
-
.update_permission(auth, channel_id, overwrite_id, allow, deny, type, reason = nil) ⇒ Object
Update a channels permission for a role or member discordapp.com/developers/docs/resources/channel#edit-channel-permissions.
-
.upload_file(auth, channel_id, file, caption = nil, tts = false) ⇒ Object
Send a file as a message to a channel discordapp.com/developers/docs/resources/channel#upload-file.
-
.webhooks(auth, channel_id) ⇒ Object
Get channel webhooks discordapp.com/developers/docs/resources/webhook#get-channel-webhooks.
Class Method Details
.add_group_user(auth, group_channel_id, user_id) ⇒ Object
Add a user to a group channel.
354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/mij-discord/core/api/channel.rb', line 354 def add_group_user(auth, group_channel_id, user_id) MijDiscord::Core::API.request( :channels_cid_recipients_uid, nil, :put, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{group_channel_id}/recipients/#{user_id}", {}.to_json, Authorization: auth, content_type: :json ) end |
.bulk_delete_messages(auth, channel_id, messages = []) ⇒ Object
Delete messages in bulk discordapp.com/developers/docs/resources/channel#bulk-delete-messages
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/mij-discord/core/api/channel.rb', line 135 def (auth, channel_id, = []) MijDiscord::Core::API.request( :channels_cid_messages_bulk_delete, channel_id, :post, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/bulk-delete", { messages: }.to_json, Authorization: auth, content_type: :json ) end |
.create_empty_group(auth, bot_user_id) ⇒ Object
Create an empty group channel.
322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/mij-discord/core/api/channel.rb', line 322 def create_empty_group(auth, bot_user_id) MijDiscord::Core::API.request( :users_uid_channels, nil, :post, "#{MijDiscord::Core::API::APIBASE_URL}/users/#{bot_user_id}/channels", {}.to_json, Authorization: auth, content_type: :json ) end |
.create_group(auth, pm_channel_id, user_id) ⇒ Object
Create a group channel.
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/mij-discord/core/api/channel.rb', line 335 def create_group(auth, pm_channel_id, user_id) MijDiscord::Core::API.request( :channels_cid_recipients_uid, nil, :put, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{pm_channel_id}/recipients/#{user_id}", {}.to_json, Authorization: auth, content_type: :json ) rescue RestClient::InternalServerError raise 'Attempted to add self as a new group channel recipient!' rescue RestClient::NoContent raise 'Attempted to create a group channel with the PM channel recipient!' rescue RestClient::Forbidden raise 'Attempted to add a user to group channel without permission!' end |
.create_invite(auth, channel_id, max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil) ⇒ Object
Create an instant invite from a server or a channel id discordapp.com/developers/docs/resources/channel#create-channel-invite
245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/mij-discord/core/api/channel.rb', line 245 def create_invite(auth, channel_id, max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil) MijDiscord::Core::API.request( :channels_cid_invites, channel_id, :post, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/invites", { max_age: max_age, max_uses: max_uses, temporary: temporary, unique: unique }.to_json, Authorization: auth, content_type: :json, 'X-Audit-Log-Reason': reason ) end |
.create_message(auth, channel_id, message, tts = false, embed = nil, mentions = []) ⇒ Object
Send a message to a channel discordapp.com/developers/docs/resources/channel#create-message
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/mij-discord/core/api/channel.rb', line 76 def (auth, channel_id, , tts = false, = nil, mentions = []) MijDiscord::Core::API.request( :channels_cid_messages_mid, channel_id, :post, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages", { content: , mentions: mentions, tts: tts, embed: }.to_json, Authorization: auth, content_type: :json ) rescue RestClient::BadRequest => e parsed = JSON.parse(e.response.body) if (content = parsed['content']).is_a?(Array) && content.first == 'Must be 2000 or fewer characters long.' raise MijDiscord::Core::Errors::MessageTooLong, "Message over the character limit (#{message.length} > 2000)" end raise end |
.create_reaction(auth, channel_id, message_id, emoji) ⇒ Object
Create a reaction on a message using this client discordapp.com/developers/docs/resources/channel#create-reaction
149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/mij-discord/core/api/channel.rb', line 149 def create_reaction(auth, channel_id, , emoji) emoji = URI.encode(emoji) unless emoji.ascii_only? MijDiscord::Core::API.request( :channels_cid_messages_mid_reactions_emoji_me, channel_id, :put, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/@me", nil, Authorization: auth, content_type: :json, header_bypass_delay: 0.25 ) end |
.create_webhook(auth, channel_id, name, avatar = nil, reason = nil) ⇒ Object
Create a webhook discordapp.com/developers/docs/resources/webhook#create-webhook
392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/mij-discord/core/api/channel.rb', line 392 def create_webhook(auth, channel_id, name, avatar = nil, reason = nil) MijDiscord::Core::API.request( :channels_cid_webhooks, channel_id, :post, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/webhooks", { name: name, avatar: avatar }.to_json, Authorization: auth, content_type: :json, 'X-Audit-Log-Reason': reason ) end |
.delete(auth, channel_id, reason = nil) ⇒ Object
Delete a channel discordapp.com/developers/docs/resources/channel#deleteclose-channel
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mij-discord/core/api/channel.rb', line 39 def delete(auth, channel_id, reason = nil) MijDiscord::Core::API.request( :channels_cid, channel_id, :delete, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}", Authorization: auth, 'X-Audit-Log-Reason': reason ) end |
.delete_all_reactions(auth, channel_id, message_id) ⇒ Object
Deletes all reactions on a message from all clients discordapp.com/developers/docs/resources/channel#delete-all-reactions
206 207 208 209 210 211 212 213 214 |
# File 'lib/mij-discord/core/api/channel.rb', line 206 def delete_all_reactions(auth, channel_id, ) MijDiscord::Core::API.request( :channels_cid_messages_mid_reactions, channel_id, :delete, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/#{message_id}/reactions", Authorization: auth ) end |
.delete_message(auth, channel_id, message_id) ⇒ Object
Delete a message discordapp.com/developers/docs/resources/channel#delete-message
123 124 125 126 127 128 129 130 131 |
# File 'lib/mij-discord/core/api/channel.rb', line 123 def (auth, channel_id, ) MijDiscord::Core::API.request( :channels_cid_messages_mid, channel_id, :delete, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/#{message_id}", Authorization: auth ) end |
.delete_own_reaction(auth, channel_id, message_id, emoji) ⇒ Object
Delete this client’s own reaction on a message discordapp.com/developers/docs/resources/channel#delete-own-reaction
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/mij-discord/core/api/channel.rb', line 165 def delete_own_reaction(auth, channel_id, , emoji) emoji = URI.encode(emoji) unless emoji.ascii_only? MijDiscord::Core::API.request( :channels_cid_messages_mid_reactions_emoji_me, channel_id, :delete, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/@me", Authorization: auth, header_bypass_delay: 0.25 ) end |
.delete_permission(auth, channel_id, overwrite_id, reason = nil) ⇒ Object
Delete channel permission discordapp.com/developers/docs/resources/channel#delete-channel-permission
260 261 262 263 264 265 266 267 268 269 |
# File 'lib/mij-discord/core/api/channel.rb', line 260 def (auth, channel_id, overwrite_id, reason = nil) MijDiscord::Core::API.request( :channels_cid_permissions_oid, channel_id, :delete, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/permissions/#{overwrite_id}", Authorization: auth, 'X-Audit-Log-Reason': reason ) end |
.delete_user_reaction(auth, channel_id, message_id, emoji, user_id) ⇒ Object
Delete another client’s reaction on a message discordapp.com/developers/docs/resources/channel#delete-user-reaction
179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/mij-discord/core/api/channel.rb', line 179 def delete_user_reaction(auth, channel_id, , emoji, user_id) emoji = URI.encode(emoji) unless emoji.ascii_only? MijDiscord::Core::API.request( :channels_cid_messages_mid_reactions_emoji_uid, channel_id, :delete, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/#{user_id}", Authorization: auth, header_bypass_delay: 0.25 ) end |
.edit_message(auth, channel_id, message_id, message, mentions = [], embed = nil) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/mij-discord/core/api/channel.rb', line 109 def (auth, channel_id, , , mentions = [], = nil) MijDiscord::Core::API.request( :channels_cid_messages_mid, channel_id, :patch, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/#{message_id}", { content: , mentions: mentions, embed: }.to_json, Authorization: auth, content_type: :json ) end |
.get_reactions(auth, channel_id, message_id, emoji) ⇒ Object
Get a list of clients who reacted with a specific reaction on a message discordapp.com/developers/docs/resources/channel#get-reactions
193 194 195 196 197 198 199 200 201 202 |
# File 'lib/mij-discord/core/api/channel.rb', line 193 def get_reactions(auth, channel_id, , emoji) emoji = URI.encode(emoji) unless emoji.ascii_only? MijDiscord::Core::API.request( :channels_cid_messages_mid_reactions_emoji, channel_id, :get, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}", Authorization: auth ) end |
.invites(auth, channel_id) ⇒ Object
Get a channel’s invite list discordapp.com/developers/docs/resources/channel#get-channel-invites
233 234 235 236 237 238 239 240 241 |
# File 'lib/mij-discord/core/api/channel.rb', line 233 def invites(auth, channel_id) MijDiscord::Core::API.request( :channels_cid_invites, channel_id, :get, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/invites", Authorization: auth ) end |
.leave_group(auth, group_channel_id) ⇒ Object
Leave a group channel.
379 380 381 382 383 384 385 386 387 388 |
# File 'lib/mij-discord/core/api/channel.rb', line 379 def leave_group(auth, group_channel_id) MijDiscord::Core::API.request( :channels_cid, nil, :delete, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{group_channel_id}", Authorization: auth, content_type: :json ) end |
.message(auth, channel_id, message_id) ⇒ Object
Get a single message from a channel’s history by id discordapp.com/developers/docs/resources/channel#get-channel-message
64 65 66 67 68 69 70 71 72 |
# File 'lib/mij-discord/core/api/channel.rb', line 64 def (auth, channel_id, ) MijDiscord::Core::API.request( :channels_cid_messages_mid, channel_id, :get, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/#{message_id}", Authorization: auth ) end |
.messages(auth, channel_id, amount, before = nil, after = nil, around = nil) ⇒ Object
Get a list of messages from a channel’s history discordapp.com/developers/docs/resources/channel#get-channel-messages
52 53 54 55 56 57 58 59 60 |
# File 'lib/mij-discord/core/api/channel.rb', line 52 def (auth, channel_id, amount, before = nil, after = nil, around = nil) MijDiscord::Core::API.request( :channels_cid_messages, channel_id, :get, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages?limit=#{amount}#{"&before=#{before}" if before}#{"&after=#{after}" if after}#{"&around=#{around}" if around}", Authorization: auth ) end |
.pin_message(auth, channel_id, message_id) ⇒ Object
298 299 300 301 302 303 304 305 306 307 |
# File 'lib/mij-discord/core/api/channel.rb', line 298 def (auth, channel_id, ) MijDiscord::Core::API.request( :channels_cid_pins_mid, channel_id, :put, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/pins/#{message_id}", nil, Authorization: auth ) end |
.pinned_messages(auth, channel_id) ⇒ Object
Get a list of pinned messages in a channel discordapp.com/developers/docs/resources/channel#get-pinned-messages
286 287 288 289 290 291 292 293 294 |
# File 'lib/mij-discord/core/api/channel.rb', line 286 def (auth, channel_id) MijDiscord::Core::API.request( :channels_cid_pins, channel_id, :get, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/pins", Authorization: auth ) end |
.remove_group_user(auth, group_channel_id, user_id) ⇒ Object
Remove a user from a group channel.
367 368 369 370 371 372 373 374 375 376 |
# File 'lib/mij-discord/core/api/channel.rb', line 367 def remove_group_user(auth, group_channel_id, user_id) MijDiscord::Core::API.request( :channels_cid_recipients_uid, nil, :delete, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{group_channel_id}/recipients/#{user_id}", Authorization: auth, content_type: :json ) end |
.resolve(auth, channel_id) ⇒ Object
Get a channel’s data discordapp.com/developers/docs/resources/channel#get-channel
7 8 9 10 11 12 13 14 15 |
# File 'lib/mij-discord/core/api/channel.rb', line 7 def resolve(auth, channel_id) MijDiscord::Core::API.request( :channels_cid, channel_id, :get, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}", Authorization: auth ) end |
.start_typing(auth, channel_id) ⇒ Object
Start typing (needs to be resent every 5 seconds to keep up the typing) discordapp.com/developers/docs/resources/channel#trigger-typing-indicator
273 274 275 276 277 278 279 280 281 282 |
# File 'lib/mij-discord/core/api/channel.rb', line 273 def start_typing(auth, channel_id) MijDiscord::Core::API.request( :channels_cid_typing, channel_id, :post, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/typing", nil, Authorization: auth ) end |
.unpin_message(auth, channel_id, message_id) ⇒ Object
311 312 313 314 315 316 317 318 319 |
# File 'lib/mij-discord/core/api/channel.rb', line 311 def (auth, channel_id, ) MijDiscord::Core::API.request( :channels_cid_pins_mid, channel_id, :delete, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/pins/#{message_id}", Authorization: auth ) end |
.update(auth, channel_id, name, topic, nsfw, parent_id, position, bitrate, user_limit, overwrites, reason = nil) ⇒ Object
Update a channel’s data discordapp.com/developers/docs/resources/channel#modify-channel
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mij-discord/core/api/channel.rb', line 19 def update(auth, channel_id, name, topic, nsfw, parent_id, position, bitrate, user_limit, overwrites, reason = nil) MijDiscord::Core::API.request( :channels_cid, channel_id, :patch, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}", { name: name, topic: topic, nsfw: nsfw, parent_id: parent_id, position: position, bitrate: bitrate, user_limit: user_limit, permission_overwrites: overwrites }.delete_if {|_, v| v.nil? }.to_json, Authorization: auth, content_type: :json, 'X-Audit-Log-Reason': reason ) end |
.update_permission(auth, channel_id, overwrite_id, allow, deny, type, reason = nil) ⇒ Object
Update a channels permission for a role or member discordapp.com/developers/docs/resources/channel#edit-channel-permissions
218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/mij-discord/core/api/channel.rb', line 218 def (auth, channel_id, overwrite_id, allow, deny, type, reason = nil) MijDiscord::Core::API.request( :channels_cid_permissions_oid, channel_id, :put, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/permissions/#{overwrite_id}", { type: type, id: overwrite_id, allow: allow, deny: deny }.to_json, Authorization: auth, content_type: :json, 'X-Audit-Log-Reason': reason ) end |
.upload_file(auth, channel_id, file, caption = nil, tts = false) ⇒ Object
Send a file as a message to a channel discordapp.com/developers/docs/resources/channel#upload-file
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/mij-discord/core/api/channel.rb', line 96 def upload_file(auth, channel_id, file, caption = nil, tts = false) MijDiscord::Core::API.request( :channels_cid_messages_mid, channel_id, :post, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages", { file: file, content: caption, tts: tts }, Authorization: auth ) end |
.webhooks(auth, channel_id) ⇒ Object
Get channel webhooks discordapp.com/developers/docs/resources/webhook#get-channel-webhooks
407 408 409 410 411 412 413 414 415 |
# File 'lib/mij-discord/core/api/channel.rb', line 407 def webhooks(auth, channel_id) MijDiscord::Core::API.request( :channels_cid_webhooks, channel_id, :get, "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/webhooks", Authorization: auth ) end |