Class: Discordrb::Snapshot
- Inherits:
-
Object
- Object
- Discordrb::Snapshot
- Defined in:
- lib/discordrb/data/snapshot.rb
Overview
A partial and immutable copy of a message that has been forwarded.
Instance Attribute Summary collapse
-
#attachments ⇒ Array<Attachment>
readonly
The files attached to the message snapshot.
-
#components ⇒ Array<Component>
readonly
The interaction components associated with the message snapshot.
-
#content ⇒ String
readonly
The text content of the message snapshot.
-
#created_at ⇒ Time
readonly
The time at which the message snapshot was created.
-
#edited_at ⇒ Time?
readonly
The time at which the message snapshot was edited.
-
#embeds ⇒ Array<Embed>
readonly
The embeds attached to the message snapshot.
-
#flags ⇒ Integer
readonly
The flags that have been set on the message snapshot.
-
#mentions ⇒ Array<User>
readonly
The users that were mentioned in the message snapshot.
-
#type ⇒ Integer
readonly
The message type of the message snapshot.
Instance Method Summary collapse
-
#buttons ⇒ Array<Components::Button>
Get the buttons that were used in the message snapshot.
-
#edited? ⇒ true, false
Check whether the message snapshot has been edited.
-
#emojis ⇒ Array<Emoji>
Get the custom emojis that were used in the message snapshot.
-
#emojis? ⇒ true, false
Check whether the message snapshot contains any custom emojis.
-
#role_mentions ⇒ Array<Role>
Get the roles that were mentioned in the message snapshot.
Instance Attribute Details
#attachments ⇒ Array<Attachment> (readonly)
Returns the files attached to the message snapshot.
16 17 18 |
# File 'lib/discordrb/data/snapshot.rb', line 16 def @attachments end |
#components ⇒ Array<Component> (readonly)
Returns the interaction components associated with the message snapshot.
31 32 33 |
# File 'lib/discordrb/data/snapshot.rb', line 31 def components @components end |
#content ⇒ String (readonly)
Returns the text content of the message snapshot.
10 11 12 |
# File 'lib/discordrb/data/snapshot.rb', line 10 def content @content end |
#created_at ⇒ Time (readonly)
Returns the time at which the message snapshot was created.
19 20 21 |
# File 'lib/discordrb/data/snapshot.rb', line 19 def created_at @created_at end |
#edited_at ⇒ Time? (readonly)
Returns the time at which the message snapshot was edited.
22 23 24 |
# File 'lib/discordrb/data/snapshot.rb', line 22 def edited_at @edited_at end |
#embeds ⇒ Array<Embed> (readonly)
Returns the embeds attached to the message snapshot.
13 14 15 |
# File 'lib/discordrb/data/snapshot.rb', line 13 def @embeds end |
#flags ⇒ Integer (readonly)
Returns the flags that have been set on the message snapshot.
25 26 27 |
# File 'lib/discordrb/data/snapshot.rb', line 25 def flags @flags end |
#mentions ⇒ Array<User> (readonly)
Returns the users that were mentioned in the message snapshot.
28 29 30 |
# File 'lib/discordrb/data/snapshot.rb', line 28 def mentions @mentions end |
#type ⇒ Integer (readonly)
Returns the message type of the message snapshot.
7 8 9 |
# File 'lib/discordrb/data/snapshot.rb', line 7 def type @type end |
Instance Method Details
#buttons ⇒ Array<Components::Button>
Get the buttons that were used in the message snapshot.
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/discordrb/data/snapshot.rb', line 83 def = @components.flat_map do |component| case component when Components::Button component when Components::ActionRow component. end end .compact end |
#edited? ⇒ true, false
Check whether the message snapshot has been edited.
50 51 52 |
# File 'lib/discordrb/data/snapshot.rb', line 50 def edited? !@edited_at.nil? end |
#emojis ⇒ Array<Emoji>
Get the custom emojis that were used in the message snapshot.
62 63 64 65 66 |
# File 'lib/discordrb/data/snapshot.rb', line 62 def emojis return [] if @content.nil? || @content.empty? @emojis ||= @bot.parse_mentions(@content).select { |parsed| parsed.is_a?(Emoji) } end |
#emojis? ⇒ true, false
Check whether the message snapshot contains any custom emojis.
56 57 58 |
# File 'lib/discordrb/data/snapshot.rb', line 56 def emojis? emojis.any? end |
#role_mentions ⇒ Array<Role>
this can only resolve roles in servers that the bot has access to via Bot#servers.
Get the roles that were mentioned in the message snapshot.
71 72 73 74 75 76 77 78 79 |
# File 'lib/discordrb/data/snapshot.rb', line 71 def role_mentions return [] if @mention_roles.empty? return @role_mentions if @role_mentions roles = @bot.servers.values.flat_map(&:roles) @role_mentions = @mention_roles.filter_map { |id| roles.find { |r| r.id == id } } end |