2019-12-13 14:37:39 +00:00
|
|
|
const math = require('math-expression-evaluator');
|
|
|
|
const stripIndents = require('common-tags').stripIndents;
|
|
|
|
|
|
|
|
exports.run = async (client, message, args, level) => {
|
|
|
|
message.delete();
|
|
|
|
|
|
|
|
if (!args[0]) {
|
2019-12-13 18:56:04 +00:00
|
|
|
return (await message.reply("you must provide an equation to be solved!")).delete(5000);
|
2019-12-13 14:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const question = args.join(" ");
|
|
|
|
|
|
|
|
let answer;
|
|
|
|
try {
|
|
|
|
answer = math.eval(question);
|
|
|
|
} catch (err) {
|
|
|
|
message.channel.send(`**Invalid math equation:** ${err}`);
|
|
|
|
}
|
|
|
|
|
2019-12-13 18:56:04 +00:00
|
|
|
message.channel.send(client.embed('', stripIndents`**Equation:**\n\`\`\`\n${question}\n\`\`\`**Answer:**\n\`\`\`\n${answer}\n\`\`\``));
|
2019-12-13 14:37:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.conf = {
|
|
|
|
enabled: true,
|
|
|
|
guildOnly: false,
|
2019-12-13 18:56:04 +00:00
|
|
|
aliases: ['calc', 'math'],
|
2019-12-13 14:37:39 +00:00
|
|
|
permLevel: "User"
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.help = {
|
2019-12-13 18:56:04 +00:00
|
|
|
name: "calculator",
|
|
|
|
category: "Utility",
|
|
|
|
description: "Calculates almost any math equation",
|
|
|
|
usage: "calculate <equation>"
|
2019-12-13 14:37:39 +00:00
|
|
|
};
|