Skip to content

Commit bcdec31

Browse files
authored
Add Just Ask context menu command (#102)
1 parent 8b237cd commit bcdec31

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

src/modules/misc.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,14 @@ export function provideCommands(): CommandDescriptor[] {
8686
.setDescription(
8787
'Send a link to the "Don\'t ask to ask" website'
8888
),
89-
handler: handleJustAskCommand,
89+
handler: handleJustAskSlashCommand,
90+
permission: CommandPermission.Public,
91+
},
92+
{
93+
builder: new Builders.ContextMenuCommandBuilder()
94+
.setName("Just Ask")
95+
.setType(Discord.ApplicationCommandType.Message),
96+
handler: handleJustAskContextMenuCommand,
9097
permission: CommandPermission.Public,
9198
},
9299
{
@@ -204,11 +211,14 @@ export async function handleWhoSaidCommand(
204211
}
205212
}
206213

207-
export async function handleJustAskCommand(
208-
interaction: Discord.ChatInputCommandInteraction
214+
export async function sendJustAsk(
215+
interaction: Discord.CommandInteraction,
216+
sender: (
217+
...args: Parameters<typeof Discord.Message.prototype.reply>
218+
) => Promise<unknown> // to allow optional chaining (?.)
209219
): Promise<void> {
210220
try {
211-
await interaction.channel?.send("https://dontasktoask.com/");
221+
await sender("https://dontasktoask.com/");
212222
await interaction.editReply(utils.CheckMarkEmoji + "Sent");
213223
logger.info({ member: interaction.member }, "Used don't ask to ask");
214224
} catch (e) {
@@ -217,6 +227,28 @@ export async function handleJustAskCommand(
217227
}
218228
}
219229

230+
export async function handleJustAskSlashCommand(
231+
interaction: Discord.ChatInputCommandInteraction
232+
): Promise<void> {
233+
if (interaction.channel) {
234+
await sendJustAsk(
235+
interaction,
236+
async (...args) => await interaction.channel?.send(...args)
237+
);
238+
}
239+
}
240+
241+
export async function handleJustAskContextMenuCommand(
242+
interaction: Discord.ContextMenuCommandInteraction
243+
): Promise<void> {
244+
if (interaction.isMessageContextMenuCommand()) {
245+
await sendJustAsk(
246+
interaction,
247+
async (...args) => await interaction.targetMessage?.reply(...args)
248+
);
249+
}
250+
}
251+
220252
export async function handleMigrateMembersWithRole(
221253
interaction: Discord.ChatInputCommandInteraction
222254
): Promise<void> {

0 commit comments

Comments
 (0)