mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +01:00
feat(MessageReaction): backport animated, client, created*, and url (#3711)
This commit is contained in:
@@ -31,7 +31,7 @@ class MessageReaction {
|
|||||||
*/
|
*/
|
||||||
this.users = new Collection();
|
this.users = new Collection();
|
||||||
|
|
||||||
this._emoji = new ReactionEmoji(this, emoji.name, emoji.id);
|
this._emoji = new ReactionEmoji(this, emoji);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,10 +1,21 @@
|
|||||||
|
const Constants = require('../util/Constants');
|
||||||
|
const Snowflake = require('../util/Snowflake');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a limited emoji set used for both custom and unicode emojis. Custom emojis
|
* Represents a limited emoji set used for both custom and unicode emojis. Custom emojis
|
||||||
* will use this class opposed to the Emoji class when the client doesn't know enough
|
* will use this class opposed to the Emoji class when the client doesn't know enough
|
||||||
* information about them.
|
* information about them.
|
||||||
*/
|
*/
|
||||||
class ReactionEmoji {
|
class ReactionEmoji {
|
||||||
constructor(reaction, name, id) {
|
constructor(reaction, emoji) {
|
||||||
|
/**
|
||||||
|
* The client that instantiated this object
|
||||||
|
* @name ReactionEmoji#client
|
||||||
|
* @type {Client}
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
|
Object.defineProperty(this, 'client', { value: reaction.message.client });
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The message reaction this emoji refers to
|
* The message reaction this emoji refers to
|
||||||
* @type {MessageReaction}
|
* @type {MessageReaction}
|
||||||
@@ -15,13 +26,49 @@ class ReactionEmoji {
|
|||||||
* The name of this reaction emoji
|
* The name of this reaction emoji
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.name = name;
|
this.name = emoji.name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ID of this reaction emoji
|
* The ID of this reaction emoji
|
||||||
* @type {?Snowflake}
|
* @type {?Snowflake}
|
||||||
*/
|
*/
|
||||||
this.id = id;
|
this.id = emoji.id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this reaction emoji is animated
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.animated = emoji.animated || false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The timestamp the reaction 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 reaction emoji was created, or null if unicode
|
||||||
|
* @type {?Date}
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
|
get createdAt() {
|
||||||
|
if (!this.id) return null;
|
||||||
|
return new Date(this.createdTimestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL to the reaction emoji file, or null if unicode
|
||||||
|
* @type {string}
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
|
get url() {
|
||||||
|
if (!this.id) return null;
|
||||||
|
return Constants.Endpoints.CDN(this.client.options.http.cdn).Emoji(this.id, this.animated ? 'gif' : 'png');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,7 +89,9 @@ class ReactionEmoji {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
toString() {
|
toString() {
|
||||||
return this.id ? `<:${this.name}:${this.id}>` : this.name;
|
if (!this.id) return this.name;
|
||||||
|
|
||||||
|
return `<${this.animated ? 'a' : ''}:${this.name}:${this.id}>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
7
typings/index.d.ts
vendored
7
typings/index.d.ts
vendored
@@ -1027,11 +1027,16 @@ declare module 'discord.js' {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ReactionEmoji {
|
export class ReactionEmoji {
|
||||||
constructor(reaction: MessageReaction, name: string, id: string);
|
constructor(reaction: MessageReaction, emoji: object);
|
||||||
|
public animated: boolean;
|
||||||
|
public readonly client: Client;
|
||||||
|
public readonly createdAt: number | null;
|
||||||
|
public readonly createdTimestamp: number | null;
|
||||||
public id: Snowflake;
|
public id: Snowflake;
|
||||||
public readonly identifier: string;
|
public readonly identifier: string;
|
||||||
public name: string;
|
public name: string;
|
||||||
public reaction: MessageReaction;
|
public reaction: MessageReaction;
|
||||||
|
public readonly url: string | null;
|
||||||
public toString(): string;
|
public toString(): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user