From 95c5c6bc9d6bdead72258f730d12055da3ba0f24 Mon Sep 17 00:00:00 2001 From: ITOH Date: Fri, 3 Dec 2021 23:07:51 +0100 Subject: [PATCH] feat modals --- .../interactions/sendInteractionResponse.ts | 2 ++ src/transformers/interaction.ts | 4 +++ .../applicationCommandCallbackData.ts | 27 ++++++++++++++++++- .../applicationCommandInteractionData.ts | 4 ++- .../interactions/interactionResponseTypes.ts | 8 +++--- src/types/interactions/interactionTypes.ts | 7 ++--- src/types/messages/components/actionRow.ts | 3 ++- .../messages/components/inputTextComponent.ts | 20 ++++++++++++++ .../components/messageComponentTypes.ts | 6 +++-- src/types/messages/components/textStyles.ts | 6 +++++ 10 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 src/types/messages/components/inputTextComponent.ts create mode 100644 src/types/messages/components/textStyles.ts diff --git a/src/helpers/interactions/sendInteractionResponse.ts b/src/helpers/interactions/sendInteractionResponse.ts index af99c741a..a3f549495 100644 --- a/src/helpers/interactions/sendInteractionResponse.ts +++ b/src/helpers/interactions/sendInteractionResponse.ts @@ -85,6 +85,8 @@ export async function sendInteractionResponse( roles: options.data.allowedMentions!.roles?.map((id) => id.toString()), }, file: options.data.file, + custom_id: options.data.customId, + title: options.data.title, components: options.data.components?.map((component) => ({ type: component.type, components: component.components.map((subcomponent) => { diff --git a/src/transformers/interaction.ts b/src/transformers/interaction.ts index 3ca707f9d..402fbdee0 100644 --- a/src/transformers/interaction.ts +++ b/src/transformers/interaction.ts @@ -9,6 +9,7 @@ import { InteractionDataResolved, MessageComponentTypes, InteractionDataOption, + MessageComponents, } from "../types/mod.ts"; import { SnakeCasedPropertiesDeep } from "../types/util.ts"; import { Collection } from "../util/collection.ts"; @@ -41,6 +42,7 @@ export function transformInteraction(bot: Bot, payload: SnakeCasedPropertiesDeep ? { componentType: payload.data.component_type, customId: payload.data.custom_id, + components: payload.data.components, values: payload.data.values, id: payload.data.id ? bot.transformers.snowflake(payload.data.id) : undefined, name: payload.data.name, @@ -152,6 +154,8 @@ export interface DiscordenoInteraction { componentType?: MessageComponentTypes; /** The custom id provided for this component. */ customId?: string; + /** The components if its a Modal Submit interaction. */ + components?: MessageComponents; /** The values chosen by the user. */ values?: string[]; /** The Id of the invoked command */ diff --git a/src/types/interactions/commands/applicationCommandCallbackData.ts b/src/types/interactions/commands/applicationCommandCallbackData.ts index caa741d9a..b604376e1 100644 --- a/src/types/interactions/commands/applicationCommandCallbackData.ts +++ b/src/types/interactions/commands/applicationCommandCallbackData.ts @@ -1,7 +1,32 @@ +import { FileContent } from "../../discordeno/fileContent.ts"; +import { Embed } from "../../embeds/embed.ts"; +import { AllowedMentions } from "../../messages/allowedMentions.ts"; +import { MessageComponents } from "../../messages/components/messageComponents.ts"; import { CreateMessage } from "../../messages/createMessage.ts"; /** https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionapplicationcommandcallbackdata */ -export interface InteractionApplicationCommandCallbackData extends Omit { +export interface InteractionApplicationCommandCallbackData { + /** The message contents (up to 2000 characters) */ + content?: string; + /** true if this is a TTS message */ + tts?: boolean; + /** Embedded `rich` content (up to 6000 characters) */ + embeds?: Embed[]; + /** Allowed mentions for the message */ + allowedMentions?: Omit & { + /** Array of role_ids to mention (Max size of 100) */ + roles?: bigint[]; + /** Array of user_ids to mention (Max size of 100) */ + users?: bigint[]; + }; + /** The contents of the file being sent */ + file?: FileContent | FileContent[]; + /** The customId you want to use for this modal response. */ + customId?: string; + /** The title you want to use for this modal response. */ + title?: string; + /** The components you would like to have sent in this message */ + components?: MessageComponents; /** Set to `64` to make your response ephemeral */ flags?: number; } diff --git a/src/types/interactions/commands/applicationCommandInteractionData.ts b/src/types/interactions/commands/applicationCommandInteractionData.ts index 42dae700a..9f91ce1db 100644 --- a/src/types/interactions/commands/applicationCommandInteractionData.ts +++ b/src/types/interactions/commands/applicationCommandInteractionData.ts @@ -1,4 +1,4 @@ -import { Message, User, Role, Channel, MessageComponentTypes } from "../../mod.ts"; +import { Message, User, Role, Channel, MessageComponentTypes, MessageComponents } from "../../mod.ts"; import { InteractionGuildMember } from "../interactionGuildMember.ts"; import { InteractionDataOption } from "./applicationCommandInteractionDataOption.ts"; @@ -7,6 +7,8 @@ export interface InteractionData { componentType?: MessageComponentTypes; /** The custom id provided for this component. */ customId?: string; + /** The components if its a Modal Submit interaction. */ + components?: MessageComponents; /** The values chosen by the user. */ values?: string[]; /** The Id of the invoked command */ diff --git a/src/types/interactions/interactionResponseTypes.ts b/src/types/interactions/interactionResponseTypes.ts index f1db5aacc..c7484ad70 100644 --- a/src/types/interactions/interactionResponseTypes.ts +++ b/src/types/interactions/interactionResponseTypes.ts @@ -7,9 +7,11 @@ export enum InteractionResponseTypes { /** ACK an interaction and edit a response later, the user sees a loading state */ DeferredChannelMessageWithSource = 5, /** For components, ACK an interaction and edit the original message later; the user does not see a loading state */ - DeferredUpdateMessage, + DeferredUpdateMessage = 6, /** For components, edit the message the component was attached to */ - UpdateMessage, + UpdateMessage = 7, /** For Application Command Options, send an autocomplete result */ - ApplicationCommandAutocompleteResult, + ApplicationCommandAutocompleteResult = 8, + /** For Command or Component interactions, send a Modal response */ + Modal = 9, } diff --git a/src/types/interactions/interactionTypes.ts b/src/types/interactions/interactionTypes.ts index 6ebf2b674..6148d35fc 100644 --- a/src/types/interactions/interactionTypes.ts +++ b/src/types/interactions/interactionTypes.ts @@ -1,7 +1,8 @@ /** https://discord.com/developers/docs/interactions/slash-commands#interaction-interactiontype */ export enum InteractionTypes { Ping = 1, - ApplicationCommand, - MessageComponent, - ApplicationCommandAutocomplete, + ApplicationCommand = 2, + MessageComponent = 3, + ApplicationCommandAutocomplete = 4, + ModalSubmit = 5, } diff --git a/src/types/messages/components/actionRow.ts b/src/types/messages/components/actionRow.ts index 5b592d2e2..5196050fc 100644 --- a/src/types/messages/components/actionRow.ts +++ b/src/types/messages/components/actionRow.ts @@ -1,4 +1,5 @@ import { ButtonComponent } from "./buttonComponent.ts"; +import { InputTextComponent } from "./inputTextComponent.ts"; import { SelectMenuComponent } from "./selectMenu.ts"; /** https://discord.com/developers/docs/interactions/message-components#actionrow */ @@ -7,7 +8,7 @@ export interface ActionRow { type: 1; /** The components in this row */ components: - | [SelectMenuComponent | ButtonComponent] + | [SelectMenuComponent | ButtonComponent | InputTextComponent] | [ButtonComponent, ButtonComponent] | [ButtonComponent, ButtonComponent, ButtonComponent] | [ButtonComponent, ButtonComponent, ButtonComponent, ButtonComponent] diff --git a/src/types/messages/components/inputTextComponent.ts b/src/types/messages/components/inputTextComponent.ts new file mode 100644 index 000000000..1e3520e18 --- /dev/null +++ b/src/types/messages/components/inputTextComponent.ts @@ -0,0 +1,20 @@ +import { MessageComponentTypes } from "./messageComponentTypes.ts"; +import { TextStyles } from "./textStyles.ts"; + +// TODO: docs link +export interface InputTextComponent { + /** InputText Component is of type 3 */ + type: MessageComponentTypes.InputText; + /** The style of the InputText */ + style: TextStyles; + /** The customId of the InputText */ + customId: string; + /** The label of the InputText */ + label: string; + /** The placeholder of the InputText */ + placeholder?: string; + /** The minimum length of the text the user has to provide */ + minLength?: number; + /** The maximum length of the text the user has to provide */ + maxLength?: number; +} diff --git a/src/types/messages/components/messageComponentTypes.ts b/src/types/messages/components/messageComponentTypes.ts index 0f329c631..d1f04df1b 100644 --- a/src/types/messages/components/messageComponentTypes.ts +++ b/src/types/messages/components/messageComponentTypes.ts @@ -3,7 +3,9 @@ export enum MessageComponentTypes { /** A row of components at the bottom of a message */ ActionRow = 1, /** A button! */ - Button, + Button = 2, /** A select menu. */ - SelectMenu, + SelectMenu = 3, + /** An Input Text. */ + InputText = 4, } diff --git a/src/types/messages/components/textStyles.ts b/src/types/messages/components/textStyles.ts new file mode 100644 index 000000000..54ab43c7b --- /dev/null +++ b/src/types/messages/components/textStyles.ts @@ -0,0 +1,6 @@ +export enum TextStyles { + /** Intended for short single-line text */ + Short = 1, + /** Intended for much longer inputs */ + Paragraph = 2, +}