-
-
Notifications
You must be signed in to change notification settings - Fork 4k
feat(applications): add Application structure
#11163
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
Draft
sdanialraza
wants to merge
2
commits into
main
Choose a base branch
from
feat/application-structures
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.
+137
−0
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,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<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. | ||
| */ | ||
| public override toString() { | ||
| return this.name; | ||
| } | ||
| } | ||
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: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); | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a left-over from previous drafts for /structures and is not needed, since inheritance already causes exactly this.