Class: Discordrb::Snapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/data/snapshot.rb

Overview

A partial and immutable copy of a message that has been forwarded.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attachmentsArray<Attachment> (readonly)

Returns the files attached to the message snapshot.

Returns:

  • (Array<Attachment>)

    the files attached to the message snapshot.



16
17
18
# File 'lib/discordrb/data/snapshot.rb', line 16

def attachments
  @attachments
end

#componentsArray<Component> (readonly)

Returns the interaction components associated with the message snapshot.

Returns:

  • (Array<Component>)

    the interaction components associated with the message snapshot.



31
32
33
# File 'lib/discordrb/data/snapshot.rb', line 31

def components
  @components
end

#contentString (readonly)

Returns the text content of the message snapshot.

Returns:

  • (String)

    the text content of the message snapshot.



10
11
12
# File 'lib/discordrb/data/snapshot.rb', line 10

def content
  @content
end

#created_atTime (readonly)

Returns the time at which the message snapshot was created.

Returns:

  • (Time)

    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_atTime? (readonly)

Returns the time at which the message snapshot was edited.

Returns:

  • (Time, nil)

    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

#embedsArray<Embed> (readonly)

Returns the embeds attached to the message snapshot.

Returns:

  • (Array<Embed>)

    the embeds attached to the message snapshot.



13
14
15
# File 'lib/discordrb/data/snapshot.rb', line 13

def embeds
  @embeds
end

#flagsInteger (readonly)

Returns the flags that have been set on the message snapshot.

Returns:

  • (Integer)

    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

#mentionsArray<User> (readonly)

Returns the users that were mentioned in the message snapshot.

Returns:

  • (Array<User>)

    the users that were mentioned in the message snapshot.



28
29
30
# File 'lib/discordrb/data/snapshot.rb', line 28

def mentions
  @mentions
end

#typeInteger (readonly)

Returns the message type of the message snapshot.

Returns:

  • (Integer)

    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

#buttonsArray<Components::Button>

Get the buttons that were used in the message snapshot.

Returns:



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/discordrb/data/snapshot.rb', line 83

def buttons
  buttons = @components.flat_map do |component|
    case component
    when Components::Button
      component
    when Components::ActionRow
      component.buttons
    end
  end

  buttons.compact
end

#edited?true, false

Check whether the message snapshot has been edited.

Returns:

  • (true, false)

    whether the snapshot was edited or not.



50
51
52
# File 'lib/discordrb/data/snapshot.rb', line 50

def edited?
  !@edited_at.nil?
end

#emojisArray<Emoji>

Get the custom emojis that were used in the message snapshot.

Returns:

  • (Array<Emoji>)

    the emojis 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.

Returns:

  • (true, false)

    whether or not any emoji were used in the snapshot.



56
57
58
# File 'lib/discordrb/data/snapshot.rb', line 56

def emojis?
  emojis.any?
end

#role_mentionsArray<Role>

Note:

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.

Returns:

  • (Array<Role>)

    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