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

Constructor Details

#initialize(data, bot, server) ⇒ Emoji

Returns a new instance of Emoji.


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/discordrb/data/emoji.rb', line 21

def initialize(data, bot, server)
  @bot = bot
  @roles = nil

  @name = data['name']
  @server = server
  @id = data['id'].nil? ? nil : data['id'].to_i
  @animated = data['animated']

  process_roles(data['roles']) if server
end

Instance Attribute Details

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

Returns if the emoji is animated.

Returns:

  • (true, false)

    if the emoji is animated


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

def animated
  @animated
end

#nameString (readonly)

Returns the emoji name.

Returns:


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

def name
  @name
end

#rolesArray<Role> (readonly)

Returns roles this emoji is active for.

Returns:

  • (Array<Role>)

    roles this emoji is active for


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

def roles
  @roles
end

#serverServer (readonly)

Returns the server of this emoji.

Returns:

  • (Server)

    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


34
35
36
37
38
39
# File 'lib/discordrb/data/emoji.rb', line 34

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

  name == other.name
end

#icon_urlString

Returns the icon URL of the emoji.

Returns:

  • (String)

    the icon URL of the emoji


59
60
61
# File 'lib/discordrb/data/emoji.rb', line 59

def icon_url
  API.emoji_icon_url(id)
end

#inspectObject

The inspect method is overwritten to give more useful output


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

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

#mentionString 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


44
45
46
# File 'lib/discordrb/data/emoji.rb', line 44

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

#to_reactionString

Returns the layout to use this emoji in a reaction.

Returns:

  • (String)

    the layout to use this emoji in a reaction


52
53
54
55
56
# File 'lib/discordrb/data/emoji.rb', line 52

def to_reaction
  return name if id.nil?

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