Class: RubyCord::CustomEmoji

Inherits:
Emoji
  • Object
show all
Defined in:
lib/rubycord/emoji.rb

Overview

Represents a custom emoji in discord.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Emoji

#==, #eql?

Instance Attribute Details

#availableBoolean (readonly) Also known as: available?

Returns whether the emoji is available.

Returns:

  • (Boolean)

    whether the emoji is available.



45
46
47
# File 'lib/rubycord/emoji.rb', line 45

def available
  @available
end

#guildRubyCord::Guild (readonly)

Returns The guild that owns this emoji.

Returns:



37
38
39
# File 'lib/rubycord/emoji.rb', line 37

def guild
  @guild
end

#idRubyCord::Snowflake (readonly)

Returns The ID of the emoji.

Returns:



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

def id
  @id
end

#managedBoolean (readonly) Also known as: managed?

Returns whether the emoji is managed by integration (ex: Twitch).

Returns:

  • (Boolean)

    whether the emoji is managed by integration (ex: Twitch).



39
40
41
# File 'lib/rubycord/emoji.rb', line 39

def managed
  @managed
end

#nameString (readonly)

Returns The name of the emoji.

Returns:

  • (String)

    The name of the emoji.



31
32
33
# File 'lib/rubycord/emoji.rb', line 31

def name
  @name
end

#require_colonsBoolean (readonly) Also known as: require_colons?

Returns whether the emoji requires colons.

Returns:

  • (Boolean)

    whether the emoji requires colons.



42
43
44
# File 'lib/rubycord/emoji.rb', line 42

def require_colons
  @require_colons
end

#rolesArray<RubyCord::Guild::Role> (readonly)

Returns The roles that can use this emoji.

Returns:



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

def roles
  @roles
end

#roles?Boolean (readonly) Also known as: role?

Returns whether or not this emoji is restricted to certain roles.

Returns:

  • (Boolean)

    whether or not this emoji is restricted to certain roles.



# File 'lib/rubycord/emoji.rb', line 48

#userRubyCord::User (readonly)

Returns The user that created this emoji.

Returns:



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

def user
  @user
end

Instance Method Details

#delete(reason: nil) ⇒ Async::Task<self> Also known as: destroy

Delete the emoji.

Parameters:

  • reason (String) (defaults to: nil)

    The reason for deleting the emoji.

Returns:

  • (Async::Task<self>)

    The deleted emoji.



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/rubycord/emoji.rb', line 135

def delete(reason: nil)
  Async do
    @client
      .http
      .request(
        RubyCord::Internal::Route.new(
          "/guilds/#{@guild.id}/emojis/#{@id}",
          "//guilds/:guild_id/emojis/:emoji_id",
          :delete
        ),
        {},
        audit_log_reason: reason
      )
      .wait
    @available = false
    self
  end
end

#edit(name: RubyCord::Unset, roles: RubyCord::Unset, reason: nil) ⇒ Async::Task<self> Also known as: modify

Note:

The arguments of this method are defaultly set to RubyCord::Unset. Specify value to set the value, if not don't specify or specify RubyCord::Unset.

Edit the emoji.

Parameters:

  • name (String) (defaults to: RubyCord::Unset)

    The new name of the emoji.

  • roles (Array<RubyCord::Guild::Role>) (defaults to: RubyCord::Unset)

    The new roles that can use this emoji.

  • reason (String) (defaults to: nil)

    The reason for editing the emoji.

Returns:

  • (Async::Task<self>)

    The edited emoji.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/rubycord/emoji.rb', line 105

def edit(name: RubyCord::Unset, roles: RubyCord::Unset, reason: nil)
  Async do
    payload = {}
    payload[:name] = name if name != RubyCord::Unset
    payload[:roles] = roles.map do |r|
      RubyCord::Utils.try(r, :id)
    end if roles != RubyCord::Unset
    @client.http.request(
      RubyCord::Internal::Route.new(
        "/guilds/#{@guild.id}/emojis/#{@id}",
        "//guilds/:guild_id/emojis/:emoji_id",
        :patch
      ),
      payload,
      audit_log_reason: reason
    )
    self
  end
end

#inspectObject



90
91
92
# File 'lib/rubycord/emoji.rb', line 90

def inspect
  "#<#{self.class} id=#{@id} :#{@name}:>"
end

#to_sString

Format the emoji for sending.

Returns:

  • (String)

    the formatted emoji.



71
72
73
# File 'lib/rubycord/emoji.rb', line 71

def to_s
  "<#{@animated ? "a" : ""}:#{@name}:#{id}>"
end

#to_uriString

Format the emoji for URI.

Returns:

  • (String)

    the formatted emoji.



80
81
82
# File 'lib/rubycord/emoji.rb', line 80

def to_uri
  "#{@name}:#{@id}"
end