-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmath.js
More file actions
20 lines (16 loc) · 929 Bytes
/
math.js
File metadata and controls
20 lines (16 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
async run(message, args, level, settings, texts) { // eslint-disable-line no-unused-vars
let exp = args.join(" ");
if (!exp) return message.channel.send(texts.cmd.math.noExp.replace(/{{prefix}}/g, settings.prefix));
if (exp.includes("°")) exp = exp.replace(/°/g, "deg");
const msg = await message.channel.send(texts.cmd.math.calculating);
try {
let evaled = math.eval(exp);
if (isNaN(evaled)) evaled = texts.cmd.math.isNaN;
if (exp.length + evaled.length > 2000) return message.channel.send("Output is too long to fit into a message!");
msg.edit(`${exp} = **${evaled}**`);
} catch (error) {
if (error.toString().startsWith("SyntaxError:") || error.message.startsWith("Undefined symbol")) return msg.edit(`**\`SyntaxError:\`** \`${error.message}\``);
this.client.logger.error(error);
msg.edit(texts.general.error.replace(/{{err}}/g, error.message));
}
}