aboutsummaryrefslogtreecommitdiff
path: root/src/commands/utilities
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/utilities')
-rw-r--r--src/commands/utilities/calculator.ts57
-rw-r--r--src/commands/utilities/decode.ts8
2 files changed, 60 insertions, 5 deletions
diff --git a/src/commands/utilities/calculator.ts b/src/commands/utilities/calculator.ts
new file mode 100644
index 0000000..5f91dca
--- /dev/null
+++ b/src/commands/utilities/calculator.ts
@@ -0,0 +1,57 @@
+import { AllowedMentions, BushCommand, BushMessage, BushSlashMessage } from '@lib';
+import { MessageEmbed } from 'discord.js';
+import { evaluate } from 'mathjs';
+
+export default class CalculatorCommand extends BushCommand {
+ public constructor() {
+ super('calculator', {
+ aliases: ['calculator', 'calc', 'math'],
+ category: 'utilities',
+ description: {
+ content: 'Calculates math expressions.',
+ usage: 'calculator <expression>',
+ examples: ['calculator ']
+ },
+ args: [
+ {
+ id: 'expression',
+ type: 'string',
+ match: 'rest',
+ prompt: {
+ start: 'What would you like to evaluate?',
+ retry: '{error} Pick something to evaluate.',
+ optional: false
+ }
+ }
+ ],
+ slash: true,
+ slashOptions: [
+ {
+ name: 'expression',
+ description: 'What would you like to evaluate?',
+ type: 'STRING',
+ required: true
+ }
+ ],
+ hidden: true,
+ clientPermissions: ['SEND_MESSAGES'],
+ userPermissions: ['SEND_MESSAGES']
+ });
+ }
+ public override async exec(message: BushMessage | BushSlashMessage, args: { expression: string }): Promise<unknown> {
+ const decodedEmbed = new MessageEmbed()
+ .setTitle(`Calculator`)
+ .addField('📥 Input', await util.inspectCleanRedactCodeblock(args.expression, 'mma'));
+ try {
+ const calculated = evaluate(args.expression);
+ decodedEmbed
+ .setColor(util.colors.success)
+ .addField('📤 Output', await util.inspectCleanRedactCodeblock(calculated.toString(), 'mma'));
+ } catch (error) {
+ decodedEmbed
+ .setColor(util.colors.error)
+ .addField(`📤 Error Calculating`, await util.inspectCleanRedactCodeblock(`${error.name}: ${error.message}`, 'js'));
+ }
+ return await message.util.reply({ embeds: [decodedEmbed], allowedMentions: AllowedMentions.none() });
+ }
+}
diff --git a/src/commands/utilities/decode.ts b/src/commands/utilities/decode.ts
index 05e988a..a5a4c21 100644
--- a/src/commands/utilities/decode.ts
+++ b/src/commands/utilities/decode.ts
@@ -99,16 +99,14 @@ export default class DecodeCommand extends BushCommand {
const encodeOrDecode = util.capitalizeFirstLetter(message?.util?.parsed?.alias || 'decoded');
const decodedEmbed = new MessageEmbed()
.setTitle(`${encodeOrDecode} Information`)
- .addField('📥 Input', await util.inspectCleanRedactCodeblock(data, undefined));
+ .addField('📥 Input', await util.inspectCleanRedactCodeblock(data));
try {
const decoded = Buffer.from(data, from).toString(to);
- decodedEmbed
- .setColor(util.colors.success)
- .addField('📤 Output', await util.inspectCleanRedactCodeblock(decoded, undefined));
+ decodedEmbed.setColor(util.colors.success).addField('📤 Output', await util.inspectCleanRedactCodeblock(decoded));
} catch (error) {
decodedEmbed
.setColor(util.colors.error)
- .addField(`📤 Error ${encodeOrDecode.slice(1)}ing`, await util.inspectCleanRedactCodeblock(error.stack, undefined));
+ .addField(`📤 Error ${encodeOrDecode.slice(1)}ing`, await util.inspectCleanRedactCodeblock(error?.stack ?? error));
}
return await message.util.reply({ embeds: [decodedEmbed], allowedMentions: AllowedMentions.none() });
}