Skip to content

Commit

Permalink
feat: user-installable apps (#921)
Browse files Browse the repository at this point in the history
Co-authored-by: Vlad Frangu <me@vladfrangu.dev>
  • Loading branch information
AtoraSuunva and vladfrangu authored May 15, 2024
1 parent 7650ce4 commit c457b8d
Show file tree
Hide file tree
Showing 26 changed files with 524 additions and 20 deletions.
46 changes: 46 additions & 0 deletions deno/payloads/v10/_interactions/applicationCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export interface APIApplicationCommand {
default_member_permissions: Permissions | null;
/**
* Indicates whether the command is available in DMs with the app, only for globally-scoped commands. By default, commands are visible
*
* @deprecated Use `contexts` instead
*/
dm_permission?: boolean;
/**
Expand All @@ -88,6 +90,18 @@ export interface APIApplicationCommand {
* Indicates whether the command is age-restricted, defaults to `false`
*/
nsfw?: boolean;
/**
* Installation context(s) where the command is available, only for globally-scoped commands. Defaults to `GUILD_INSTALL ([0])`
*
* @unstable
*/
integration_types?: ApplicationIntegrationType[];
/**
* Interaction context(s) where the command can be used, only for globally-scoped commands. By default, all interaction context types included for new commands `[0,1,2]`.
*
* @unstable
*/
contexts?: InteractionContextType[] | null;
/**
* Autoincrementing version identifier updated during substantial record changes
*/
Expand All @@ -103,6 +117,38 @@ export enum ApplicationCommandType {
Message,
}

/**
* https://discord.com/developers/docs/resources/application#application-object-application-integration-types
*/
export enum ApplicationIntegrationType {
/**
* App is installable to servers
*/
GuildInstall = 0,
/**
* App is installable to users
*/
UserInstall = 1,
}

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types
*/
export enum InteractionContextType {
/**
* Interaction can be used within servers
*/
Guild = 0,
/**
* Interaction can be used within DMs with the app's bot user
*/
BotDM = 1,
/**
* Interaction can be used within Group DMs and DMs other than the app's bot user
*/
PrivateChannel = 2,
}

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-data
*/
Expand Down
50 changes: 48 additions & 2 deletions deno/payloads/v10/_interactions/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Permissions, Snowflake } from '../../../globals.ts';
import type { APIRole, LocaleString } from '../../../v10.ts';
import type { APIRole, ApplicationIntegrationType, InteractionContextType, LocaleString } from '../../../v10.ts';
import type {
APIAttachment,
APIChannel,
Expand All @@ -14,6 +14,40 @@ import type { APIEntitlement } from '../monetization.ts';
import type { APIUser } from '../user.ts';
import type { InteractionType } from './responses.ts';

/**
* https://discord.com/developers/docs/resources/channel#message-interaction-metadata-object
*/
export interface APIMessageInteractionMetadata {
/**
* ID of the interaction
*/
id: Snowflake;
/**
* Type of interaction
*/
type: InteractionType;
/**
* User who triggered the interaction
*/
user: APIUser;
/**
* IDs for installation context(s) related to an interaction. Details in Authorizing Integration Owners Object
*/
authorizing_integration_owners: APIAuthorizingIntegrationOwnersMap;
/**
* ID of the original response message, present only on follow-up messages
*/
original_response_message_id?: Snowflake;
/**
* ID of the message that contained interactive component, present only on messages created from component interactions
*/
interacted_message_id?: Snowflake;
/**
* Metadata for the interaction that was used to open the modal, present only on modal submit interactions
*/
triggering_interaction_metadata?: APIMessageInteractionMetadata;
}

export type PartialAPIMessageInteractionGuildMember = Pick<
APIGuildMember,
| 'avatar'
Expand Down Expand Up @@ -122,7 +156,7 @@ export interface APIBaseInteraction<Type extends InteractionType, Data> {
/**
* Bitwise set of permissions the app or bot has within the channel the interaction was sent from
*/
app_permissions?: Permissions;
app_permissions: Permissions;
/**
* The selected language of the invoking user
*/
Expand All @@ -135,8 +169,20 @@ export interface APIBaseInteraction<Type extends InteractionType, Data> {
* For monetized apps, any entitlements for the invoking user, representing access to premium SKUs
*/
entitlements: APIEntitlement[];
/**
* Mapping of installation contexts that the interaction was authorized for to related user or guild IDs.
*/
authorizing_integration_owners: APIAuthorizingIntegrationOwnersMap;
/**
* Context where the interaction was triggered from
*/
context?: InteractionContextType;
}

export type APIAuthorizingIntegrationOwnersMap = {
[key in ApplicationIntegrationType]?: Snowflake;
};

export type APIDMInteractionWrapper<Original extends APIBaseInteraction<InteractionType, unknown>> = Omit<
Original,
'guild_id' | 'member'
Expand Down
15 changes: 15 additions & 0 deletions deno/payloads/v10/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type { Permissions, Snowflake } from '../../globals.ts';
import type { LocalizationMap } from '../common.ts';
import type { APIPartialGuild } from './guild.ts';
import type { ApplicationIntegrationType } from './interactions.ts';
import type { OAuth2Scopes } from './oauth2.ts';
import type { APITeam } from './teams.ts';
import type { APIUser } from './user.ts';
Expand Down Expand Up @@ -128,6 +129,12 @@ export interface APIApplication {
* Settings for the application's default in-app authorization link, if enabled
*/
install_params?: APIApplicationInstallParams;
/**
* Default scopes and permissions for each supported installation context. Value for each key is an integration type configuration object
*
* @unstable
*/
integration_types_config?: APIApplicationIntegrationTypesConfigMap;
/**
* The application's default custom authorization link, if enabled
*/
Expand All @@ -139,6 +146,14 @@ export interface APIApplicationInstallParams {
permissions: Permissions;
}

export interface APIApplicationIntegrationTypeConfiguration {
oauth2_install_params?: APIApplicationInstallParams;
}

export type APIApplicationIntegrationTypesConfigMap = {
[key in ApplicationIntegrationType]?: APIApplicationIntegrationTypeConfiguration;
};

/**
* https://discord.com/developers/docs/resources/application#application-object-application-flags
*/
Expand Down
10 changes: 9 additions & 1 deletion deno/payloads/v10/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Permissions, Snowflake } from '../../globals.ts';
import type { APIApplication } from './application.ts';
import type { APIPartialEmoji } from './emoji.ts';
import type { APIGuildMember } from './guild.ts';
import type { APIInteractionDataResolved, APIMessageInteraction } from './interactions.ts';
import type { APIInteractionDataResolved, APIMessageInteraction, APIMessageInteractionMetadata } from './interactions.ts';
import type { APIRole } from './permissions.ts';
import type { APIPoll } from './poll.ts';
import type { APISticker, APIStickerItem } from './sticker.ts';
Expand Down Expand Up @@ -667,8 +667,16 @@ export interface APIMessage {
* See https://discord.com/developers/docs/resources/channel#message-object
*/
referenced_message?: APIMessage | null;
/**
* Sent if the message is sent as a result of an interaction
*
* @unstable
*/
interaction_metadata?: APIMessageInteractionMetadata;
/**
* Sent if the message is a response to an Interaction
*
* @deprecated In favor of `interaction_metadata`
*/
interaction?: APIMessageInteraction;
/**
Expand Down
46 changes: 46 additions & 0 deletions deno/payloads/v9/_interactions/applicationCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export interface APIApplicationCommand {
default_member_permissions: Permissions | null;
/**
* Indicates whether the command is available in DMs with the app, only for globally-scoped commands. By default, commands are visible
*
* @deprecated Use `contexts` instead
*/
dm_permission?: boolean;
/**
Expand All @@ -88,6 +90,18 @@ export interface APIApplicationCommand {
* Indicates whether the command is age-restricted, defaults to `false`
*/
nsfw?: boolean;
/**
* Installation context(s) where the command is available, only for globally-scoped commands. Defaults to `GUILD_INSTALL ([0])`
*
* @unstable
*/
integration_types?: ApplicationIntegrationType[];
/**
* Interaction context(s) where the command can be used, only for globally-scoped commands. By default, all interaction context types included for new commands `[0,1,2]`.
*
* @unstable
*/
contexts?: InteractionContextType[] | null;
/**
* Autoincrementing version identifier updated during substantial record changes
*/
Expand All @@ -103,6 +117,38 @@ export enum ApplicationCommandType {
Message,
}

/**
* https://discord.com/developers/docs/resources/application#application-object-application-integration-types
*/
export enum ApplicationIntegrationType {
/**
* App is installable to servers
*/
GuildInstall = 0,
/**
* App is installable to users
*/
UserInstall = 1,
}

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types
*/
export enum InteractionContextType {
/**
* Interaction can be used within servers
*/
Guild = 0,
/**
* Interaction can be used within DMs with the app's bot user
*/
BotDM = 1,
/**
* Interaction can be used within Group DMs and DMs other than the app's bot user
*/
PrivateChannel = 2,
}

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-data
*/
Expand Down
50 changes: 48 additions & 2 deletions deno/payloads/v9/_interactions/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Permissions, Snowflake } from '../../../globals.ts';
import type { APIRole, LocaleString } from '../../../v9.ts';
import type { APIRole, ApplicationIntegrationType, InteractionContextType, LocaleString } from '../../../v9.ts';
import type {
APIAttachment,
APIChannel,
Expand All @@ -14,6 +14,40 @@ import type { APIEntitlement } from '../monetization.ts';
import type { APIUser } from '../user.ts';
import type { InteractionType } from './responses.ts';

/**
* https://discord.com/developers/docs/resources/channel#message-interaction-metadata-object
*/
export interface APIMessageInteractionMetadata {
/**
* ID of the interaction
*/
id: Snowflake;
/**
* Type of interaction
*/
type: InteractionType;
/**
* User who triggered the interaction
*/
user: APIUser;
/**
* IDs for installation context(s) related to an interaction. Details in Authorizing Integration Owners Object
*/
authorizing_integration_owners: APIAuthorizingIntegrationOwnersMap;
/**
* ID of the original response message, present only on follow-up messages
*/
original_response_message_id?: Snowflake;
/**
* ID of the message that contained interactive component, present only on messages created from component interactions
*/
interacted_message_id?: Snowflake;
/**
* Metadata for the interaction that was used to open the modal, present only on modal submit interactions
*/
triggering_interaction_metadata?: APIMessageInteractionMetadata;
}

export type PartialAPIMessageInteractionGuildMember = Pick<
APIGuildMember,
| 'avatar'
Expand Down Expand Up @@ -122,7 +156,7 @@ export interface APIBaseInteraction<Type extends InteractionType, Data> {
/**
* Bitwise set of permissions the app or bot has within the channel the interaction was sent from
*/
app_permissions?: Permissions;
app_permissions: Permissions;
/**
* The selected language of the invoking user
*/
Expand All @@ -135,8 +169,20 @@ export interface APIBaseInteraction<Type extends InteractionType, Data> {
* For monetized apps, any entitlements for the invoking user, representing access to premium SKUs
*/
entitlements: APIEntitlement[];
/**
* Mapping of installation contexts that the interaction was authorized for to related user or guild IDs.
*/
authorizing_integration_owners: APIAuthorizingIntegrationOwnersMap;
/**
* Context where the interaction was triggered from
*/
context?: InteractionContextType;
}

export type APIAuthorizingIntegrationOwnersMap = {
[key in ApplicationIntegrationType]?: Snowflake;
};

export type APIDMInteractionWrapper<Original extends APIBaseInteraction<InteractionType, unknown>> = Omit<
Original,
'guild_id' | 'member'
Expand Down
15 changes: 15 additions & 0 deletions deno/payloads/v9/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type { Permissions, Snowflake } from '../../globals.ts';
import type { LocalizationMap } from '../common.ts';
import type { APIPartialGuild } from './guild.ts';
import type { ApplicationIntegrationType } from './interactions.ts';
import type { OAuth2Scopes } from './oauth2.ts';
import type { APITeam } from './teams.ts';
import type { APIUser } from './user.ts';
Expand Down Expand Up @@ -128,6 +129,12 @@ export interface APIApplication {
* Settings for the application's default in-app authorization link, if enabled
*/
install_params?: APIApplicationInstallParams;
/**
* Default scopes and permissions for each supported installation context. Value for each key is an integration type configuration object
*
* @unstable
*/
integration_types_config?: APIApplicationIntegrationTypesConfigMap;
/**
* The application's default custom authorization link, if enabled
*/
Expand All @@ -139,6 +146,14 @@ export interface APIApplicationInstallParams {
permissions: Permissions;
}

export interface APIApplicationIntegrationTypeConfiguration {
oauth2_install_params?: APIApplicationInstallParams;
}

export type APIApplicationIntegrationTypesConfigMap = {
[key in ApplicationIntegrationType]?: APIApplicationIntegrationTypeConfiguration;
};

/**
* https://discord.com/developers/docs/resources/application#application-object-application-flags
*/
Expand Down
Loading

0 comments on commit c457b8d

Please sign in to comment.