Class: DiscordRDA::Sticker
- Defined in:
- lib/discord_rda/entity/support.rb
Overview
Represents a sticker
Constant Summary collapse
- TYPES =
Sticker types
{ standard: 1, guild: 2 }.freeze
- FORMATS =
Sticker formats
{ png: 1, apng: 2, lottie: 3, gif: 4 }.freeze
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#animated? ⇒ Boolean
Check if animated.
-
#creator ⇒ User?
Get creator.
-
#format ⇒ Symbol
Get format type name.
-
#guild? ⇒ Boolean
Check if guild sticker.
-
#guild_id ⇒ Snowflake?
Get guild ID.
-
#standard? ⇒ Boolean
Check if standard sticker.
-
#url ⇒ String
Get sticker URL.
Methods inherited from Entity
#==, attribute, #created_at, from_hash, #hash, #initialize, #inspect, #to_h, #to_json
Constructor Details
This class inherits a constructor from DiscordRDA::Entity
Instance Method Details
#animated? ⇒ Boolean
Check if animated
266 267 268 |
# File 'lib/discord_rda/entity/support.rb', line 266 def animated? format_type == 2 || format_type == 4 end |
#creator ⇒ User?
Get creator
290 291 292 |
# File 'lib/discord_rda/entity/support.rb', line 290 def creator @user ||= User.new(@raw_data['user']) if @raw_data['user'] end |
#format ⇒ Symbol
Get format type name
260 261 262 |
# File 'lib/discord_rda/entity/support.rb', line 260 def format FORMATS.key(format_type) || :unknown end |
#guild? ⇒ Boolean
Check if guild sticker
254 255 256 |
# File 'lib/discord_rda/entity/support.rb', line 254 def guild? type == 2 end |
#guild_id ⇒ Snowflake?
Get guild ID
284 285 286 |
# File 'lib/discord_rda/entity/support.rb', line 284 def guild_id @raw_data['guild_id'] ? Snowflake.new(@raw_data['guild_id']) : nil end |
#standard? ⇒ Boolean
Check if standard sticker
248 249 250 |
# File 'lib/discord_rda/entity/support.rb', line 248 def standard? type == 1 end |
#url ⇒ String
Get sticker URL
272 273 274 275 276 277 278 279 280 |
# File 'lib/discord_rda/entity/support.rb', line 272 def url format_ext = { 1 => 'png', 2 => 'png', 3 => 'json', 4 => 'gif' }[format_type] || 'png' if guild? "https://cdn.discordapp.com/stickers/#{id}.#{format_ext}" else "https://cdn.discordapp.com/stickers/#{id}.#{format_ext}" end end |