diff --git a/packages/structures/src/applications/Application.ts b/packages/structures/src/applications/Application.ts new file mode 100644 index 000000000000..72b7d170aa23 --- /dev/null +++ b/packages/structures/src/applications/Application.ts @@ -0,0 +1,119 @@ +import { DiscordSnowflake } from '@sapphire/snowflake'; +import type { APIApplication } from 'discord-api-types/v10'; +import { Structure } from '../Structure.js'; +import { kData, kPatch } from '../utils/symbols.js'; +import { isIdSet } from '../utils/type-guards.js'; +import type { Partialize } from '../utils/types.js'; + +/** + * Represents a Discord application + * + * @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate` + */ +export class Application extends Structure { + public static override readonly DataTemplate: Partial = {}; + + /** + * @param data - The raw data received from the API for the application + */ + public constructor(data: Partialize) { + super(data); + } + + /** + * {@inheritDoc Structure.[kPatch]} + * + * @internal + */ + public override [kPatch](data: Partial) { + return super[kPatch](data); + } + + /** + * The id of the application + */ + public get id() { + return this[kData].id; + } + + /** + * The name of the application + */ + public get name() { + return this[kData].name; + } + + /** + * The description of the application + */ + public get description() { + return this[kData].description; + } + + /** + * The icon hash of the application + */ + public get icon() { + return this[kData].icon; + } + + /** + * If this application's bot is public. + * When `false` only the application owner can add the application's bot to guilds + */ + public get botPublic() { + return this[kData].bot_public; + } + + /** + * If this application's bot requires code grant. + * When `true` the application's bot will only join upon completion of the full OAuth2 code grant flow + */ + public get botRequireCodeGrant() { + return this[kData].bot_require_code_grant; + } + + /** + * The hexadecimal encoded key for verification in interactions and the GameSDK's GetTicket function + */ + public get verifyKey() { + return this[kData].verify_key; + } + + /** + * The team this application belongs to + */ + public get team() { + return this[kData].team; + } + + /** + * If webhook events are enabled for the application + */ + public get eventWebhookStatus() { + return this[kData].event_webhooks_status; + } + + /** + * The timestamp the application was created at + */ + public get createdTimestamp() { + return isIdSet(this.id) ? DiscordSnowflake.timestampFrom(this.id) : null; + } + + /** + * The time the application was created at + */ + public get createdAt() { + const createdTimestamp = this.createdTimestamp; + return createdTimestamp ? new Date(createdTimestamp) : null; + } + + /** + * When concatenated with a string, this automatically returns the application's name instead of the + * Application object. + */ + public override toString() { + return this.name; + } +} diff --git a/packages/structures/src/applications/index.ts b/packages/structures/src/applications/index.ts new file mode 100644 index 000000000000..42e05d0760b1 --- /dev/null +++ b/packages/structures/src/applications/index.ts @@ -0,0 +1 @@ +export * from './Application.js'; diff --git a/packages/structures/src/bitfields/ApplicationFlagsBitField.ts b/packages/structures/src/bitfields/ApplicationFlagsBitField.ts new file mode 100644 index 000000000000..2074303bcdf8 --- /dev/null +++ b/packages/structures/src/bitfields/ApplicationFlagsBitField.ts @@ -0,0 +1,16 @@ +import { ApplicationFlags } from 'discord-api-types/v10'; +import { BitField } from './BitField.js'; + +/** + * Data structure that makes it easy to interact with a {@link (Application:class).flags} bitfield. + */ +export class ApplicationFlagsBitField extends BitField { + /** + * Numeric application flags. + */ + public static override readonly Flags = ApplicationFlags; + + public override toJSON() { + return super.toJSON(true); + } +} diff --git a/packages/structures/src/index.ts b/packages/structures/src/index.ts index 5a2e6b407d7f..62fa8d59f4d6 100644 --- a/packages/structures/src/index.ts +++ b/packages/structures/src/index.ts @@ -1,3 +1,4 @@ +export * from './applications/index.js'; export * from './bitfields/index.js'; export * from './channels/index.js'; export * from './invites/index.js';