diff --git a/src/commands/ask.ts b/src/commands/ask.ts index 6fcb531..f327852 100644 --- a/src/commands/ask.ts +++ b/src/commands/ask.ts @@ -1,14 +1,11 @@ -import { ApplicationCommandOptionType, CommandInteraction, InteractionResponse, escapeMarkdown } from 'discord.js' import { - Discord, - SimpleCommand, - SimpleCommandMessage, - SimpleCommandOption, - SimpleCommandOptionType, - Slash, - SlashChoice, - SlashOption, -} from 'discordx' + ApplicationCommandOptionType, + CommandInteraction, + EmbedBuilder, + InteractionResponse, + 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 +26,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({ @@ -87,10 +53,16 @@ class Ask { try { const answer = await this.fetchAnswer(question, units) - return interaction.reply(`[${escapeMarkdown(question)}] ${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('There was a problem communicating with Wolfram Alpha.') + return interaction.reply({ content: 'There was a problem communicating with Wolfram Alpha.', ephemeral: true }) } } @@ -104,10 +76,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()) }