From 8cfdf56c935bd64a59e411b219f2cb3b237e0937 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Tue, 5 Dec 2017 17:28:59 +0000 Subject: [PATCH] Math command is back again --- commands/number-edit/math.js | 30 ++++++++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 commands/number-edit/math.js diff --git a/commands/number-edit/math.js b/commands/number-edit/math.js new file mode 100644 index 00000000..c041da5f --- /dev/null +++ b/commands/number-edit/math.js @@ -0,0 +1,30 @@ +const { Command } = require('discord.js-commando'); +const math = require('mathjs'); + +module.exports = class MathCommand extends Command { + constructor(client) { + super(client, { + name: 'math', + aliases: ['mathematics', 'solve'], + group: 'number-edit', + memberName: 'math', + description: 'Evaluates a math expression.', + args: [ + { + key: 'expression', + prompt: 'What expression do you want to evaluate?', + type: 'string' + } + ] + }); + } + + run(msg, { expression }) { + try { + const evaluated = math.eval(expression).toString(); + return msg.say(evaluated).catch(() => msg.say('Invalid expression.')); + } catch (err) { + return msg.say('Invalid expression.'); + } + } +}; diff --git a/package.json b/package.json index 7a76cf17..28b5890e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "56.0.1", + "version": "56.1.0", "description": "Your personal server companion.", "main": "XiaoBot.js", "scripts": { @@ -37,6 +37,7 @@ "discord.js": "github:hydrabolt/discord.js", "discord.js-commando": "github:dragonfire535/discord.js-commando#default-functions", "erlpack": "github:discordapp/erlpack", + "mathjs": "^3.17.0", "node-opus": "^0.2.7", "snekfetch": "^3.6.0", "uws": "^8.14.1",