forked from embee/woomy
no longer crashes when invalid equation is entered
This commit is contained in:
parent
ba4781f0f4
commit
f31f75ae79
1 changed files with 43 additions and 39 deletions
|
@ -1,5 +1,5 @@
|
||||||
var allowed = ["+", "-", "*", "/", "(", ")", " "];
|
var allowed = ["+", "-", "*", "/", "(", ")", " "];
|
||||||
exports.run = (client, message, args) => {
|
exports.run = (client, message, args) => {
|
||||||
let exercise = args.join(" ");
|
let exercise = args.join(" ");
|
||||||
|
|
||||||
if (!exercise) {
|
if (!exercise) {
|
||||||
|
@ -8,6 +8,7 @@ exports.run = (client, message, args) => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
for (var i = 0; i < exercise.length; i++) {
|
for (var i = 0; i < exercise.length; i++) {
|
||||||
let c = exercise.charAt(i);
|
let c = exercise.charAt(i);
|
||||||
let found = allowed.find((element) => element === c);
|
let found = allowed.find((element) => element === c);
|
||||||
|
@ -23,20 +24,23 @@ exports.run = (client, message, args) => {
|
||||||
|
|
||||||
let result = (new Function( 'return ' + exercise )());
|
let result = (new Function( 'return ' + exercise )());
|
||||||
|
|
||||||
message.channel.send(`\`RESULT:\`\n\`\`\`${result}\`\`\``);
|
message.channel.send(`\`RESULT:\`\n\`\`\`${result}\`\`\``)
|
||||||
};
|
} catch (err) {
|
||||||
|
message.channel.send('<:error:466995152976871434> Malformed input.')
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
exports.conf = {
|
exports.conf = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
guildOnly: false,
|
guildOnly: false,
|
||||||
aliases: ["calc", "math"],
|
aliases: ["calc", "math"],
|
||||||
permLevel: "User",
|
permLevel: "User",
|
||||||
requiredPerms: []
|
requiredPerms: []
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.help = {
|
exports.help = {
|
||||||
name: "calculate",
|
name: "calculate",
|
||||||
category: "Utility",
|
category: "Utility",
|
||||||
description: "Solves basic mathematical equations.",
|
description: "Solves basic mathematical equations.",
|
||||||
usage: "calculate [equation]"
|
usage: "calculate [equation]"
|
||||||
};
|
};
|
Loading…
Reference in a new issue