Skip to content

Commit

Permalink
feat: Add ApplicationEmoji to EmojiResolvable and MessageReaction#emo…
Browse files Browse the repository at this point in the history
…ji (#10477)

* types: add ApplicationEmoji to EmojiResolvable

* typings: add ApplicationEmoji to MessageReaction#emoji

* removed ApplicationEmoji from MessageReaction

* update BaseGuildEmojiManager

* chore: lint error

* feat: add ApplicationEmoji to MessageReaction#emoji getter

* refactor: check application emojis first

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
Moebits and kodiakhq[bot] authored Oct 1, 2024
1 parent b20346f commit c633d5c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
7 changes: 6 additions & 1 deletion packages/discord.js/src/managers/BaseGuildEmojiManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const CachedManager = require('./CachedManager');
const ApplicationEmoji = require('../structures/ApplicationEmoji');
const GuildEmoji = require('../structures/GuildEmoji');
const ReactionEmoji = require('../structures/ReactionEmoji');
const { parseEmoji } = require('../util/Util');
Expand All @@ -25,7 +26,8 @@ class BaseGuildEmojiManager extends CachedManager {
* * A Snowflake
* * A GuildEmoji object
* * A ReactionEmoji object
* @typedef {Snowflake|GuildEmoji|ReactionEmoji} EmojiResolvable
* * An ApplicationEmoji object
* @typedef {Snowflake|GuildEmoji|ReactionEmoji|ApplicationEmoji} EmojiResolvable
*/

/**
Expand All @@ -35,6 +37,7 @@ class BaseGuildEmojiManager extends CachedManager {
*/
resolve(emoji) {
if (emoji instanceof ReactionEmoji) return super.resolve(emoji.id);
if (emoji instanceof ApplicationEmoji) return super.resolve(emoji.id);
return super.resolve(emoji);
}

Expand All @@ -45,6 +48,7 @@ class BaseGuildEmojiManager extends CachedManager {
*/
resolveId(emoji) {
if (emoji instanceof ReactionEmoji) return emoji.id;
if (emoji instanceof ApplicationEmoji) return emoji.id;
return super.resolveId(emoji);
}

Expand All @@ -65,6 +69,7 @@ class BaseGuildEmojiManager extends CachedManager {
const emojiResolvable = this.resolve(emoji);
if (emojiResolvable) return emojiResolvable.identifier;
if (emoji instanceof ReactionEmoji) return emoji.identifier;
if (emoji instanceof ApplicationEmoji) return emoji.identifier;
if (typeof emoji === 'string') {
const res = parseEmoji(emoji);
if (res?.name.length) {
Expand Down
15 changes: 12 additions & 3 deletions packages/discord.js/src/structures/MessageReaction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const { Routes } = require('discord-api-types/v10');
const ApplicationEmoji = require('./ApplicationEmoji');
const GuildEmoji = require('./GuildEmoji');
const ReactionEmoji = require('./ReactionEmoji');
const ReactionUserManager = require('../managers/ReactionUserManager');
Expand Down Expand Up @@ -108,16 +109,24 @@ class MessageReaction {
}

/**
* The emoji of this reaction. Either a {@link GuildEmoji} object for known custom emojis, or a {@link ReactionEmoji}
* object which has fewer properties. Whatever the prototype of the emoji, it will still have
* The emoji of this reaction. Either a {@link GuildEmoji} object for known custom emojis,
* {@link ApplicationEmoji} for application emojis, or a {@link ReactionEmoji} object
* which has fewer properties. Whatever the prototype of the emoji, it will still have
* `name`, `id`, `identifier` and `toString()`
* @type {GuildEmoji|ReactionEmoji}
* @type {GuildEmoji|ReactionEmoji|ApplicationEmoji}
* @readonly
*/
get emoji() {
if (this._emoji instanceof GuildEmoji) return this._emoji;
if (this._emoji instanceof ApplicationEmoji) return this._emoji;
// Check to see if the emoji has become known to the client
if (this._emoji.id) {
const applicationEmojis = this.message.client.application.emojis.cache;
if (applicationEmojis.has(this._emoji.id)) {
const emoji = applicationEmojis.get(this._emoji.id);
this._emoji = emoji;
return emoji;
}
const emojis = this.message.client.emojis.cache;
if (emojis.has(this._emoji.id)) {
const emoji = emojis.get(this._emoji.id);
Expand Down
6 changes: 3 additions & 3 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2462,13 +2462,13 @@ export class MessagePayload {

export class MessageReaction {
private constructor(client: Client<true>, data: RawMessageReactionData, message: Message);
private _emoji: GuildEmoji | ReactionEmoji;
private _emoji: GuildEmoji | ReactionEmoji | ApplicationEmoji;

public burstColors: string[] | null;
public readonly client: Client<true>;
public count: number;
public countDetails: ReactionCountDetailsData;
public get emoji(): GuildEmoji | ReactionEmoji;
public get emoji(): GuildEmoji | ReactionEmoji | ApplicationEmoji;
public me: boolean;
public meBurst: boolean;
public message: Message | PartialMessage;
Expand Down Expand Up @@ -5709,7 +5709,7 @@ export type EmojiIdentifierResolvable =
| `<${'' | 'a'}:${string}:${Snowflake}>`
| string;

export type EmojiResolvable = Snowflake | GuildEmoji | ReactionEmoji;
export type EmojiResolvable = Snowflake | GuildEmoji | ReactionEmoji | ApplicationEmoji;

export interface FetchApplicationCommandOptions extends BaseFetchOptions {
guildId?: Snowflake;
Expand Down

0 comments on commit c633d5c

Please sign in to comment.