From 995ab23c8147b09065b876b81e0fb712b2d24972 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Mon, 3 May 2021 17:08:16 -0400 Subject: [PATCH] Switch math back to mathjs --- commands/edit-number/math.js | 15 ++++++++++++--- package.json | 1 - 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/commands/edit-number/math.js b/commands/edit-number/math.js index 50204fea..b1bb1938 100644 --- a/commands/edit-number/math.js +++ b/commands/edit-number/math.js @@ -1,5 +1,6 @@ const Command = require('../../structures/Command'); -const { Parser } = require('expr-eval'); +const core = require('mathjs/number'); +const math = core.create(core.all); module.exports = class MathCommand extends Command { constructor(client) { @@ -15,14 +16,22 @@ module.exports = class MathCommand extends Command { prompt: 'What expression do you want to evaluate?', type: 'string' } + ], + credit: [ + { + name: 'mathjs', + url: 'https://mathjs.org/', + reason: 'Expression Parser' + } ] }); } run(msg, { expression }) { try { - const evaluated = Parser.evaluate(expression).toString(); - return msg.reply(evaluated).catch(() => msg.reply('Invalid expression.')); + const evaluated = math.evaluate(expression); + if (typeof result === 'function') return msg.reply('Invalid expression.'); + return msg.reply(evaluated.toString()); } catch { return msg.reply('Invalid expression.'); } diff --git a/package.json b/package.json index fca10ae6..54564794 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,6 @@ "dotenv": "^8.2.0", "emoji-regex": "^9.2.2", "eslint": "^7.25.0", - "expr-eval": "^2.0.2", "fen-validator": "^1.4.1", "font-finder": "^1.1.0", "gifencoder": "^2.0.1",