Class: Discordrb::Attachment
- Inherits:
-
Object
- Object
- Discordrb::Attachment
- 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
-
#clip_application ⇒ Application?
readonly
The application that was recognized in the clipped stream.
-
#clip_creation_time ⇒ Time?
readonly
The time at when the clip was created, if applicable.
-
#clip_participants ⇒ Array<User>
readonly
The users who were in the clipped stream.
-
#content_type ⇒ String?
readonly
The attachment's media type.
-
#description ⇒ String?
readonly
The attachment's description.
-
#duration_seconds ⇒ Float?
readonly
The duration of the voice message in seconds.
-
#ephemeral ⇒ true, false
(also: #ephemeral?)
readonly
Whether this attachment is ephemeral.
-
#filename ⇒ String
readonly
The attachment's filename.
-
#flags ⇒ Integer
readonly
The flags set on this attachment combined as a bitfield.
-
#height ⇒ Integer?
readonly
The height of an image file, in pixels, or
nilif the file is not an image. -
#placeholder ⇒ String?
readonly
The thumbhash of the attachment, if applicable.
-
#placeholder_version ⇒ Integer?
readonly
The version of the attachment's thumbhash, if applicable.
-
#proxy_url ⇒ String
readonly
The attachment's proxy URL - I'm not sure what exactly this does, but I think it has something to do with CDNs.
-
#size ⇒ Integer
readonly
The attachment's file size in bytes.
-
#url ⇒ String
readonly
The CDN URL this attachment can be downloaded at.
-
#waveform ⇒ String?
readonly
The base64 encoded bytearray representing a sampled waveform for a voice message.
-
#width ⇒ Integer?
readonly
The width of an image file, in pixels, or
nilif the file is not an image.
Attributes included from IDObject
Instance Method Summary collapse
-
#animated? ⇒ true, false
Whether or not the attachment is considered to be an animated image.
-
#clip? ⇒ true, false
Whether or not the attachment is a clip from a stream.
-
#image? ⇒ true, false
Whether this file is an image file.
-
#message ⇒ Message?
The message this attachment object belongs to.
-
#snapshot ⇒ Snapshot?
The message snapshot this attachment object belongs to.
-
#spoiler? ⇒ true, false
Whether this file is tagged as a spoiler.
-
#thumbnail? ⇒ true, false
Whether or not the attachment is the thumbnail of a thread in a media channel.
Methods included from IDObject
#==, #creation_time, synthesise
Instance Attribute Details
#clip_application ⇒ Application? (readonly)
Returns 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_time ⇒ Time? (readonly)
Returns 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_participants ⇒ Array<User> (readonly)
Returns 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_type ⇒ String? (readonly)
Returns the attachment's media type.
39 40 41 |
# File 'lib/discordrb/data/attachment.rb', line 39 def content_type @content_type end |
#description ⇒ String? (readonly)
Returns the attachment's description.
36 37 38 |
# File 'lib/discordrb/data/attachment.rb', line 36 def description @description end |
#duration_seconds ⇒ Float? (readonly)
Returns 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 |
#ephemeral ⇒ true, false (readonly) Also known as: ephemeral?
Returns whether this attachment is ephemeral.
42 43 44 |
# File 'lib/discordrb/data/attachment.rb', line 42 def ephemeral @ephemeral end |
#filename ⇒ String (readonly)
Returns the attachment's filename.
24 25 26 |
# File 'lib/discordrb/data/attachment.rb', line 24 def filename @filename end |
#flags ⇒ Integer (readonly)
Returns 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 |
#height ⇒ Integer? (readonly)
Returns 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 |
#placeholder ⇒ String? (readonly)
Returns the thumbhash of the attachment, if applicable.
55 56 57 |
# File 'lib/discordrb/data/attachment.rb', line 55 def placeholder @placeholder end |
#placeholder_version ⇒ Integer? (readonly)
Returns 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_url ⇒ String (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.
21 22 23 |
# File 'lib/discordrb/data/attachment.rb', line 21 def proxy_url @proxy_url end |
#size ⇒ Integer (readonly)
Returns the attachment's file size in bytes.
27 28 29 |
# File 'lib/discordrb/data/attachment.rb', line 27 def size @size end |
#url ⇒ String (readonly)
Returns the CDN URL this attachment can be downloaded at.
17 18 19 |
# File 'lib/discordrb/data/attachment.rb', line 17 def url @url end |
#waveform ⇒ String? (readonly)
Returns 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 |
#width ⇒ Integer? (readonly)
Returns 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.
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.
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.
102 103 104 |
# File 'lib/discordrb/data/attachment.rb', line 102 def image? !(@width.nil? || @height.nil?) end |
#message ⇒ Message?
Returns the message this attachment object belongs to.
112 113 114 |
# File 'lib/discordrb/data/attachment.rb', line 112 def @message unless @message.is_a?(Snapshot) end |
#snapshot ⇒ Snapshot?
Returns 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.
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.
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 |