From d8f2e77a73a0a6eca7e873b876fa37fe2eae936b Mon Sep 17 00:00:00 2001 From: Daniel <46201432+TechGeekGamer@users.noreply.github.com> Date: Sun, 22 May 2022 15:48:30 -0700 Subject: [PATCH] Add use_modal param to speak command --- src/commands.ts | 6 +++++ src/commands/speak.ts | 43 +++++++++++++++++++++++++++++++++ src/modals/speak_large_input.ts | 39 ++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 src/modals/speak_large_input.ts diff --git a/src/commands.ts b/src/commands.ts index c1975c1..5599d71 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -546,6 +546,12 @@ const utilityCommands: ApplicationCommandOptionData[] = [ description: "Whether or not to have pings (allowed_mentions)", required: false, }, + { + type: "BOOLEAN", + name: "use_modal", + description: "Use Modal to send text instead of provided text param", + required: false, + }, ], }, ]; diff --git a/src/commands/speak.ts b/src/commands/speak.ts index 8c1f574..e7339ad 100644 --- a/src/commands/speak.ts +++ b/src/commands/speak.ts @@ -9,6 +9,49 @@ export default new Command({ let text = interaction.options.getString("text"); let disable_ping: boolean = interaction.options.getBoolean("disable_ping", false) || false; + let use_modal: boolean = + interaction.options.getBoolean("use_modal", false) || false; + + if (use_modal) + return ( + // @ts-expect-error + interaction.client.api + // @ts-expect-error + .interactions(interaction.id)(interaction.token) + .callback.post({ + data: { + type: 9, + data: { + components: [ + { + type: 1, + components: [ + { + type: 4, + custom_id: "text", + style: 2, + label: "Text", + }, + ], + }, + { + type: 1, + components: [ + { + type: 4, + custom_id: "mentions_disabled", + style: 2, + label: "Disable mentions? true/false", + }, + ], + }, + ], + title: "Speak: Large Input", + custom_id: "speak_large_input", + }, + }, + }) + ); let responseMessage: MessageOptions = { content: text, diff --git a/src/modals/speak_large_input.ts b/src/modals/speak_large_input.ts new file mode 100644 index 0000000..f8a0a99 --- /dev/null +++ b/src/modals/speak_large_input.ts @@ -0,0 +1,39 @@ +import { MessageOptions, ThreadChannel } from "discord.js"; +import { config } from "../../config"; +import ModalCommand from "../classes/ModalCommand"; + +export default new ModalCommand({ + customId: "speak_large_input", + staffOnly: true, + async execute(interaction, client) { + let messageText = + interaction.data.components[0]?.components[0]?.value || ""; + let disable_ping = Boolean( + interaction.data.components[1]?.components[0]?.value || false + ); + // @ts-expect-error + client.api + //@ts-expect-error + .interactions(interaction.id)(interaction.token) + .callback.post({ + data: { + type: 4, + data: { + content: `Sent!`, + flags: 64, + }, + }, + }); + let channel = client.channels.cache.get(interaction.channel_id); + if (channel.isText()) { + let responseMessage: MessageOptions = { + content: messageText, + }; + if (disable_ping) + responseMessage.allowedMentions = { + parse: [], + }; + channel.send(responseMessage); + } + }, +});