Skip to content

Commit

Permalink
Add Just Ask context menu command (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
RafDevX authored Oct 16, 2022
1 parent 8b237cd commit bcdec31
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions src/modules/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
{
Expand Down Expand Up @@ -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<typeof Discord.Message.prototype.reply>
) => Promise<unknown> // to allow optional chaining (?.)
): Promise<void> {
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) {
Expand All @@ -217,6 +227,28 @@ export async function handleJustAskCommand(
}
}

export async function handleJustAskSlashCommand(
interaction: Discord.ChatInputCommandInteraction
): Promise<void> {
if (interaction.channel) {
await sendJustAsk(
interaction,
async (...args) => await interaction.channel?.send(...args)
);
}
}

export async function handleJustAskContextMenuCommand(
interaction: Discord.ContextMenuCommandInteraction
): Promise<void> {
if (interaction.isMessageContextMenuCommand()) {
await sendJustAsk(
interaction,
async (...args) => await interaction.targetMessage?.reply(...args)
);
}
}

export async function handleMigrateMembersWithRole(
interaction: Discord.ChatInputCommandInteraction
): Promise<void> {
Expand Down

0 comments on commit bcdec31

Please sign in to comment.