From 88c79763675a0a3edde695ba1d9d672c6003d1a5 Mon Sep 17 00:00:00 2001 From: Riccardo Fano Date: Fri, 26 Apr 2024 19:55:12 +0200 Subject: [PATCH 1/5] Remove prefix command --- src/commands/ask.ts | 52 +++++++-------------------------------------- 1 file changed, 8 insertions(+), 44 deletions(-) diff --git a/src/commands/ask.ts b/src/commands/ask.ts index 6fcb531..34e978d 100644 --- a/src/commands/ask.ts +++ b/src/commands/ask.ts @@ -1,14 +1,12 @@ -import { ApplicationCommandOptionType, CommandInteraction, InteractionResponse, escapeMarkdown } from 'discord.js' import { - Discord, - SimpleCommand, - SimpleCommandMessage, - SimpleCommandOption, - SimpleCommandOptionType, - Slash, - SlashChoice, - SlashOption, -} from 'discordx' + ApplicationCommandOptionType, + CommandInteraction, + InteractionResponse, + blockQuote, + bold, + escapeMarkdown, +} from 'discord.js' +import { Discord, Slash, SlashChoice, SlashOption } from 'discordx' const COMMAND_NAME = 'ask' const COMMAND_DESC = 'Ask a question to Wolfram Alpha' @@ -29,37 +27,6 @@ class Ask { } } - @SimpleCommand({ name: COMMAND_NAME, description: COMMAND_DESC, argSplitter: '\n' }) - async simple( - @SimpleCommandOption({ name: 'question', type: SimpleCommandOptionType.String }) - question: string | undefined, - @SimpleCommandOption({ name: 'units of measurement', type: SimpleCommandOptionType.Boolean }) - units: string | undefined, - command: SimpleCommandMessage - ) { - if (!question) { - return await command.message.reply({ - content: 'Usage: >ask \n (metric or imperial)', - allowedMentions: { repliedUser: false }, - }) - } - - if (this.isOnCooldown()) { - return - } - - try { - const answer = await this.fetchAnswer(question, units) - return command.message.reply({ content: answer, allowedMentions: { repliedUser: false } }) - } catch (err) { - console.error(err) - return command.message.reply({ - content: 'There was a problem communicating with Wolfram Alpha.', - allowedMentions: { repliedUser: false }, - }) - } - } - @Slash({ name: COMMAND_NAME, description: COMMAND_DESC }) private async slash( @SlashOption({ @@ -104,10 +71,7 @@ class Ask { url.searchParams.append('i', question) url.searchParams.append('units', units.toLowerCase()) - console.log(url) - const response = await fetch(url) - if (response.ok) { return escapeMarkdown(await response.text()) } From 6c3332866bf3d49a5a179ce6bbb4b8acbeac9e4f Mon Sep 17 00:00:00 2001 From: Riccardo Fano Date: Fri, 26 Apr 2024 19:55:25 +0200 Subject: [PATCH 2/5] Format bot output --- src/commands/ask.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/ask.ts b/src/commands/ask.ts index 34e978d..ed05420 100644 --- a/src/commands/ask.ts +++ b/src/commands/ask.ts @@ -54,7 +54,7 @@ class Ask { try { const answer = await this.fetchAnswer(question, units) - return interaction.reply(`[${escapeMarkdown(question)}] ${answer}`) + return interaction.reply(`[${bold(escapeMarkdown(question))}] ${blockQuote(answer)}`) } catch (err) { console.error(err) return interaction.reply('There was a problem communicating with Wolfram Alpha.') From a72f24640680b619f29e11f3b54977303c9e347a Mon Sep 17 00:00:00 2001 From: Riccardo Fano Date: Fri, 26 Apr 2024 20:12:27 +0200 Subject: [PATCH 3/5] Update output formatting --- src/commands/ask.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/ask.ts b/src/commands/ask.ts index ed05420..eabbe25 100644 --- a/src/commands/ask.ts +++ b/src/commands/ask.ts @@ -54,7 +54,7 @@ class Ask { try { const answer = await this.fetchAnswer(question, units) - return interaction.reply(`[${bold(escapeMarkdown(question))}] ${blockQuote(answer)}`) + return interaction.reply(`### ${escapeMarkdown(question)}\n${blockQuote(answer)}`) } catch (err) { console.error(err) return interaction.reply('There was a problem communicating with Wolfram Alpha.') From aefdc50bc47a9fc421fb54f28d925c27637cb019 Mon Sep 17 00:00:00 2001 From: Riccardo Fano Date: Fri, 26 Apr 2024 20:13:00 +0200 Subject: [PATCH 4/5] Make error reply ephemeral --- src/commands/ask.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/ask.ts b/src/commands/ask.ts index eabbe25..a6ee6dd 100644 --- a/src/commands/ask.ts +++ b/src/commands/ask.ts @@ -57,7 +57,7 @@ class Ask { return interaction.reply(`### ${escapeMarkdown(question)}\n${blockQuote(answer)}`) } catch (err) { console.error(err) - return interaction.reply('There was a problem communicating with Wolfram Alpha.') + return interaction.reply({ content: 'There was a problem communicating with Wolfram Alpha.', ephemeral: true }) } } From 490a15a96b5c5e9b50327e0d62af5a4ae2e8cfda Mon Sep 17 00:00:00 2001 From: Riccardo Fano Date: Fri, 26 Apr 2024 21:08:00 +0200 Subject: [PATCH 5/5] Use embed to format bot reply --- src/commands/ask.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/commands/ask.ts b/src/commands/ask.ts index a6ee6dd..f327852 100644 --- a/src/commands/ask.ts +++ b/src/commands/ask.ts @@ -1,9 +1,8 @@ import { ApplicationCommandOptionType, CommandInteraction, + EmbedBuilder, InteractionResponse, - blockQuote, - bold, escapeMarkdown, } from 'discord.js' import { Discord, Slash, SlashChoice, SlashOption } from 'discordx' @@ -54,7 +53,13 @@ class Ask { try { const answer = await this.fetchAnswer(question, units) - return interaction.reply(`### ${escapeMarkdown(question)}\n${blockQuote(answer)}`) + const capitalizedAnswer = answer.charAt(0).toUpperCase() + answer.slice(1) + const embed = new EmbedBuilder() + .setColor('#FBAB00') // MasterMind's color + .setTitle(escapeMarkdown(question)) + .setDescription(capitalizedAnswer) + + return await interaction.reply({ embeds: [embed] }) } catch (err) { console.error(err) return interaction.reply({ content: 'There was a problem communicating with Wolfram Alpha.', ephemeral: true })