Skip to content

Commit

Permalink
refactor: split interaction metadata objects (#1129)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdanialraza authored Nov 19, 2024
1 parent f5ebb20 commit 7debb55
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 28 deletions.
48 changes: 41 additions & 7 deletions deno/payloads/v10/_interactions/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,69 @@ import type { InteractionType } from './responses.ts';
/**
* https://discord.com/developers/docs/resources/channel#message-interaction-metadata-object
*/
export interface APIMessageInteractionMetadata {
export type APIMessageInteractionMetadata =
| APIApplicationCommandInteractionMetadata
| APIMessageComponentInteractionMetadata
| APIModalSubmitInteractionMetadata;

interface APIBaseInteractionMetadata<Type extends InteractionType> {
/**
* ID of the interaction
*/
id: Snowflake;
/**
* Type of interaction
*/
type: InteractionType;
type: Type;
/**
* User who triggered the interaction
*/
user: APIUser;
/**
* IDs for installation context(s) related to an interaction. Details in Authorizing Integration Owners Object
* IDs for installation context(s) related to an interaction
*/
authorizing_integration_owners: APIAuthorizingIntegrationOwnersMap;
/**
* ID of the original response message, present only on follow-up messages
*/
original_response_message_id?: Snowflake;
}

/**
* https://discord.com/developers/docs/resources/message#message-interaction-metadata-object-application-command-interaction-metadata-structure
*/
export interface APIApplicationCommandInteractionMetadata
extends APIBaseInteractionMetadata<InteractionType.ApplicationCommand> {
/**
* ID of the message that contained interactive component, present only on messages created from component interactions
* The user the command was run on, present only on user commands interactions
*/
interacted_message_id?: Snowflake;
target_user?: APIUser;
/**
* The ID of the message the command was run on, present only on message command interactions.
* The original response message will also have `message_reference` and `referenced_message` pointing to this message.
*/
target_message_id?: Snowflake;
}

/**
* https://discord.com/developers/docs/resources/message#message-interaction-metadata-object-message-command-interaction-metadata-structure
*/
export interface APIMessageComponentInteractionMetadata
extends APIBaseInteractionMetadata<InteractionType.MessageComponent> {
/**
* ID of the message that contained the interactive component
*/
interacted_message_id: Snowflake;
}

/**
* https://discord.com/developers/docs/resources/message#message-interaction-metadata-object-modal-submit-interaction-metadata-structure
*/
export interface APIModalSubmitInteractionMetadata extends APIBaseInteractionMetadata<InteractionType.ModalSubmit> {
/**
* Metadata for the interaction that was used to open the modal, present only on modal submit interactions
* Metadata for the interaction that was used to open the modal
*/
triggering_interaction_metadata?: APIMessageInteractionMetadata;
triggering_interaction_metadata: APIApplicationCommandInteractionMetadata | APIMessageComponentInteractionMetadata;
}

export type PartialAPIMessageInteractionGuildMember = Pick<
Expand Down
51 changes: 44 additions & 7 deletions deno/payloads/v9/_interactions/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,72 @@ import type { InteractionType } from './responses.ts';
/**
* https://discord.com/developers/docs/resources/channel#message-interaction-metadata-object
*/
export interface APIMessageInteractionMetadata {
export type APIMessageInteractionMetadata =
| APIApplicationCommandInteractionMetadata
| APIMessageComponentInteractionMetadata
| APIModalSubmitInteractionMetadata;

/**
* https://discord.com/developers/docs/resources/channel#message-interaction-metadata-object
*/
interface APIBaseInteractionMetadata<Type extends InteractionType> {
/**
* ID of the interaction
*/
id: Snowflake;
/**
* Type of interaction
*/
type: InteractionType;
type: Type;
/**
* User who triggered the interaction
*/
user: APIUser;
/**
* IDs for installation context(s) related to an interaction. Details in Authorizing Integration Owners Object
* IDs for installation context(s) related to an interaction
*/
authorizing_integration_owners: APIAuthorizingIntegrationOwnersMap;
/**
* ID of the original response message, present only on follow-up messages
*/
original_response_message_id?: Snowflake;
}

/**
* https://discord.com/developers/docs/resources/message#message-interaction-metadata-object-application-command-interaction-metadata-structure
*/
export interface APIApplicationCommandInteractionMetadata
extends APIBaseInteractionMetadata<InteractionType.ApplicationCommand> {
/**
* The user the command was run on, present only on user commands interactions
*/
target_user?: APIUser;
/**
* ID of the message that contained interactive component, present only on messages created from component interactions
* The ID of the message the command was run on, present only on message command interactions.
* The original response message will also have `message_reference` and `referenced_message` pointing to this message.
*/
interacted_message_id?: Snowflake;
target_message_id?: Snowflake;
}

/**
* https://discord.com/developers/docs/resources/message#message-interaction-metadata-object-message-command-interaction-metadata-structure
*/
export interface APIMessageComponentInteractionMetadata
extends APIBaseInteractionMetadata<InteractionType.MessageComponent> {
/**
* ID of the message that contained the interactive component
*/
interacted_message_id: Snowflake;
}

/**
* https://discord.com/developers/docs/resources/message#message-interaction-metadata-object-modal-submit-interaction-metadata-structure
*/
export interface APIModalSubmitInteractionMetadata extends APIBaseInteractionMetadata<InteractionType.ModalSubmit> {
/**
* Metadata for the interaction that was used to open the modal, present only on modal submit interactions
* Metadata for the interaction that was used to open the modal
*/
triggering_interaction_metadata?: APIMessageInteractionMetadata;
triggering_interaction_metadata: APIApplicationCommandInteractionMetadata | APIMessageComponentInteractionMetadata;
}

export type PartialAPIMessageInteractionGuildMember = Pick<
Expand Down
48 changes: 41 additions & 7 deletions payloads/v10/_interactions/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,69 @@ import type { InteractionType } from './responses';
/**
* https://discord.com/developers/docs/resources/channel#message-interaction-metadata-object
*/
export interface APIMessageInteractionMetadata {
export type APIMessageInteractionMetadata =
| APIApplicationCommandInteractionMetadata
| APIMessageComponentInteractionMetadata
| APIModalSubmitInteractionMetadata;

interface APIBaseInteractionMetadata<Type extends InteractionType> {
/**
* ID of the interaction
*/
id: Snowflake;
/**
* Type of interaction
*/
type: InteractionType;
type: Type;
/**
* User who triggered the interaction
*/
user: APIUser;
/**
* IDs for installation context(s) related to an interaction. Details in Authorizing Integration Owners Object
* IDs for installation context(s) related to an interaction
*/
authorizing_integration_owners: APIAuthorizingIntegrationOwnersMap;
/**
* ID of the original response message, present only on follow-up messages
*/
original_response_message_id?: Snowflake;
}

/**
* https://discord.com/developers/docs/resources/message#message-interaction-metadata-object-application-command-interaction-metadata-structure
*/
export interface APIApplicationCommandInteractionMetadata
extends APIBaseInteractionMetadata<InteractionType.ApplicationCommand> {
/**
* ID of the message that contained interactive component, present only on messages created from component interactions
* The user the command was run on, present only on user commands interactions
*/
interacted_message_id?: Snowflake;
target_user?: APIUser;
/**
* The ID of the message the command was run on, present only on message command interactions.
* The original response message will also have `message_reference` and `referenced_message` pointing to this message.
*/
target_message_id?: Snowflake;
}

/**
* https://discord.com/developers/docs/resources/message#message-interaction-metadata-object-message-command-interaction-metadata-structure
*/
export interface APIMessageComponentInteractionMetadata
extends APIBaseInteractionMetadata<InteractionType.MessageComponent> {
/**
* ID of the message that contained the interactive component
*/
interacted_message_id: Snowflake;
}

/**
* https://discord.com/developers/docs/resources/message#message-interaction-metadata-object-modal-submit-interaction-metadata-structure
*/
export interface APIModalSubmitInteractionMetadata extends APIBaseInteractionMetadata<InteractionType.ModalSubmit> {
/**
* Metadata for the interaction that was used to open the modal, present only on modal submit interactions
* Metadata for the interaction that was used to open the modal
*/
triggering_interaction_metadata?: APIMessageInteractionMetadata;
triggering_interaction_metadata: APIApplicationCommandInteractionMetadata | APIMessageComponentInteractionMetadata;
}

export type PartialAPIMessageInteractionGuildMember = Pick<
Expand Down
51 changes: 44 additions & 7 deletions payloads/v9/_interactions/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,72 @@ import type { InteractionType } from './responses';
/**
* https://discord.com/developers/docs/resources/channel#message-interaction-metadata-object
*/
export interface APIMessageInteractionMetadata {
export type APIMessageInteractionMetadata =
| APIApplicationCommandInteractionMetadata
| APIMessageComponentInteractionMetadata
| APIModalSubmitInteractionMetadata;

/**
* https://discord.com/developers/docs/resources/channel#message-interaction-metadata-object
*/
interface APIBaseInteractionMetadata<Type extends InteractionType> {
/**
* ID of the interaction
*/
id: Snowflake;
/**
* Type of interaction
*/
type: InteractionType;
type: Type;
/**
* User who triggered the interaction
*/
user: APIUser;
/**
* IDs for installation context(s) related to an interaction. Details in Authorizing Integration Owners Object
* IDs for installation context(s) related to an interaction
*/
authorizing_integration_owners: APIAuthorizingIntegrationOwnersMap;
/**
* ID of the original response message, present only on follow-up messages
*/
original_response_message_id?: Snowflake;
}

/**
* https://discord.com/developers/docs/resources/message#message-interaction-metadata-object-application-command-interaction-metadata-structure
*/
export interface APIApplicationCommandInteractionMetadata
extends APIBaseInteractionMetadata<InteractionType.ApplicationCommand> {
/**
* The user the command was run on, present only on user commands interactions
*/
target_user?: APIUser;
/**
* ID of the message that contained interactive component, present only on messages created from component interactions
* The ID of the message the command was run on, present only on message command interactions.
* The original response message will also have `message_reference` and `referenced_message` pointing to this message.
*/
interacted_message_id?: Snowflake;
target_message_id?: Snowflake;
}

/**
* https://discord.com/developers/docs/resources/message#message-interaction-metadata-object-message-command-interaction-metadata-structure
*/
export interface APIMessageComponentInteractionMetadata
extends APIBaseInteractionMetadata<InteractionType.MessageComponent> {
/**
* ID of the message that contained the interactive component
*/
interacted_message_id: Snowflake;
}

/**
* https://discord.com/developers/docs/resources/message#message-interaction-metadata-object-modal-submit-interaction-metadata-structure
*/
export interface APIModalSubmitInteractionMetadata extends APIBaseInteractionMetadata<InteractionType.ModalSubmit> {
/**
* Metadata for the interaction that was used to open the modal, present only on modal submit interactions
* Metadata for the interaction that was used to open the modal
*/
triggering_interaction_metadata?: APIMessageInteractionMetadata;
triggering_interaction_metadata: APIApplicationCommandInteractionMetadata | APIMessageComponentInteractionMetadata;
}

export type PartialAPIMessageInteractionGuildMember = Pick<
Expand Down

0 comments on commit 7debb55

Please sign in to comment.