diff --git a/deno/utils/v10.ts b/deno/utils/v10.ts index ab9c40aa..87928f56 100644 --- a/deno/utils/v10.ts +++ b/deno/utils/v10.ts @@ -5,13 +5,20 @@ import { APIButtonComponent, APIButtonComponentWithCustomId, APIButtonComponentWithURL, + APIChatInputApplicationCommandInteraction, + APIContextMenuInteraction, APIDMInteraction, APIGuildInteraction, APIInteraction, + APIMessageComponentButtonInteraction, APIMessageComponentDMInteraction, APIMessageComponentGuildInteraction, APIMessageComponentInteraction, + APIMessageComponentSelectMenuInteraction, + ApplicationCommandType, ButtonStyle, + ComponentType, + InteractionType, } from '../payloads/v10/mod.ts'; // Interactions @@ -101,3 +108,64 @@ export function isLinkButton(component: APIButtonComponent): component is APIBut export function isInteractionButton(component: APIButtonComponent): component is APIButtonComponentWithCustomId { return component.style !== ButtonStyle.Link; } + +// Message Components + +/** + * A type-guard check for message component interactions + * @param interaction The interaction to check against + * @returns A boolean that indicates if the interaction is a message component + */ +export function isMessageComponentInteraction( + interaction: APIInteraction, +): interaction is APIMessageComponentInteraction { + return interaction.type === InteractionType.MessageComponent; +} + +/** + * A type-guard check for button message component interactions + * @param interaction The message component interaction to check against + * @returns A boolean that indicates if the message component is a button + */ +export function isMessageComponentButtonInteraction( + interaction: APIMessageComponentInteraction, +): interaction is APIMessageComponentButtonInteraction { + return interaction.data.component_type === ComponentType.Button; +} + +/** + * A type-guard check for select menu message component interactions + * @param interaction The message component interaction to check against + * @returns A boolean that indicates if the message component is a select menu + */ +export function isMessageComponentSelectMenuInteraction( + interaction: APIMessageComponentInteraction, +): interaction is APIMessageComponentSelectMenuInteraction { + return interaction.data.component_type === ComponentType.SelectMenu; +} + +// Application Commands + +/** + * A type-guard check for chat input application commands. + * @param interaction The interaction to check against + * @returns A boolean that indicates if the interaction is a chat input application command + */ +export function isChatInputApplicationCommandInteraction( + interaction: APIApplicationCommandInteraction, +): interaction is APIChatInputApplicationCommandInteraction { + return interaction.data.type === ApplicationCommandType.ChatInput; +} + +/** + * A type-guard check for context menu application commands. + * @param interaction The interaction to check against + * @returns A boolean that indicates if the interaction is a context menu application command + */ +export function isContextMenuApplicationCommandInteraction( + interaction: APIApplicationCommandInteraction, +): interaction is APIContextMenuInteraction { + return ( + interaction.data.type === ApplicationCommandType.Message || interaction.data.type === ApplicationCommandType.User + ); +} diff --git a/deno/utils/v9.ts b/deno/utils/v9.ts index fc87d081..a1a03fce 100644 --- a/deno/utils/v9.ts +++ b/deno/utils/v9.ts @@ -5,13 +5,20 @@ import { APIButtonComponent, APIButtonComponentWithCustomId, APIButtonComponentWithURL, + APIChatInputApplicationCommandInteraction, + APIContextMenuInteraction, APIDMInteraction, APIGuildInteraction, APIInteraction, + APIMessageComponentButtonInteraction, APIMessageComponentDMInteraction, APIMessageComponentGuildInteraction, APIMessageComponentInteraction, + APIMessageComponentSelectMenuInteraction, + ApplicationCommandType, ButtonStyle, + ComponentType, + InteractionType, } from '../payloads/v9/mod.ts'; // Interactions @@ -101,3 +108,64 @@ export function isLinkButton(component: APIButtonComponent): component is APIBut export function isInteractionButton(component: APIButtonComponent): component is APIButtonComponentWithCustomId { return component.style !== ButtonStyle.Link; } + +// Message Components + +/** + * A type-guard check for message component interactions + * @param interaction The interaction to check against + * @returns A boolean that indicates if the interaction is a message component + */ +export function isMessageComponentInteraction( + interaction: APIInteraction, +): interaction is APIMessageComponentInteraction { + return interaction.type === InteractionType.MessageComponent; +} + +/** + * A type-guard check for button message component interactions + * @param interaction The message component interaction to check against + * @returns A boolean that indicates if the message component is a button + */ +export function isMessageComponentButtonInteraction( + interaction: APIMessageComponentInteraction, +): interaction is APIMessageComponentButtonInteraction { + return interaction.data.component_type === ComponentType.Button; +} + +/** + * A type-guard check for select menu message component interactions + * @param interaction The message component interaction to check against + * @returns A boolean that indicates if the message component is a select menu + */ +export function isMessageComponentSelectMenuInteraction( + interaction: APIMessageComponentInteraction, +): interaction is APIMessageComponentSelectMenuInteraction { + return interaction.data.component_type === ComponentType.SelectMenu; +} + +// Application Commands + +/** + * A type-guard check for chat input application commands. + * @param interaction The interaction to check against + * @returns A boolean that indicates if the interaction is a chat input application command + */ +export function isChatInputApplicationCommandInteraction( + interaction: APIApplicationCommandInteraction, +): interaction is APIChatInputApplicationCommandInteraction { + return interaction.data.type === ApplicationCommandType.ChatInput; +} + +/** + * A type-guard check for context menu application commands. + * @param interaction The interaction to check against + * @returns A boolean that indicates if the interaction is a context menu application command + */ +export function isContextMenuApplicationCommandInteraction( + interaction: APIApplicationCommandInteraction, +): interaction is APIContextMenuInteraction { + return ( + interaction.data.type === ApplicationCommandType.Message || interaction.data.type === ApplicationCommandType.User + ); +} diff --git a/utils/v10.ts b/utils/v10.ts index a21ced85..ee9fd305 100644 --- a/utils/v10.ts +++ b/utils/v10.ts @@ -5,13 +5,20 @@ import { APIButtonComponent, APIButtonComponentWithCustomId, APIButtonComponentWithURL, + APIChatInputApplicationCommandInteraction, + APIContextMenuInteraction, APIDMInteraction, APIGuildInteraction, APIInteraction, + APIMessageComponentButtonInteraction, APIMessageComponentDMInteraction, APIMessageComponentGuildInteraction, APIMessageComponentInteraction, + APIMessageComponentSelectMenuInteraction, + ApplicationCommandType, ButtonStyle, + ComponentType, + InteractionType, } from '../payloads/v10/index'; // Interactions @@ -101,3 +108,64 @@ export function isLinkButton(component: APIButtonComponent): component is APIBut export function isInteractionButton(component: APIButtonComponent): component is APIButtonComponentWithCustomId { return component.style !== ButtonStyle.Link; } + +// Message Components + +/** + * A type-guard check for message component interactions + * @param interaction The interaction to check against + * @returns A boolean that indicates if the interaction is a message component + */ +export function isMessageComponentInteraction( + interaction: APIInteraction, +): interaction is APIMessageComponentInteraction { + return interaction.type === InteractionType.MessageComponent; +} + +/** + * A type-guard check for button message component interactions + * @param interaction The message component interaction to check against + * @returns A boolean that indicates if the message component is a button + */ +export function isMessageComponentButtonInteraction( + interaction: APIMessageComponentInteraction, +): interaction is APIMessageComponentButtonInteraction { + return interaction.data.component_type === ComponentType.Button; +} + +/** + * A type-guard check for select menu message component interactions + * @param interaction The message component interaction to check against + * @returns A boolean that indicates if the message component is a select menu + */ +export function isMessageComponentSelectMenuInteraction( + interaction: APIMessageComponentInteraction, +): interaction is APIMessageComponentSelectMenuInteraction { + return interaction.data.component_type === ComponentType.SelectMenu; +} + +// Application Commands + +/** + * A type-guard check for chat input application commands. + * @param interaction The interaction to check against + * @returns A boolean that indicates if the interaction is a chat input application command + */ +export function isChatInputApplicationCommandInteraction( + interaction: APIApplicationCommandInteraction, +): interaction is APIChatInputApplicationCommandInteraction { + return interaction.data.type === ApplicationCommandType.ChatInput; +} + +/** + * A type-guard check for context menu application commands. + * @param interaction The interaction to check against + * @returns A boolean that indicates if the interaction is a context menu application command + */ +export function isContextMenuApplicationCommandInteraction( + interaction: APIApplicationCommandInteraction, +): interaction is APIContextMenuInteraction { + return ( + interaction.data.type === ApplicationCommandType.Message || interaction.data.type === ApplicationCommandType.User + ); +} diff --git a/utils/v9.ts b/utils/v9.ts index ff03cb52..21f0ba0b 100644 --- a/utils/v9.ts +++ b/utils/v9.ts @@ -5,13 +5,20 @@ import { APIButtonComponent, APIButtonComponentWithCustomId, APIButtonComponentWithURL, + APIChatInputApplicationCommandInteraction, + APIContextMenuInteraction, APIDMInteraction, APIGuildInteraction, APIInteraction, + APIMessageComponentButtonInteraction, APIMessageComponentDMInteraction, APIMessageComponentGuildInteraction, APIMessageComponentInteraction, + APIMessageComponentSelectMenuInteraction, + ApplicationCommandType, ButtonStyle, + ComponentType, + InteractionType, } from '../payloads/v9/index'; // Interactions @@ -101,3 +108,64 @@ export function isLinkButton(component: APIButtonComponent): component is APIBut export function isInteractionButton(component: APIButtonComponent): component is APIButtonComponentWithCustomId { return component.style !== ButtonStyle.Link; } + +// Message Components + +/** + * A type-guard check for message component interactions + * @param interaction The interaction to check against + * @returns A boolean that indicates if the interaction is a message component + */ +export function isMessageComponentInteraction( + interaction: APIInteraction, +): interaction is APIMessageComponentInteraction { + return interaction.type === InteractionType.MessageComponent; +} + +/** + * A type-guard check for button message component interactions + * @param interaction The message component interaction to check against + * @returns A boolean that indicates if the message component is a button + */ +export function isMessageComponentButtonInteraction( + interaction: APIMessageComponentInteraction, +): interaction is APIMessageComponentButtonInteraction { + return interaction.data.component_type === ComponentType.Button; +} + +/** + * A type-guard check for select menu message component interactions + * @param interaction The message component interaction to check against + * @returns A boolean that indicates if the message component is a select menu + */ +export function isMessageComponentSelectMenuInteraction( + interaction: APIMessageComponentInteraction, +): interaction is APIMessageComponentSelectMenuInteraction { + return interaction.data.component_type === ComponentType.SelectMenu; +} + +// Application Commands + +/** + * A type-guard check for chat input application commands. + * @param interaction The interaction to check against + * @returns A boolean that indicates if the interaction is a chat input application command + */ +export function isChatInputApplicationCommandInteraction( + interaction: APIApplicationCommandInteraction, +): interaction is APIChatInputApplicationCommandInteraction { + return interaction.data.type === ApplicationCommandType.ChatInput; +} + +/** + * A type-guard check for context menu application commands. + * @param interaction The interaction to check against + * @returns A boolean that indicates if the interaction is a context menu application command + */ +export function isContextMenuApplicationCommandInteraction( + interaction: APIApplicationCommandInteraction, +): interaction is APIContextMenuInteraction { + return ( + interaction.data.type === ApplicationCommandType.Message || interaction.data.type === ApplicationCommandType.User + ); +}