From bcdec3155beb271467b88df22cdcdc5d8af26f67 Mon Sep 17 00:00:00 2001 From: Rafael Oliveira <56204853+RafDevX@users.noreply.github.com> Date: Sun, 16 Oct 2022 16:17:00 +0100 Subject: [PATCH] Add Just Ask context menu command (#102) --- src/modules/misc.ts | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/modules/misc.ts b/src/modules/misc.ts index dde959c..5d68fe2 100644 --- a/src/modules/misc.ts +++ b/src/modules/misc.ts @@ -86,7 +86,14 @@ export function provideCommands(): CommandDescriptor[] { .setDescription( 'Send a link to the "Don\'t ask to ask" website' ), - handler: handleJustAskCommand, + handler: handleJustAskSlashCommand, + permission: CommandPermission.Public, + }, + { + builder: new Builders.ContextMenuCommandBuilder() + .setName("Just Ask") + .setType(Discord.ApplicationCommandType.Message), + handler: handleJustAskContextMenuCommand, permission: CommandPermission.Public, }, { @@ -204,11 +211,14 @@ export async function handleWhoSaidCommand( } } -export async function handleJustAskCommand( - interaction: Discord.ChatInputCommandInteraction +export async function sendJustAsk( + interaction: Discord.CommandInteraction, + sender: ( + ...args: Parameters + ) => Promise // to allow optional chaining (?.) ): Promise { try { - await interaction.channel?.send("https://dontasktoask.com/"); + await sender("https://dontasktoask.com/"); await interaction.editReply(utils.CheckMarkEmoji + "Sent"); logger.info({ member: interaction.member }, "Used don't ask to ask"); } catch (e) { @@ -217,6 +227,28 @@ export async function handleJustAskCommand( } } +export async function handleJustAskSlashCommand( + interaction: Discord.ChatInputCommandInteraction +): Promise { + if (interaction.channel) { + await sendJustAsk( + interaction, + async (...args) => await interaction.channel?.send(...args) + ); + } +} + +export async function handleJustAskContextMenuCommand( + interaction: Discord.ContextMenuCommandInteraction +): Promise { + if (interaction.isMessageContextMenuCommand()) { + await sendJustAsk( + interaction, + async (...args) => await interaction.targetMessage?.reply(...args) + ); + } +} + export async function handleMigrateMembersWithRole( interaction: Discord.ChatInputCommandInteraction ): Promise {