-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat(structures): add Application structure #11393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
keston-dev
wants to merge
14
commits into
discordjs:main
Choose a base branch
from
keston-dev:feat/application-structure
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+297
−2
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
122c5fb
feat(structures): add Application structure
keston-dev 5528ccf
feat(structures): rename eventsWebhookStatus to eventWebhooksStatus
keston-dev d2240ee
feat(structures): add application to index.ts
keston-dev 18c735a
feat(structures): fix casing and remove substructures
keston-dev aeefabb
feat(structures): remove team substructure
keston-dev e06156c
feat(structures): add createdAt and createdTimestamp to Application
keston-dev 0f77519
feat(structures): fix bitfield to use typeof and repair jsdoc links
keston-dev a67bec1
Merge branch 'main' into feat/application-structure
keston-dev dc11d9e
feat(structures): repair JSDoc and property casing
keston-dev 5f23e52
Merge branch 'feat/application-structure' of https://github.com/kesto…
keston-dev bced135
feat(structures): fix import extensions and match new flag check
keston-dev 57acbf5
Merge branch 'main' of https://github.com/discordjs/discord.js into f…
keston-dev 5debdbe
feat(structures): use isFieldSet and add image URL getters
keston-dev 05f5d2b
feat(structures): fix wrong CDN route
keston-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,278 @@ | ||
| import { DiscordSnowflake } from '@sapphire/snowflake'; | ||
| import { | ||
| type ApplicationIconFormat, | ||
| type APIApplication, | ||
| type ApplicationCoverFormat, | ||
| type ApplicationFlags, | ||
| CDNRoutes, | ||
| ImageFormat, | ||
| RouteBases, | ||
| } from 'discord-api-types/v10'; | ||
| import { Structure } from '../Structure.js'; | ||
| import { ApplicationFlagsBitField } from '../bitfields/ApplicationFlagsBitField.js'; | ||
| import { kData } from '../utils/symbols.js'; | ||
| import { isFieldSet, isIdSet } from '../utils/type-guards.js'; | ||
| import type { Partialize } from '../utils/types.js'; | ||
|
|
||
| /** | ||
| * Represents an application 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`, `Guild` and `Team`, which need to be instantiated and stored by an extending class using it. | ||
| */ | ||
| export class Application<Omitted extends keyof APIApplication | '' = ''> extends Structure<APIApplication, Omitted> { | ||
| /** | ||
| * @param data - The raw data from the API for the application. | ||
| */ | ||
| public constructor(data: Partialize<APIApplication, Omitted>) { | ||
| super(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 icon hash of the application. | ||
| * | ||
| * @see {@link https://discord.com/developers/docs/reference#image-formatting} | ||
| */ | ||
| public get icon() { | ||
keston-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return this[kData].icon; | ||
| } | ||
|
|
||
| /** | ||
| * Get the URL to the icon. | ||
| * | ||
| * @param format - the file format to use | ||
| */ | ||
| public iconURL(format: ApplicationIconFormat = ImageFormat.WebP) { | ||
| return isIdSet(this[kData].id) && isFieldSet(this[kData], 'icon', 'string') | ||
| ? `${RouteBases.cdn}${CDNRoutes.applicationIcon(this[kData].id.toString(), this[kData].icon, format)}` | ||
| : null; | ||
| } | ||
|
|
||
| /** | ||
| * The description of the application. | ||
| */ | ||
| public get description() { | ||
| return this[kData].description; | ||
| } | ||
|
|
||
| /** | ||
| * A list of RPC origin URLs, if RPC is enabled. | ||
| */ | ||
| public get rpcOrigins() { | ||
| return this[kData].rpc_origins; | ||
| } | ||
|
|
||
| /** | ||
| * Whether the application is public. | ||
| * | ||
| * @remarks If `false`, only the app owner can add the app to guilds. | ||
| */ | ||
| public get botPublic() { | ||
| return this[kData].bot_public; | ||
| } | ||
|
|
||
| /** | ||
| * Whether the application requires a code grant. | ||
| * | ||
| * @remarks When `true`, the app's bot will only join upon completion of the full OAuth2 grant flow. | ||
| */ | ||
| public get botRequiresCodeGrant() { | ||
| return this[kData].bot_require_code_grant; | ||
| } | ||
|
|
||
| /** | ||
| * The URL of the app's terms and service. | ||
| */ | ||
| public get termsOfServiceURL() { | ||
| return this[kData].terms_of_service_url; | ||
| } | ||
|
|
||
| /** | ||
| * The URL of the app's privacy policy. | ||
| */ | ||
| public get privacyPolicyURL() { | ||
| return this[kData].privacy_policy_url; | ||
| } | ||
|
|
||
| /** | ||
| * Hexadecimal encoded key for verification in interactions and the GameSDK's GetTicket function. | ||
| * | ||
| * @see {@link https://github.com/discord/discord-api-docs/blob/legacy-gamesdk/docs/game_sdk/Applications.md#getticket} | ||
| */ | ||
| public get verifyKey() { | ||
| return this[kData].verify_key; | ||
| } | ||
|
|
||
| /** | ||
| * The id of the guild associated with the app. | ||
| */ | ||
| public get guildId() { | ||
| return this[kData].guild_id; | ||
| } | ||
|
|
||
| /** | ||
| * The id of the "Game SKU" that is created, if this application is a game sold on Discord. | ||
| */ | ||
| public get primarySkuId() { | ||
| return this[kData].primary_sku_id; | ||
| } | ||
|
|
||
| /** | ||
| * The URL that links to the store page, if the application is a game sold on Discord. | ||
| */ | ||
| public get slug() { | ||
| return this[kData].slug; | ||
| } | ||
|
|
||
| /** | ||
| * The application's default rich presence invite cover image hash. | ||
| * | ||
| * @see {@link https://discord.com/developers/docs/reference#image-formatting} | ||
| */ | ||
| public get coverImage() { | ||
keston-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return this[kData].cover_image; | ||
| } | ||
|
|
||
| /** | ||
| * Get the URL to the cover image. | ||
| * | ||
| * @param format - the file format to use | ||
| */ | ||
| public coverImageURL(format: ApplicationCoverFormat = ImageFormat.WebP) { | ||
| return isIdSet(this[kData].id) && isFieldSet(this[kData], 'cover_image', 'string') | ||
| ? `${RouteBases.cdn}${CDNRoutes.applicationCover(this[kData].id.toString(), this[kData].cover_image, format)}` | ||
| : null; | ||
| } | ||
|
|
||
| /** | ||
| * The application's public flags. | ||
| * | ||
| * @see {@link https://discord.com/developers/docs/resources/application#application-object-application-flags} | ||
| */ | ||
| public get flags() { | ||
| return isFieldSet(this[kData], 'flags', 'number') | ||
| ? new ApplicationFlagsBitField(this[kData].flags as ApplicationFlags) | ||
| : null; | ||
| } | ||
|
|
||
| /** | ||
| * Approximate count of guilds the application has been added to. | ||
| */ | ||
| public get approximateGuildCount() { | ||
| return this[kData].approximate_guild_count; | ||
| } | ||
|
|
||
| /** | ||
| * Approximate count of users that have installed the application | ||
| * (authorized with `application.commands` as a scope) | ||
| */ | ||
| public get approximateUserInstallCount() { | ||
| return this[kData].approximate_user_install_count; | ||
| } | ||
|
|
||
| /** | ||
| * Approximate count of users that have OAuth2 authorizations for the app. | ||
| */ | ||
| public get approximateUserAuthorizationCount() { | ||
| return this[kData].approximate_user_authorization_count; | ||
| } | ||
|
|
||
| /** | ||
| * An array of redirect URIs for the application. | ||
| */ | ||
| public get redirectURIs() { | ||
| return this[kData].redirect_uris; | ||
| } | ||
|
|
||
| /** | ||
| * The interaction's endpoint URL for the application. | ||
| */ | ||
| public get interactionsEndpointURL() { | ||
| return this[kData].interactions_endpoint_url; | ||
| } | ||
|
|
||
| /** | ||
| * The application's role connection verification entry point, which when configured will render the app as a verification method in the guild role verification configuration | ||
| */ | ||
| public get roleConnectionsVerificationURL() { | ||
| return this[kData].role_connections_verification_url; | ||
| } | ||
|
|
||
| /** | ||
| * The event webhooks URL for the application to receive webhook events. | ||
| */ | ||
| public get eventWebhooksURL() { | ||
| return this[kData].event_webhooks_url; | ||
| } | ||
|
|
||
| /** | ||
| * If webhook events are enabled for the app | ||
| */ | ||
| public get eventWebhooksStatus() { | ||
| return this[kData].event_webhooks_status; | ||
| } | ||
|
|
||
| /** | ||
| * List of webhook event types the application subscribes to. | ||
| */ | ||
| public get eventWebhooksTypes() { | ||
| return this[kData].event_webhooks_types; | ||
| } | ||
|
|
||
| /** | ||
| * Up to 5 tags of 20 maximum characters, used to describe the content and functionality of the application. | ||
| */ | ||
| public get tags() { | ||
| return this[kData].tags; | ||
| } | ||
|
|
||
| /** | ||
| * Settings for the app's default in-app authorization link, if enabled. | ||
| */ | ||
| public get installParams() { | ||
| return this[kData].install_params; | ||
| } | ||
|
|
||
| /** | ||
| * Default scopes and permissions for each supported installation context. Value for each key is an integration type configuration object. | ||
| */ | ||
| public get integrationTypesConfig() { | ||
| return this[kData].integration_types_config; | ||
| } | ||
|
|
||
| /** | ||
| * Default custom authorization URL for the application, if enabled. | ||
| */ | ||
| public get customInstallURL() { | ||
| return this[kData].custom_install_url; | ||
| } | ||
|
|
||
| /** | ||
| * 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; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './Application.js'; |
16 changes: 16 additions & 0 deletions
16
packages/structures/src/bitfields/ApplicationFlagsBitField.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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#flags} bitfield. | ||
| */ | ||
| export class ApplicationFlagsBitField extends BitField<keyof typeof ApplicationFlags> { | ||
| /** | ||
| * Numeric application flags. | ||
| */ | ||
| public static override readonly Flags = ApplicationFlags; | ||
|
|
||
| public override toJSON() { | ||
| return super.toJSON(true); | ||
| } | ||
Qjuh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.