diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-08-25 16:16:44 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-08-25 16:16:44 -0400 |
commit | 4364f1d344e75d23728ce951fc768bc9c8405bed (patch) | |
tree | 47dbdb0482fc16842271c44e3736ba86e0064351 /src/commands/utilities | |
parent | 95dc4c4a4abeed75f419c9ccd5b3f072609c5035 (diff) | |
download | tanzanite-4364f1d344e75d23728ce951fc768bc9c8405bed.tar.gz tanzanite-4364f1d344e75d23728ce951fc768bc9c8405bed.tar.bz2 tanzanite-4364f1d344e75d23728ce951fc768bc9c8405bed.zip |
cleaned up, wolfram alpha command, a few fixes
Diffstat (limited to 'src/commands/utilities')
-rw-r--r-- | src/commands/utilities/calculator.ts | 3 | ||||
-rw-r--r-- | src/commands/utilities/wolframAlpha.ts | 59 |
2 files changed, 60 insertions, 2 deletions
diff --git a/src/commands/utilities/calculator.ts b/src/commands/utilities/calculator.ts index d845aaa..a2c91e4 100644 --- a/src/commands/utilities/calculator.ts +++ b/src/commands/utilities/calculator.ts @@ -10,7 +10,7 @@ export default class CalculatorCommand extends BushCommand { description: { content: 'Calculates math expressions.', usage: 'calculator <expression>', - examples: ['calculator '] + examples: ['calculator 9+10'] }, args: [ { @@ -33,7 +33,6 @@ export default class CalculatorCommand extends BushCommand { required: true } ], - hidden: true, clientPermissions: ['SEND_MESSAGES'], userPermissions: ['SEND_MESSAGES'] }); diff --git a/src/commands/utilities/wolframAlpha.ts b/src/commands/utilities/wolframAlpha.ts new file mode 100644 index 0000000..c18646c --- /dev/null +++ b/src/commands/utilities/wolframAlpha.ts @@ -0,0 +1,59 @@ +import { AllowedMentions, BushCommand, BushMessage, BushSlashMessage } from '@lib'; +import { MessageEmbed } from 'discord.js'; +// @ts-expect-error: no types :( +import WolframAlphaAPI from 'wolfram-alpha-api'; + +export default class WolframAlphaCommand extends BushCommand { + public constructor() { + super('wolframAlpha', { + aliases: ['wolframalpha', 'wolfram', 'alpha', 'wolf', 'wa'], + category: 'utilities', + description: { + content: 'Queries Wolfram|Alpha for a result.', + usage: 'wolframalpha <expression>', + examples: ['wolframalpha what is the population of france'] + }, + args: [ + { + id: 'expression', + type: 'string', + match: 'rest', + prompt: { + start: 'What would you like to look up?', + retry: '{error} Pick something to look up.', + optional: false + } + } + ], + slash: true, + slashOptions: [ + { + name: 'expression', + description: 'What would you like to look up?', + type: 'STRING', + required: true + } + ], + clientPermissions: ['SEND_MESSAGES'], + userPermissions: ['SEND_MESSAGES'] + }); + } + public override async exec(message: BushMessage | BushSlashMessage, args: { expression: string }): Promise<unknown> { + const waApi = WolframAlphaAPI(this.client.config.credentials.wolframAlphaAppId); + + const decodedEmbed = new MessageEmbed().addField('📥 Input', await util.inspectCleanRedactCodeblock(args.expression)); + try { + const calculated = await waApi.getShort(args.expression); + decodedEmbed + .setTitle(`${util.emojis.successFull} Successfully Queried Expression`) + .setColor(util.colors.success) + .addField('📤 Output', await util.inspectCleanRedactCodeblock(calculated.toString())); + } catch (error) { + decodedEmbed + .setTitle(`${util.emojis.errorFull} Unable to Query Expression`) + .setColor(util.colors.error) + .addField(`📤 Error`, await util.inspectCleanRedactCodeblock(`${error.name}: ${error.message}`, 'js')); + } + return await message.util.reply({ embeds: [decodedEmbed], allowedMentions: AllowedMentions.none() }); + } +} |