diff --git a/packages/structures/src/emojis/Emoji.ts b/packages/structures/src/emojis/Emoji.ts new file mode 100644 index 000000000..5bcfc1004 --- /dev/null +++ b/packages/structures/src/emojis/Emoji.ts @@ -0,0 +1,100 @@ +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` + */ +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; + } + + /** + * The roles allowed to use this Emoji + */ + public get roles() { + return this[kData].roles; + } + + /** + * User that created this emoji + */ + public get user() { + return this[kData].user; + } + + /** + * 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';