Class: OnyxCord::Message
- Inherits:
-
Object
- Object
- OnyxCord::Message
- Includes:
- IDObject
- Defined in:
- lib/onyxcord/models/message.rb
Overview
A message on Discord that was sent to a text channel
Constant Summary collapse
- FLAGS =
Map of message flags.
{ crossposted: 1 << 0, crosspost: 1 << 1, suppress_embeds: 1 << 2, source_message_deleted: 1 << 3, urgent: 1 << 4, thread: 1 << 5, ephemeral: 1 << 6, loading: 1 << 7, failed_to_mention_roles: 1 << 8, suppress_notifications: 1 << 12, voice_message: 1 << 13, snapshot: 1 << 14, uikit_components: 1 << 15, is_components_v2: OnyxCord::MessageComponents::IS_COMPONENTS_V2, components_v2: OnyxCord::MessageComponents::IS_COMPONENTS_V2 }.freeze
- TYPES =
Map of message types.
{ default: 0, recipient_add: 1, recipient_remove: 2, call: 3, channel_name_change: 4, channel_icon_change: 5, channel_pinned_message: 6, server_member_join: 7, server_boost: 8, server_boost_tier_one: 9, server_boost_tier_two: 10, server_boost_tier_three: 11, channel_follow_add: 12, server_discovery_disqualified: 14, server_discovery_requalified: 15, server_discovery_grace_period_initial_warning: 16, server_discovery_grace_period_final_warning: 17, thread_created: 18, reply: 19, chat_input_command: 20, thread_starter_message: 21, server_invite_reminder: 22, context_menu_command: 23, automod_action: 24, role_subscription_purchase: 25, interaction_premium_upsell: 26, stage_start: 27, stage_end: 28, stage_speaker: 29, stage_raise_hand: 30, stage_topic: 31, server_application_premium_subscription: 32, server_incident_alert_mode_enabled: 36, server_incident_alert_mode_disabled: 37, server_incident_report_raid: 38, server_incident_report_false_alarm: 39, purchase_notification: 44, poll_result: 46, changelog: 47, server_join_request_accepted: 52, server_join_request_rejected: 53, server_join_request_withdrawn: 54, report_to_mod_deleted_message: 58, report_to_mod_timeout_user: 59, report_to_mod_kick_user: 60, report_to_mod_ban_user: 61, report_to_mod_closed_report: 62, server_emoji_added: 63 }.freeze
Instance Attribute Summary collapse
-
#activity ⇒ MessageActivity?
readonly
The rich-presence activity that prompted this message.
-
#application_id ⇒ Integer?
readonly
The ID of the application associated with this message.
-
#attachments ⇒ Array<Attachment>
readonly
The files attached to this message.
-
#call ⇒ Call?
readonly
The call in a private channel that prompted this message.
-
#channel ⇒ Channel
readonly
The channel in which this message was sent.
-
#components ⇒ Array<Component>
readonly
Interaction components for this message.
-
#content ⇒ String
(also: #text, #to_s)
readonly
The content of this message.
-
#edited ⇒ true, false
(also: #edited?)
readonly
Whether the message was edited or not.
-
#edited_timestamp ⇒ Time
(also: #edit_timestamp)
readonly
The timestamp at which this message was edited.
-
#embeds ⇒ Array<Embed>
readonly
The embed objects contained in this message.
-
#flags ⇒ Integer
readonly
Flags set on the message.
-
#interaction_metadata ⇒ Interactions::Metadata?
readonly
The metadata about the interaction that prompted this message.
-
#mention_everyone ⇒ true, false
(also: #mention_everyone?, #mentions_everyone?)
readonly
Whether the message mentioned everyone or not.
-
#mentions ⇒ Array<User>
readonly
The users that were mentioned in this message.
-
#nonce ⇒ String
readonly
Used for validating a message was sent.
-
#pinned ⇒ true, false
(also: #pinned?)
readonly
Whether the message is pinned or not.
-
#pinned_at ⇒ Time?
readonly
The time at when this message was pinned.
-
#poll ⇒ Poll?
readonly
The poll that was sent with this message, or
nil. -
#poll_result ⇒ Poll::Result?
(also: #poll_results)
readonly
The finalised results for a poll that prompted this message.
-
#position ⇒ Integer
readonly
A generally increasing integer that can be used to determine this message's position in a thread.
-
#reactions ⇒ Array<Reaction>
readonly
The reaction objects contained in this message.
-
#role_subscription ⇒ RoleSubscriptionData?
readonly
The role subscription purchase or renewal that prompted this message.
-
#snapshots ⇒ Array<Snapshot>
readonly
The message snapshots included in this message.
-
#thread ⇒ Channel?
readonly
The thread that was started from this message, or nil.
-
#tts ⇒ true, false
(also: #tts?)
readonly
Whether the message used Text-To-Speech (TTS) or not.
-
#type ⇒ Integer
readonly
What the type of the message is.
-
#webhook_id ⇒ Integer?
readonly
The webhook ID that sent this message, or
nilif it wasn't sent through a webhook.
Attributes included from IDObject
Instance Method Summary collapse
-
#all_reaction_users(limit: 100) ⇒ Hash<String => Array<User>>
Returns a hash of all reactions to a message as keys and the users that reacted to it as values.
-
#author ⇒ Member, User
(also: #user, #writer)
The user that sent this message.
-
#await(key, attributes = {}, &block) ⇒ Object
deprecated
Deprecated.
Will be changed to blocking behavior in v4.0. Use #await! instead.
-
#await!(attributes = {}, &block) ⇒ Object
Add a blocking Await for a message with the same user and channel.
-
#await_reaction(key, attributes = {}, &block) ⇒ Object
deprecated
Deprecated.
Will be changed to blocking behavior in v4.0. Use #await_reaction! instead.
-
#await_reaction!(attributes = {}, &block) ⇒ Object
Add a blocking Await for a reaction to be added on this message.
- #buttons ⇒ Array<Components::Button>
-
#create_reaction(reaction) ⇒ nil
(also: #react)
Reacts to a message.
-
#crosspost ⇒ Message
Crossposts a message in a news channel.
-
#delete(reason = nil) ⇒ nil
Deletes this message.
-
#delete_all_reactions ⇒ Object
Removes all reactions from this message.
-
#delete_all_reactions_for_emoji(reaction) ⇒ Object
Removes all reactions for a single emoji.
-
#delete_own_reaction(reaction) ⇒ Object
Deletes this client's reaction on this message.
-
#delete_reaction(user, reaction) ⇒ Object
Deletes a reaction made by a user on this message.
-
#edit(new_content, new_embeds = nil, new_components = nil, flags = 0) ⇒ Message
Edits this message to have the specified content instead.
-
#emoji ⇒ Array<Emoji>
(also: #emojis)
The emotes that were used/mentioned in this message.
-
#emoji? ⇒ true, false
(also: #emojis?)
Check if any emoji were used in this message.
-
#forward(channel, must_exist: true, timeout: nil, flags: 0, nonce: nil, enforce_nonce: false) ⇒ Message?
Forward this message to another channel.
-
#from_bot? ⇒ true, false
Whether this message was sent by the current Bot.
-
#inspect ⇒ Object
The inspect method is overwritten to give more useful output.
-
#link ⇒ String
(also: #jump_link)
A URL that a user can use to navigate to this message in the client.
-
#mentions?(target) ⇒ true, false
Check if this message mentions a specific user or role.
-
#my_reactions ⇒ Array<Reaction>
Returns the reactions made by the current bot or user.
-
#pin(reason = nil) ⇒ nil
Pins this message.
-
#reacted_with(reaction, limit: 100, type: :normal) ⇒ Array<User>
Returns the list of users who reacted with a certain reaction.
-
#reactions? ⇒ true, false
Check if any reactions were used in this message.
-
#referenced_message ⇒ Message?
The Message this Message was sent in reply to.
-
#reply(content) ⇒ Message
deprecated
Deprecated.
Please use #respond.
-
#reply!(content, tts: false, embed: nil, attachments: nil, allowed_mentions: {}, mention_user: false, components: nil, flags: 0) ⇒ Message
Responds to this message as an inline reply.
-
#reply? ⇒ true, false
Whether or not this message was sent in reply to another message.
-
#respond(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0) ⇒ Message
Sends a message to this channel.
-
#role_mentions ⇒ Array<Role>
Get the roles that were mentioned in this message.
-
#server ⇒ Server?
The server this message was sent in.
-
#suppress_embeds ⇒ Message
Removes embeds from the message.
-
#timestamps ⇒ Array<TimestampMarkdown>
Get the formatted timestamps contained in the message content.
-
#to_message ⇒ OnyxCord::Message
(also: #message)
to_message -> self or message.
-
#to_reference(type: :reply, must_exist: true) ⇒ Hash
Convert this message to a hash that can be used to reference this message in a forward or a reply.
-
#unpin(reason = nil) ⇒ nil
Unpins this message.
-
#webhook? ⇒ true, false
Whether this message has been sent over a webhook.
Methods included from IDObject
#==, #creation_time, synthesise
Instance Attribute Details
#activity ⇒ MessageActivity? (readonly)
Returns the rich-presence activity that prompted this message.
166 167 168 |
# File 'lib/onyxcord/models/message.rb', line 166 def activity @activity end |
#application_id ⇒ Integer? (readonly)
Returns the ID of the application associated with this message.
163 164 165 |
# File 'lib/onyxcord/models/message.rb', line 163 def application_id @application_id end |
#attachments ⇒ Array<Attachment> (readonly)
Returns the files attached to this message.
97 98 99 |
# File 'lib/onyxcord/models/message.rb', line 97 def @attachments end |
#call ⇒ Call? (readonly)
Returns the call in a private channel that prompted this message.
144 145 146 |
# File 'lib/onyxcord/models/message.rb', line 144 def call @call end |
#channel ⇒ Channel (readonly)
Returns the channel in which this message was sent.
87 88 89 |
# File 'lib/onyxcord/models/message.rb', line 87 def channel @channel end |
#components ⇒ Array<Component> (readonly)
Returns Interaction components for this message.
132 133 134 |
# File 'lib/onyxcord/models/message.rb', line 132 def components @components end |
#content ⇒ String (readonly) Also known as: text, to_s
Returns the content of this message.
82 83 84 |
# File 'lib/onyxcord/models/message.rb', line 82 def content @content end |
#edited ⇒ true, false (readonly) Also known as: edited?
Returns whether the message was edited or not.
113 114 115 |
# File 'lib/onyxcord/models/message.rb', line 113 def edited @edited end |
#edited_timestamp ⇒ Time (readonly) Also known as: edit_timestamp
Returns the timestamp at which this message was edited. nil if the message was never edited.
90 91 92 |
# File 'lib/onyxcord/models/message.rb', line 90 def @edited_timestamp end |
#embeds ⇒ Array<Embed> (readonly)
Returns the embed objects contained in this message.
100 101 102 |
# File 'lib/onyxcord/models/message.rb', line 100 def @embeds end |
#flags ⇒ Integer (readonly)
Returns flags set on the message.
135 136 137 |
# File 'lib/onyxcord/models/message.rb', line 135 def flags @flags end |
#interaction_metadata ⇒ Interactions::Metadata? (readonly)
Returns the metadata about the interaction that prompted this message.
169 170 171 |
# File 'lib/onyxcord/models/message.rb', line 169 def @interaction_metadata end |
#mention_everyone ⇒ true, false (readonly) Also known as: mention_everyone?, mentions_everyone?
Returns whether the message mentioned everyone or not.
117 118 119 |
# File 'lib/onyxcord/models/message.rb', line 117 def mention_everyone @mention_everyone end |
#mentions ⇒ Array<User> (readonly)
Returns the users that were mentioned in this message.
94 95 96 |
# File 'lib/onyxcord/models/message.rb', line 94 def mentions @mentions end |
#nonce ⇒ String (readonly)
Returns used for validating a message was sent.
110 111 112 |
# File 'lib/onyxcord/models/message.rb', line 110 def nonce @nonce end |
#pinned ⇒ true, false (readonly) Also known as: pinned?
Returns whether the message is pinned or not.
122 123 124 |
# File 'lib/onyxcord/models/message.rb', line 122 def pinned @pinned end |
#pinned_at ⇒ Time? (readonly)
Returns the time at when this message was pinned. Only present on messages fetched via Channel#pins.
141 142 143 |
# File 'lib/onyxcord/models/message.rb', line 141 def pinned_at @pinned_at end |
#poll ⇒ Poll? (readonly)
Returns the poll that was sent with this message, or nil.
156 157 158 |
# File 'lib/onyxcord/models/message.rb', line 156 def poll @poll end |
#poll_result ⇒ Poll::Result? (readonly) Also known as: poll_results
Returns the finalised results for a poll that prompted this message.
159 160 161 |
# File 'lib/onyxcord/models/message.rb', line 159 def poll_result @poll_result end |
#position ⇒ Integer (readonly)
Returns a generally increasing integer that can be used to determine this message's position in a thread.
153 154 155 |
# File 'lib/onyxcord/models/message.rb', line 153 def position @position end |
#reactions ⇒ Array<Reaction> (readonly)
Returns the reaction objects contained in this message.
103 104 105 |
# File 'lib/onyxcord/models/message.rb', line 103 def reactions @reactions end |
#role_subscription ⇒ RoleSubscriptionData? (readonly)
Returns the role subscription purchase or renewal that prompted this message.
150 151 152 |
# File 'lib/onyxcord/models/message.rb', line 150 def role_subscription @role_subscription end |
#snapshots ⇒ Array<Snapshot> (readonly)
Returns the message snapshots included in this message.
147 148 149 |
# File 'lib/onyxcord/models/message.rb', line 147 def snapshots @snapshots end |
#thread ⇒ Channel? (readonly)
Returns The thread that was started from this message, or nil.
138 139 140 |
# File 'lib/onyxcord/models/message.rb', line 138 def thread @thread end |
#tts ⇒ true, false (readonly) Also known as: tts?
Returns whether the message used Text-To-Speech (TTS) or not.
106 107 108 |
# File 'lib/onyxcord/models/message.rb', line 106 def tts @tts end |
#type ⇒ Integer (readonly)
Returns what the type of the message is.
126 127 128 |
# File 'lib/onyxcord/models/message.rb', line 126 def type @type end |
#webhook_id ⇒ Integer? (readonly)
Returns the webhook ID that sent this message, or nil if it wasn't sent through a webhook.
129 130 131 |
# File 'lib/onyxcord/models/message.rb', line 129 def webhook_id @webhook_id end |
Instance Method Details
#all_reaction_users(limit: 100) ⇒ Hash<String => Array<User>>
Returns a hash of all reactions to a message as keys and the users that reacted to it as values.
485 486 487 |
# File 'lib/onyxcord/models/message.rb', line 485 def all_reaction_users(limit: 100) @reactions.to_h { |reaction| [reaction.to_s, reacted_with(reaction, limit: limit)] } end |
#author ⇒ Member, User Also known as: user, writer
Returns the user that sent this message. (Will be a OnyxCord::Member most of the time, it should only be a User for old messages when the author has left the server since then).
234 235 236 237 238 239 240 241 242 243 |
# File 'lib/onyxcord/models/message.rb', line 234 def return @author if @author unless @channel.private? @author = @channel.server.member(@author_id) OnyxCord::LOGGER.debug("Member with ID #{@author_id} not cached (possibly left the server).") if @author.nil? end @author ||= @bot.user(@author_id) end |
#await(key, attributes = {}, &block) ⇒ Object
356 357 358 |
# File 'lib/onyxcord/models/message.rb', line 356 def await(key, attributes = {}, &block) @bot.add_await(key, OnyxCord::Events::MessageEvent, { from: @author.id, in: @channel.id }.merge(attributes), &block) end |
#await!(attributes = {}, &block) ⇒ Object
Add a blocking Await for a message with the same user and channel.
362 363 364 |
# File 'lib/onyxcord/models/message.rb', line 362 def await!(attributes = {}, &block) @bot.add_await!(OnyxCord::Events::MessageEvent, { from: @author.id, in: @channel.id }.merge(attributes), &block) end |
#await_reaction(key, attributes = {}, &block) ⇒ Object
Will be changed to blocking behavior in v4.0. Use #await_reaction! instead.
Add an Await for a reaction to be added on this message.
369 370 371 |
# File 'lib/onyxcord/models/message.rb', line 369 def await_reaction(key, attributes = {}, &block) @bot.add_await(key, OnyxCord::Events::ReactionAddEvent, { message: @id }.merge(attributes), &block) end |
#await_reaction!(attributes = {}, &block) ⇒ Object
Add a blocking Await for a reaction to be added on this message.
375 376 377 |
# File 'lib/onyxcord/models/message.rb', line 375 def await_reaction!(attributes = {}, &block) @bot.add_await!(OnyxCord::Events::ReactionAddEvent, { message: @id }.merge(attributes), &block) end |
#buttons ⇒ Array<Components::Button>
544 545 546 547 548 549 550 551 552 553 554 555 556 557 |
# File 'lib/onyxcord/models/message.rb', line 544 def = @components.flat_map do |component| case component when Components::Button component when Components::Section component.accessory if component.accessory.is_a?(Components::Button) when Components::ActionRow, Components::Container component. end end .compact end |
#create_reaction(reaction) ⇒ nil Also known as: react
Reacts to a message.
440 441 442 443 444 |
# File 'lib/onyxcord/models/message.rb', line 440 def create_reaction(reaction) reaction = reaction.to_reaction if reaction.respond_to?(:to_reaction) REST::Channel.create_reaction(@bot.token, @channel.id, @id, reaction) nil end |
#crosspost ⇒ Message
Crossposts a message in a news channel.
348 349 350 351 |
# File 'lib/onyxcord/models/message.rb', line 348 def crosspost response = REST::Channel.(@bot.token, @channel.id, @id) Message.new(OnyxCord::Internal::JSON.parse(response), @bot) end |
#delete(reason = nil) ⇒ nil
Deletes this message.
325 326 327 328 |
# File 'lib/onyxcord/models/message.rb', line 325 def delete(reason = nil) REST::Channel.(@bot.token, @channel.id, @id, reason) nil end |
#delete_all_reactions ⇒ Object
Removes all reactions from this message.
505 506 507 |
# File 'lib/onyxcord/models/message.rb', line 505 def delete_all_reactions REST::Channel.delete_all_reactions(@bot.token, @channel.id, @id) end |
#delete_all_reactions_for_emoji(reaction) ⇒ Object
Removes all reactions for a single emoji.
511 512 513 514 |
# File 'lib/onyxcord/models/message.rb', line 511 def delete_all_reactions_for_emoji(reaction) reaction = reaction.to_reaction if reaction.respond_to?(:to_reaction) REST::Channel.delete_all_emoji_reactions(@bot.token, @channel.id, @id, reaction.to_s) end |
#delete_own_reaction(reaction) ⇒ Object
Deletes this client's reaction on this message.
499 500 501 502 |
# File 'lib/onyxcord/models/message.rb', line 499 def delete_own_reaction(reaction) reaction = reaction.to_reaction if reaction.respond_to?(:to_reaction) REST::Channel.delete_own_reaction(@bot.token, @channel.id, @id, reaction) end |
#delete_reaction(user, reaction) ⇒ Object
Deletes a reaction made by a user on this message.
492 493 494 495 |
# File 'lib/onyxcord/models/message.rb', line 492 def delete_reaction(user, reaction) reaction = reaction.to_reaction if reaction.respond_to?(:to_reaction) REST::Channel.delete_user_reaction(@bot.token, @channel.id, @id, reaction, user.resolve_id) end |
#edit(new_content, new_embeds = nil, new_components = nil, flags = 0) ⇒ Message
Edits this message to have the specified content instead. You can only edit your own messages.
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/onyxcord/models/message.rb', line 306 def edit(new_content, = nil, new_components = nil, flags = 0) = if == OnyxCord::MessagePayload::KEEP else (if .instance_of?(Array) .map { || .respond_to?(:to_hash) ? .to_hash : } else [&.to_hash] end).compact end new_components = new_components.to_a flags = OnyxCord::MessageComponents.apply_v2_flag(flags, new_components) response = REST::Channel.(@bot.token, @channel.id, @id, new_content, :undef, , new_components, flags) Message.new(OnyxCord::Internal::JSON.parse(response), @bot) end |
#emoji ⇒ Array<Emoji> Also known as: emojis
Returns the emotes that were used/mentioned in this message.
390 391 392 393 394 |
# File 'lib/onyxcord/models/message.rb', line 390 def emoji return [] if @content.empty? || @content.nil? @emoji ||= @bot.parse_mentions(@content).select { |mention| mention.is_a?(OnyxCord::Emoji) } end |
#emoji? ⇒ true, false Also known as: emojis?
Check if any emoji were used in this message.
400 401 402 |
# File 'lib/onyxcord/models/message.rb', line 400 def emoji? emoji.any? end |
#forward(channel, must_exist: true, timeout: nil, flags: 0, nonce: nil, enforce_nonce: false) ⇒ Message?
Forward this message to another channel.
597 598 599 600 601 |
# File 'lib/onyxcord/models/message.rb', line 597 def forward(channel, must_exist: true, timeout: nil, flags: 0, nonce: nil, enforce_nonce: false) reference = to_reference(type: :forward, must_exist: must_exist) @bot.channel(channel).(reference: reference, timeout: timeout, flags: flags, nonce: nonce, enforce_nonce: enforce_nonce) end |
#from_bot? ⇒ true, false
Returns whether this message was sent by the current Bot.
380 381 382 |
# File 'lib/onyxcord/models/message.rb', line 380 def from_bot? (@author_id || @author&.id) == @bot.profile.id end |
#inspect ⇒ Object
The inspect method is overwritten to give more useful output
517 518 519 |
# File 'lib/onyxcord/models/message.rb', line 517 def inspect "<Message content=\"#{@content}\" id=#{@id} timestamp=#{creation_time} author=#{@author} channel=#{@channel}>" end |
#link ⇒ String Also known as: jump_link
Returns a URL that a user can use to navigate to this message in the client.
522 523 524 |
# File 'lib/onyxcord/models/message.rb', line 522 def link "https://discord.com/channels/#{server&.id || '@me'}/#{@channel.id}/#{@id}" end |
#mentions?(target) ⇒ true, false
Check if this message mentions a specific user or role.
429 430 431 432 433 434 435 |
# File 'lib/onyxcord/models/message.rb', line 429 def mentions?(target) mentions = (@mentions + role_mentions) mentions << server if @mention_everyone mentions.any?(target.resolve_id) end |
#my_reactions ⇒ Array<Reaction>
Returns the reactions made by the current bot or user.
414 415 416 |
# File 'lib/onyxcord/models/message.rb', line 414 def my_reactions @reactions.select(&:me) end |
#pin(reason = nil) ⇒ nil
Pins this message
332 333 334 335 336 |
# File 'lib/onyxcord/models/message.rb', line 332 def pin(reason = nil) REST::Channel.(@bot.token, @channel.id, @id, reason) @pinned = true nil end |
#reacted_with(reaction, limit: 100, type: :normal) ⇒ Array<User>
Returns the list of users who reacted with a certain reaction.
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'lib/onyxcord/models/message.rb', line 455 def reacted_with(reaction, limit: 100, type: :normal) reaction = reaction.to_reaction if reaction.respond_to?(:to_reaction) reaction = reaction.to_s if reaction.respond_to?(:to_s) type = Reaction::TYPES[type] || type get_reactions = proc do |fetch_limit, after_id = nil| resp = REST::Channel.get_reactions(@bot.token, @channel.id, @id, reaction, nil, after_id, fetch_limit, type) OnyxCord::Internal::JSON.parse(resp).map { |d| User.new(d, @bot) } end # Can be done without pagination return get_reactions.call(limit) if limit && limit <= 100 paginator = Paginator.new(limit, :down) do |last_page| if last_page && last_page.count < 100 [] else get_reactions.call(100, last_page&.last&.id) end end paginator.to_a end |
#reactions? ⇒ true, false
Check if any reactions were used in this message.
408 409 410 |
# File 'lib/onyxcord/models/message.rb', line 408 def reactions? !@reactions.empty? end |
#referenced_message ⇒ Message?
Returns the Message this Message was sent in reply to.
535 536 537 538 539 540 541 |
# File 'lib/onyxcord/models/message.rb', line 535 def return @referenced_message if @referenced_message return nil unless @message_reference referenced_channel = @bot.channel(@message_reference['channel_id']) @referenced_message = referenced_channel&.(@message_reference['message_id']) end |
#reply(content) ⇒ Message
Please use #respond.
Replies to this message with the specified content.
272 273 274 |
# File 'lib/onyxcord/models/message.rb', line 272 def reply(content) @channel.(content) end |
#reply!(content, tts: false, embed: nil, attachments: nil, allowed_mentions: {}, mention_user: false, components: nil, flags: 0) ⇒ Message
Responds to this message as an inline reply.
286 287 288 289 290 291 292 |
# File 'lib/onyxcord/models/message.rb', line 286 def reply!(content, tts: false, embed: nil, attachments: nil, allowed_mentions: {}, mention_user: false, components: nil, flags: 0) allowed_mentions = { parse: [] } if allowed_mentions == false allowed_mentions = allowed_mentions.to_hash.transform_keys(&:to_sym) allowed_mentions[:replied_user] = mention_user respond(content, tts, , , allowed_mentions, self, components, flags) end |
#reply? ⇒ true, false
Whether or not this message was sent in reply to another message
530 531 532 |
# File 'lib/onyxcord/models/message.rb', line 530 def reply? !@referenced_message.nil? end |
#respond(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0) ⇒ Message
Sends a message to this channel.
295 296 297 |
# File 'lib/onyxcord/models/message.rb', line 295 def respond(content, tts = false, = nil, = nil, allowed_mentions = nil, = nil, components = nil, flags = 0) @channel.(content, tts, , , allowed_mentions, , components, flags) end |
#role_mentions ⇒ Array<Role>
Get the roles that were mentioned in this message.
261 262 263 264 265 |
# File 'lib/onyxcord/models/message.rb', line 261 def role_mentions return [] if @channel.private? || @mention_roles.empty? @role_mentions ||= @mention_roles.map { |id| server.role(id) } end |
#server ⇒ Server?
Returns the server this message was sent in. If this message was sent in a PM channel, it will be nil.
251 252 253 254 255 |
# File 'lib/onyxcord/models/message.rb', line 251 def server return if @channel.private? @server ||= @channel.server end |
#suppress_embeds ⇒ Message
Removes embeds from the message
420 421 422 423 424 |
# File 'lib/onyxcord/models/message.rb', line 420 def flags = @flags | (1 << 2) response = REST::Channel.(@bot.token, @channel.id, @id, :undef, :undef, :undef, :undef, flags) Message.new(OnyxCord::Internal::JSON.parse(response), @bot) end |
#timestamps ⇒ Array<TimestampMarkdown>
Get the formatted timestamps contained in the message content.
605 606 607 608 609 610 611 612 613 614 615 616 617 618 |
# File 'lib/onyxcord/models/message.rb', line 605 def return (@timestamps || []) if @timestamps || !@content || @content.empty? @timestamps = [] @content.scan(/<t:(-?\d{1,13})(?::(t|T|d|D|f|F|s|S|R))?>/) do |time, style| # If it's not between these values, Discord won't show it, so don't bother. if (time = time.to_i).between?(-8_640_000_000_000, 8_640_000_000_000) @timestamps << TimestampMarkdown.new(Time.at(time), style) end end @timestamps end |
#to_message ⇒ OnyxCord::Message Also known as: message
to_message -> self or message
561 562 563 |
# File 'lib/onyxcord/models/message.rb', line 561 def self end |
#to_reference(type: :reply, must_exist: true) ⇒ Hash
Convert this message to a hash that can be used to reference this message in a forward or a reply.
583 584 585 586 587 |
# File 'lib/onyxcord/models/message.rb', line 583 def to_reference(type: :reply, must_exist: true) type = (type == :reply ? 0 : 1) if type.is_a?(Symbol) { type: type, message_id: @id, channel_id: @channel.id, fail_if_not_exists: must_exist } end |
#unpin(reason = nil) ⇒ nil
Unpins this message
340 341 342 343 344 |
# File 'lib/onyxcord/models/message.rb', line 340 def unpin(reason = nil) REST::Channel.(@bot.token, @channel.id, @id, reason) @pinned = false nil end |
#webhook? ⇒ true, false
Returns whether this message has been sent over a webhook.
385 386 387 |
# File 'lib/onyxcord/models/message.rb', line 385 def webhook? !@webhook_id.nil? end |