-
-
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
16
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.
Open
Changes from 1 commit
Commits
Show all changes
16 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 3c87423
fix(structures): add missing datatemplate
keston-dev 7f6cc1f
fix: change createdAt to proposed createdDate structure
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
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,261 @@ | ||
| import type { APIApplication, ApplicationFlags } from 'discord-api-types/v10'; | ||
| import { Structure } from '../Structure'; | ||
| import { ApplicationFlagsBitField } from '../bitfields'; | ||
| import { kData } from '../utils/symbols'; | ||
| import type { Partialize } from '../utils/types'; | ||
|
|
||
| /** | ||
| * 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` | ||
| */ | ||
keston-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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. | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| 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 https://discord.com/developers/docs/reference#image-formatting | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public get icon() { | ||
keston-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return this[kData].icon; | ||
| } | ||
|
|
||
| /** | ||
| * 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; | ||
| } | ||
|
|
||
| /** | ||
| * Partial user object for the bot user associated with the application. | ||
| */ | ||
| public get bot() { | ||
| return this[kData].bot; | ||
| } | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * The URL of the app's Terms and Service. | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public get termsOfServiceURL() { | ||
| return this[kData].terms_of_service_url; | ||
| } | ||
|
|
||
| /** | ||
| * The URL of the app's Privacy Policy. | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public get privacyPolicyURL() { | ||
| return this[kData].privacy_policy_url; | ||
| } | ||
|
|
||
| /** | ||
| * Partial user object containing the owner of the application. | ||
| * | ||
| * @see https://discord.com/developers/docs/resources/user#user-object | ||
| */ | ||
| public get owner() { | ||
| return this[kData].owner; | ||
| } | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Hexadecimal encoded key for verification in interactions and the GameSDK's GetTicket function. | ||
| * | ||
| * @see https://discord.com/developers/docs/game-sdk/applications#getticket | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public get verifyKey() { | ||
| return this[kData].verify_key; | ||
| } | ||
|
|
||
| /** | ||
| * The team this application belongs to. | ||
| * | ||
| * @see https://discord.com/developers/docs/topics/teams#data-models-team-object | ||
| */ | ||
| public get team() { | ||
| return this[kData].team; | ||
| } | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * The ID of the guild associated with the app. | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public get guildId() { | ||
| return this[kData].guild_id; | ||
| } | ||
|
|
||
| /** | ||
| * A partial object of the guild associated with the app. | ||
| */ | ||
| public get guild() { | ||
| return this[kData].guild; | ||
| } | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * The id of the "Game SKU" that is created, if this application is a game sold on Discord, . | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public get primarySKUId() { | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 https://discord.com/developers/docs/reference#image-formatting | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public get coverImage() { | ||
keston-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return this[kData].cover_image; | ||
| } | ||
|
|
||
| /** | ||
| * The application's public flags. | ||
| * | ||
| * @see https://discord.com/developers/docs/resources/application#application-object-application-flags | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public get flags() { | ||
| const flags = this[kData].flags; | ||
| return flags ? new ApplicationFlagsBitField(this[kData].flags as ApplicationFlags) : null; | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
almeidx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * 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. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we expose directly as array for this (general question) |
||
| */ | ||
| 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 eventsWebhookStatus() { | ||
| return this[kData].event_webhooks_status; | ||
almeidx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * 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; | ||
| } | ||
| } | ||
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'; | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Data structure that makes it easy to interact with a {@link Application#flags} bitfield. | ||
| */ | ||
| export class ApplicationFlagsBitField extends BitField<keyof ApplicationFlags> { | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /** | ||
| * Numeric application flags. | ||
| */ | ||
| public static override readonly Flags = ApplicationFlags; | ||
keston-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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
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.