From 69432a1bca00c5181557a33e0288b7839dbe9737 Mon Sep 17 00:00:00 2001 From: Asad <105254706+AsadHumayun@users.noreply.github.com> Date: Thu, 15 Jan 2026 23:31:35 +0000 Subject: [PATCH] feat(structures): add emoji structure (#11369) * feat(structures): add emoji structure * chore: update deps * chore: update deps * chore: update deps * Revert "chore: update deps" This reverts commit 8332f48611eded926dd04c7a061aeae3266a4abb. * Revert "chore: update deps" This reverts commit a168e735a3cde3b7d10eb07664583881675fafa0. * Revert "chore: update deps" This reverts commit 0b19058cdaba93c7d72a8c3b3526e26565725d35. * chore: consistency (capitalisation) * fix(structures): do not export substructures from emoji structure * chore(structures): add remark detailing substructures * chore: update remarks to reflect exported substructures (remove roles) * chore: update remarks to explain why roles not exposed on structure --- packages/structures/src/emojis/Emoji.ts | 88 +++++++++++++++++++++++++ packages/structures/src/emojis/index.ts | 1 + packages/structures/src/index.ts | 1 + 3 files changed, 90 insertions(+) create mode 100644 packages/structures/src/emojis/Emoji.ts create mode 100644 packages/structures/src/emojis/index.ts diff --git a/packages/structures/src/emojis/Emoji.ts b/packages/structures/src/emojis/Emoji.ts new file mode 100644 index 000000000..5765008ea --- /dev/null +++ b/packages/structures/src/emojis/Emoji.ts @@ -0,0 +1,88 @@ +import { DiscordSnowflake } from '@sapphire/snowflake'; +import type { APIEmoji } from 'discord-api-types/v10'; +import { Structure } from '../Structure.js'; +import { kData } from '../utils/symbols.js'; +import { isIdSet } from '../utils/type-guards.js'; +import type { Partialize } from '../utils/types.js'; + +/** + * Represents any emoji on Discord. + * + * @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate` + * @remarks has substructure `User` which needs to be instantiated and stored by an extending class using it + * @remarks intentionally does not export `roles` so that extending classes can resolve `Snowflake[]` to `Role[]` + */ +export class Emoji extends Structure { + /** + * The template used for removing data from the raw data stored for each emoji + */ + public static override readonly DataTemplate: Partial = {}; + + /** + * @param data - The raw data received from the API for the emoji + */ + public constructor(data: Partialize) { + super(data); + } + + /** + * The emoji's id + */ + public get id() { + return this[kData].id; + } + + /** + * The name of the emoji + * + * @remarks can be null only in reaction emoji objects + */ + public get name() { + return this[kData].name; + } + + /** + * Whether this emoji must be wrapped in colons + */ + public get requireColons() { + return this[kData].require_colons; + } + + /** + * Whether the emoji is managed + */ + public get managed() { + return this[kData].managed; + } + + /** + * Whether the emoji is animated + */ + public get animated() { + return this[kData].animated; + } + + /** + * Whether the emoji can be used + * + * @remarks May be false due to loss of server boosts + */ + public get available() { + return this[kData].available; + } + + /** + * The timestamp the emoji was created at + */ + public get createdTimestamp() { + return isIdSet(this.id) ? DiscordSnowflake.timestampFrom(this.id) : null; + } + + /** + * The time the emoji was created at + */ + public get createdAt() { + const createdTimestamp = this.createdTimestamp; + return createdTimestamp ? new Date(createdTimestamp) : null; + } +} diff --git a/packages/structures/src/emojis/index.ts b/packages/structures/src/emojis/index.ts new file mode 100644 index 000000000..79b3d8e94 --- /dev/null +++ b/packages/structures/src/emojis/index.ts @@ -0,0 +1 @@ +export * from './Emoji.js'; diff --git a/packages/structures/src/index.ts b/packages/structures/src/index.ts index 274b2ef05..06a7611db 100644 --- a/packages/structures/src/index.ts +++ b/packages/structures/src/index.ts @@ -1,5 +1,6 @@ export * from './bitfields/index.js'; export * from './channels/index.js'; +export * from './emojis/index.js'; export * from './interactions/index.js'; export * from './invites/index.js'; export * from './messages/index.js';