Class: DiscordRDA::Sticker

Inherits:
Entity
  • Object
show all
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

#id

Instance Method Summary collapse

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

Returns:

  • (Boolean)

    True if animated



266
267
268
# File 'lib/discord_rda/entity/support.rb', line 266

def animated?
  format_type == 2 || format_type == 4
end

#creatorUser?

Get creator

Returns:

  • (User, nil)

    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

#formatSymbol

Get format type name

Returns:

  • (Symbol)

    Format type



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

Returns:

  • (Boolean)

    True if guild



254
255
256
# File 'lib/discord_rda/entity/support.rb', line 254

def guild?
  type == 2
end

#guild_idSnowflake?

Get guild ID

Returns:



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

Returns:

  • (Boolean)

    True if standard



248
249
250
# File 'lib/discord_rda/entity/support.rb', line 248

def standard?
  type == 1
end

#urlString

Get sticker URL

Returns:

  • (String)

    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