diff --git a/commands/num-edit/math.js b/commands/num-edit/math.js new file mode 100644 index 00000000..7cc31437 --- /dev/null +++ b/commands/num-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: ['calculator', 'calc'], + group: 'num-edit', + memberName: 'math', + description: 'Evaluates math expressions.', + args: [ + { + key: 'expression', + prompt: 'What expression would you like to evaluate?', + type: 'string' + } + ] + }); + } + + run(msg, { expression }) { + try { + const answer = math.eval(expression).toString(); + return msg.say(answer).catch(() => msg.reply('Invalid expression.')); + } catch (err) { + return msg.reply('Invalid expression.'); + } + } +}; diff --git a/package.json b/package.json index 770d48c2..b0910d71 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "51.0.2", + "version": "51.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:gawdl3y/discord.js-commando", "erlpack": "github:discordapp/erlpack", + "mathjs": "^3.16.5", "node-opus": "^0.2.7", "snekfetch": "^3.5.8", "uws": "^8.14.1",