mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat(applications): add Application structure
This commit is contained in:
120
packages/structures/src/applications/Application.ts
Normal file
120
packages/structures/src/applications/Application.ts
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
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<Omitted extends keyof APIApplication | '' = ''> extends Structure<APIApplication, Omitted> {
|
||||||
|
public static override readonly DataTemplate: Partial<APIApplication> = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param data - The raw data received from the API for the application
|
||||||
|
*/
|
||||||
|
public constructor(data: Partialize<APIApplication, Omitted>) {
|
||||||
|
super(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc Structure.[kPatch]}
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
public override [kPatch](data: Partial<APIApplication>) {
|
||||||
|
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.
|
||||||
|
*
|
||||||
|
* @returns The application's name or an empty string if it doesn't have a name
|
||||||
|
*/
|
||||||
|
public override toString() {
|
||||||
|
return this.name ?? '';
|
||||||
|
}
|
||||||
|
}
|
||||||
1
packages/structures/src/applications/index.ts
Normal file
1
packages/structures/src/applications/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './Application.js';
|
||||||
@@ -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<keyof ApplicationFlags> {
|
||||||
|
/**
|
||||||
|
* Numeric application flags.
|
||||||
|
*/
|
||||||
|
public static override readonly Flags = ApplicationFlags;
|
||||||
|
|
||||||
|
public override toJSON() {
|
||||||
|
return super.toJSON(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
export * from './applications/index.js';
|
||||||
export * from './bitfields/index.js';
|
export * from './bitfields/index.js';
|
||||||
export * from './channels/index.js';
|
export * from './channels/index.js';
|
||||||
export * from './invites/index.js';
|
export * from './invites/index.js';
|
||||||
|
|||||||
Reference in New Issue
Block a user