Class: DiscordRDA::Emoji

Inherits:
Entity
  • Object
show all
Defined in:
lib/discord_rda/entity/emoji.rb

Overview

Represents a Discord emoji (custom or Unicode).

Instance Attribute Summary

Attributes inherited from Entity

#id

Instance Method Summary collapse

Methods inherited from Entity

#==, attribute, 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 emoji is animated

Returns:

  • (Boolean)

    True if animated



23
24
25
# File 'lib/discord_rda/entity/emoji.rb', line 23

def animated?
  animated
end

#available?Boolean

Check if emoji is available (not blocked by role restrictions)

Returns:

  • (Boolean)

    True if available



41
42
43
# File 'lib/discord_rda/entity/emoji.rb', line 41

def available?
  available
end

#created_atTime?

Get creation time (custom emojis only)

Returns:

  • (Time, nil)

    Creation time



85
86
87
# File 'lib/discord_rda/entity/emoji.rb', line 85

def created_at
  id&.timestamp
end

#custom?Boolean

Check if this is a custom emoji

Returns:

  • (Boolean)

    True if custom emoji



79
80
81
# File 'lib/discord_rda/entity/emoji.rb', line 79

def custom?
  !id.nil?
end

#guild_idSnowflake?

Get the guild ID

Returns:



17
18
19
# File 'lib/discord_rda/entity/emoji.rb', line 17

def guild_id
  @raw_data['guild_id'] ? Snowflake.new(@raw_data['guild_id']) : nil
end

#managed?Boolean

Check if emoji is managed by integration

Returns:

  • (Boolean)

    True if managed



35
36
37
# File 'lib/discord_rda/entity/emoji.rb', line 35

def managed?
  managed
end

#mentionString

Get the emoji mention string

Returns:

  • (String)

    Emoji mention



66
67
68
69
# File 'lib/discord_rda/entity/emoji.rb', line 66

def mention
  prefix = animated? ? 'a' : ''
  "<#{prefix}:#{name}:#{id}>"
end

#require_colons?Boolean

Check if emoji requires colons

Returns:

  • (Boolean)

    True if requires colons



29
30
31
# File 'lib/discord_rda/entity/emoji.rb', line 29

def require_colons?
  require_colons
end

#role_idsArray<Snowflake>

Get role restrictions

Returns:



53
54
55
# File 'lib/discord_rda/entity/emoji.rb', line 53

def role_ids
  (@raw_data['roles'] || []).map { |r| Snowflake.new(r) }
end

#unicode?Boolean

Check if this is a Unicode emoji (no ID)

Returns:

  • (Boolean)

    True if Unicode emoji



73
74
75
# File 'lib/discord_rda/entity/emoji.rb', line 73

def unicode?
  id.nil?
end

#urlString

Get the emoji URL

Returns:

  • (String)

    Emoji URL



59
60
61
62
# File 'lib/discord_rda/entity/emoji.rb', line 59

def url
  ext = animated? ? 'gif' : 'png'
  "https://cdn.discordapp.com/emojis/#{id}.#{ext}"
end

#userUser?

Get the emoji creator

Returns:

  • (User, nil)

    Creator



47
48
49
# File 'lib/discord_rda/entity/emoji.rb', line 47

def user
  @user ||= User.new(@raw_data['user']) if @raw_data['user']
end