Class: Discordrb::Attachment

Inherits:
Object
  • Object
show all
Includes:
IDObject
Defined in:
lib/discordrb/data/attachment.rb

Overview

An attachment to a message

Constant Summary collapse

FLAGS =

Mapping of attachment flags.

{
  clip: 1 << 0,
  thumbnail: 1 << 1,
  spoiler: 1 << 3,
  animated: 1 << 5
}.freeze

Instance Attribute Summary collapse

Attributes included from IDObject

#id

Instance Method Summary collapse

Methods included from IDObject

#==, #creation_time, synthesise

Instance Attribute Details

#clip_applicationApplication? (readonly)

Returns the application that was recognized in the clipped stream.

Returns:

  • (Application, nil)

    the application that was recognized in the clipped stream.



61
62
63
# File 'lib/discordrb/data/attachment.rb', line 61

def clip_application
  @clip_application
end

#clip_creation_timeTime? (readonly)

Returns the time at when the clip was created, if applicable.

Returns:

  • (Time, nil)

    the time at when the clip was created, if applicable.



67
68
69
# File 'lib/discordrb/data/attachment.rb', line 67

def clip_creation_time
  @clip_creation_time
end

#clip_participantsArray<User> (readonly)

Returns the users who were in the clipped stream.

Returns:

  • (Array<User>)

    the users who were in the clipped stream.



64
65
66
# File 'lib/discordrb/data/attachment.rb', line 64

def clip_participants
  @clip_participants
end

#content_typeString? (readonly)

Returns the attachment's media type.

Returns:

  • (String, nil)

    the attachment's media type.



39
40
41
# File 'lib/discordrb/data/attachment.rb', line 39

def content_type
  @content_type
end

#descriptionString? (readonly)

Returns the attachment's description.

Returns:

  • (String, nil)

    the attachment's description.



36
37
38
# File 'lib/discordrb/data/attachment.rb', line 36

def description
  @description
end

#duration_secondsFloat? (readonly)

Returns the duration of the voice message in seconds.

Returns:

  • (Float, nil)

    the duration of the voice message in seconds.



46
47
48
# File 'lib/discordrb/data/attachment.rb', line 46

def duration_seconds
  @duration_seconds
end

#ephemeraltrue, false (readonly) Also known as: ephemeral?

Returns whether this attachment is ephemeral.

Returns:

  • (true, false)

    whether this attachment is ephemeral.



42
43
44
# File 'lib/discordrb/data/attachment.rb', line 42

def ephemeral
  @ephemeral
end

#filenameString (readonly)

Returns the attachment's filename.

Returns:

  • (String)

    the attachment's filename.



24
25
26
# File 'lib/discordrb/data/attachment.rb', line 24

def filename
  @filename
end

#flagsInteger (readonly)

Returns the flags set on this attachment combined as a bitfield.

Returns:

  • (Integer)

    the flags set on this attachment combined as a bitfield.



52
53
54
# File 'lib/discordrb/data/attachment.rb', line 52

def flags
  @flags
end

#heightInteger? (readonly)

Returns the height of an image file, in pixels, or nil if the file is not an image.

Returns:

  • (Integer, nil)

    the height of an image file, in pixels, or nil if the file is not an image.



33
34
35
# File 'lib/discordrb/data/attachment.rb', line 33

def height
  @height
end

#placeholderString? (readonly)

Returns the thumbhash of the attachment, if applicable.

Returns:

  • (String, nil)

    the thumbhash of the attachment, if applicable.



55
56
57
# File 'lib/discordrb/data/attachment.rb', line 55

def placeholder
  @placeholder
end

#placeholder_versionInteger? (readonly)

Returns the version of the attachment's thumbhash, if applicable.

Returns:

  • (Integer, nil)

    the version of the attachment's thumbhash, if applicable.



58
59
60
# File 'lib/discordrb/data/attachment.rb', line 58

def placeholder_version
  @placeholder_version
end

#proxy_urlString (readonly)

Returns the attachment's proxy URL - I'm not sure what exactly this does, but I think it has something to do with CDNs.

Returns:

  • (String)

    the attachment's proxy URL - I'm not sure what exactly this does, but I think it has something to do with CDNs.



21
22
23
# File 'lib/discordrb/data/attachment.rb', line 21

def proxy_url
  @proxy_url
end

#sizeInteger (readonly)

Returns the attachment's file size in bytes.

Returns:

  • (Integer)

    the attachment's file size in bytes.



27
28
29
# File 'lib/discordrb/data/attachment.rb', line 27

def size
  @size
end

#urlString (readonly)

Returns the CDN URL this attachment can be downloaded at.

Returns:

  • (String)

    the CDN URL this attachment can be downloaded at.



17
18
19
# File 'lib/discordrb/data/attachment.rb', line 17

def url
  @url
end

#waveformString? (readonly)

Returns the base64 encoded bytearray representing a sampled waveform for a voice message.

Returns:

  • (String, nil)

    the base64 encoded bytearray representing a sampled waveform for a voice message.



49
50
51
# File 'lib/discordrb/data/attachment.rb', line 49

def waveform
  @waveform
end

#widthInteger? (readonly)

Returns the width of an image file, in pixels, or nil if the file is not an image.

Returns:

  • (Integer, nil)

    the width of an image file, in pixels, or nil if the file is not an image.



30
31
32
# File 'lib/discordrb/data/attachment.rb', line 30

def width
  @width
end

Instance Method Details

#animated?true, false

Returns whether or not the attachment is considered to be an animated image.

Returns:

  • (true, false)

    whether or not the attachment is considered to be an animated image.



127
128
129
# File 'lib/discordrb/data/attachment.rb', line 127

FLAGS.each do |name, value|
  define_method("#{name}?") { @flags.anybits?(value) } if name != :spoiler
end

#clip?true, false

Returns whether or not the attachment is a clip from a stream.

Returns:

  • (true, false)

    whether or not the attachment is a clip from a stream.



127
128
129
# File 'lib/discordrb/data/attachment.rb', line 127

FLAGS.each do |name, value|
  define_method("#{name}?") { @flags.anybits?(value) } if name != :spoiler
end

#image?true, false

Returns whether this file is an image file.

Returns:

  • (true, false)

    whether this file is an image file.



102
103
104
# File 'lib/discordrb/data/attachment.rb', line 102

def image?
  !(@width.nil? || @height.nil?)
end

#messageMessage?

Returns the message this attachment object belongs to.

Returns:

  • (Message, nil)

    the message this attachment object belongs to.



112
113
114
# File 'lib/discordrb/data/attachment.rb', line 112

def message
  @message unless @message.is_a?(Snapshot)
end

#snapshotSnapshot?

Returns the message snapshot this attachment object belongs to.

Returns:

  • (Snapshot, nil)

    the message snapshot this attachment object belongs to.



117
118
119
# File 'lib/discordrb/data/attachment.rb', line 117

def snapshot
  @message unless @message.is_a?(Message)
end

#spoiler?true, false

Returns whether this file is tagged as a spoiler.

Returns:

  • (true, false)

    whether this file is tagged as a spoiler.



107
108
109
# File 'lib/discordrb/data/attachment.rb', line 107

def spoiler?
  @filename.start_with?('SPOILER_') || @flags.anybits?(FLAGS[:spoiler])
end

#thumbnail?true, false

Returns whether or not the attachment is the thumbnail of a thread in a media channel.

Returns:

  • (true, false)

    whether or not the attachment is the thumbnail of a thread in a media channel.



127
128
129
# File 'lib/discordrb/data/attachment.rb', line 127

FLAGS.each do |name, value|
  define_method("#{name}?") { @flags.anybits?(value) } if name != :spoiler
end