woomy/src/commands/calculate.js

42 lines
1 KiB
JavaScript
Raw Normal View History

2020-01-25 10:02:43 +00:00
var allowed = ["+", "-", "*", "/", "(", ")", " "];
exports.run = (client, message, args) => {
let exercise = args.join(" ");
if (!exercise) {
return message.channel.send(
`<:error:466995152976871434> No equation provided. Usage :\`${client.commands.get(`calculate`).help.usage}\``
);
}
for (var i = 0; i < exercise.length; i++) {
let c = exercise.charAt(i);
let found = allowed.find((element) => element === c);
if(c == "0") found = true;
if(!(Number(c) || found))
{
return message.channel.send(
`<:error:466995152976871434> Invalid equation. Please use \`*\` for multiplication and \`/\` for division!`
);
}
}
let result = (new Function( 'return ' + exercise )());
2020-03-09 01:11:33 +00:00
message.channel.send(`\`RESULT:\`\n\`\`\`${result}\`\`\``);
2020-01-25 10:02:43 +00:00
};
exports.conf = {
enabled: true,
guildOnly: false,
2020-03-22 11:13:41 +00:00
aliases: ["calc", "math"],
2020-01-25 10:02:43 +00:00
permLevel: "User",
requiredPerms: []
};
exports.help = {
2020-03-22 11:13:41 +00:00
name: "calculate",
2020-01-25 10:02:43 +00:00
category: "Utility",
description: "Solves basic mathematical equations.",
2020-03-22 11:13:41 +00:00
usage: "calculate [equation]"
2020-01-25 10:02:43 +00:00
};