Files
discord.js/src/structures/Emoji.js
BorgerKing bbdbc4cfa7 feat: remove datastores and implement Managers (#3696)
* Initial commit: add 5 initial managers

- Base manager
- GuildChannelManager
- MessageManager
- PresenceManager
- Reaction Manager
- Added LimitedCollection

* Add GuildEmojiManager, various fixes

* Modify some managers and add guildmembermanager

* Initial integration

* Delete old stores

* Integration part two, removed LRUCollection

- Most of the integration has been finished
- TODO typings
- Removed LRUCollection, needless sweeping

* Typings + stuff i somehow missed in ChannelManager

* LimitedCollection typings/ final changes

* Various jsdoc and syntactical fixes, Removed Util.mixin()

* tslint fix

* Grammatical and logical changes

* Delete temporary file placed by mistake

* Grammatical changes

* Add missing type

* Update jsdoc examples

* fix: ChannelManager#remove should call cache#delete not cache#remove

* fix recursive require

* Fix missed cache in util

* fix: more missed cache

* Remove accidental _fetchMany change from #3645

* fix: use .cache.delete() over .remove()

* fix: missing cache in ReactionCollector

* fix: missed cache in client

* fix: members is a collection not a manager

Co-Authored-By: Sugden <28943913+NotSugden@users.noreply.github.com>

* fix: various docs and cache fixes

* fix: missed cache

* fix: missing _roles

* Final testing and debugging

* LimitedCollection: return the Collection instead of undefined on .set

* Add cache to BaseManager in typings

* Commit fixes i forgot to stage yesterday

* Update invite events

* Account for new commit

* fix: MessageReactionRemoveAll should call .cache.clear()

* fix: add .cache at various places, correct return type

* docs: remove mentions of 'store'

* Add extra documented properties to typings

Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>
Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
2020-02-11 20:21:07 +01:00

106 lines
2.3 KiB
JavaScript

'use strict';
const Snowflake = require('../util/Snowflake');
const Base = require('./Base');
/**
* Represents an emoji, see {@link GuildEmoji} and {@link ReactionEmoji}.
* @extends {Base}
*/
class Emoji extends Base {
constructor(client, emoji) {
super(client);
/**
* Whether this emoji is animated
* @type {boolean}
*/
this.animated = emoji.animated;
/**
* The name of this emoji
* @type {string}
*/
this.name = emoji.name;
/**
* The ID of this emoji
* @type {?Snowflake}
*/
this.id = emoji.id;
/**
* Whether this emoji has been deleted
* @type {boolean}
*/
this.deleted = false;
}
/**
* The identifier of this emoji, used for message reactions
* @type {string}
* @readonly
*/
get identifier() {
if (this.id) return `${this.animated ? 'a:' : ''}${this.name}:${this.id}`;
return encodeURIComponent(this.name);
}
/**
* The URL to the emoji file if its a custom emoji
* @type {?string}
* @readonly
*/
get url() {
if (!this.id) return null;
return this.client.rest.cdn.Emoji(this.id, this.animated ? 'gif' : 'png');
}
/**
* The timestamp the emoji was created at, or null if unicode
* @type {?number}
* @readonly
*/
get createdTimestamp() {
if (!this.id) return null;
return Snowflake.deconstruct(this.id).timestamp;
}
/**
* The time the emoji was created at, or null if unicode
* @type {?Date}
* @readonly
*/
get createdAt() {
if (!this.id) return null;
return new Date(this.createdTimestamp);
}
/**
* When concatenated with a string, this automatically returns the text required to form a graphical emoji on Discord
* instead of the Emoji object.
* @returns {string}
* @example
* // Send a custom emoji from a guild:
* const emoji = guild.emojis.cache.first();
* msg.reply(`Hello! ${emoji}`);
* @example
* // Send the emoji used in a reaction to the channel the reaction is part of
* reaction.message.channel.send(`The emoji used was: ${reaction.emoji}`);
*/
toString() {
return this.id ? `<${this.animated ? 'a' : ''}:${this.name}:${this.id}>` : this.name;
}
toJSON() {
return super.toJSON({
guild: 'guildID',
createdTimestamp: true,
url: true,
identifier: true,
});
}
}
module.exports = Emoji;