Class: Discordrb::Emoji

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

Overview

Server emoji

Instance Attribute Summary collapse

Attributes included from IDObject

#id

Instance Method Summary collapse

Methods included from IDObject

#creation_time, synthesise

Instance Attribute Details

#animated ⇒ true, false (readonly) Also known as: animated?

Returns if the emoji is animated.

Returns:

  • (true, false) —

    if the emoji is animated



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

def animated
  @animated
end

#available ⇒ Boolean? (readonly) Also known as: available?

Returns if this emoji is currently usable, or nil if the emoji's server is unknown.

Returns:

  • (Boolean, nil) —

    if this emoji is currently usable, or nil if the emoji's server is unknown



29
30
31
# File 'lib/discordrb/data/emoji.rb', line 29

def available
  @available
end

#creator ⇒ User? (readonly)

Returns the user who uploaded this emoji, or nil if the emoji's server is unknown.

Returns:

  • (User, nil) —

    the user who uploaded this emoji, or nil if the emoji's server is unknown



18
19
20
# File 'lib/discordrb/data/emoji.rb', line 18

def creator
  @creator
end

#managed ⇒ Boolean? (readonly) Also known as: managed?

Returns whether this emoji is managed by an integration, or nil if the emoji's server is unknown.

Returns:

  • (Boolean, nil) —

    whether this emoji is managed by an integration, or nil if the emoji's server is unknown



25
26
27
# File 'lib/discordrb/data/emoji.rb', line 25

def managed
  @managed
end

#name ⇒ String (readonly)

Returns the emoji name.

Returns:



9
10
11
# File 'lib/discordrb/data/emoji.rb', line 9

def name
  @name
end

#requires_colons ⇒ Boolean? (readonly) Also known as: requires_colons?

Returns if the emoji requires colons to be used, or nil if the emoji's server is unknown.

Returns:

  • (Boolean, nil) —

    if the emoji requires colons to be used, or nil if the emoji's server is unknown



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

def requires_colons
  @requires_colons
end

#roles ⇒ Array<Role>? (readonly)

Returns roles this emoji is active for, or nil if the emoji's server is unknown.

Returns:

  • (Array<Role>, nil) —

    roles this emoji is active for, or nil if the emoji's server is unknown



15
16
17
# File 'lib/discordrb/data/emoji.rb', line 15

def roles
  @roles
end

#server ⇒ Server? (readonly)

Returns the server of this emoji.

Returns:

  • (Server, nil) —

    the server of this emoji



12
13
14
# File 'lib/discordrb/data/emoji.rb', line 12

def server
  @server
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

ID or name based comparison



54
55
56
57
58
59
# File 'lib/discordrb/data/emoji.rb', line 54

def ==(other)
  return false unless other.is_a? Emoji
  return Discordrb.id_compare?(@id, other) if @id

  name == other.name
end

#icon_url ⇒ String

Returns the icon URL of the emoji.

Returns:

  • (String) —

    the icon URL of the emoji



81
82
83
# File 'lib/discordrb/data/emoji.rb', line 81

def icon_url
  API.emoji_icon_url(id)
end

#inspect ⇒ Object

The inspect method is overwritten to give more useful output



86
87
88
# File 'lib/discordrb/data/emoji.rb', line 86

def inspect
  "<Emoji name=#{name.inspect} id=#{id.inspect} animated=#{animated}>"
end

#mention ⇒ String Also known as: use, to_s

Returns the layout to mention it (or have it used) in a message.

Returns:

  • (String) —

    the layout to mention it (or have it used) in a message



64
65
66
67
68
# File 'lib/discordrb/data/emoji.rb', line 64

def mention
  return name if id.nil?

  "<#{'a' if animated}:#{name}:#{id}>"
end

#to_h ⇒ Hash

Converts this Emoji into a hash that can be sent back to Discord in other endpoints.

Returns:

  • (Hash) —

    A hash representation of this emoji.



92
93
94
# File 'lib/discordrb/data/emoji.rb', line 92

def to_h
  id.nil? ? { name: name } : { id: id }
end

#to_reaction ⇒ String

Returns the layout to use this emoji in a reaction.

Returns:

  • (String) —

    the layout to use this emoji in a reaction



74
75
76
77
78
# File 'lib/discordrb/data/emoji.rb', line 74

def to_reaction
  return name if id.nil?

  "#{name}:#{id}"
end