2021-04-11 09:11:21 +00:00
|
|
|
import {NamedCommand, RestCommand} from "../../core";
|
2021-03-31 01:40:29 +00:00
|
|
|
import * as math from "mathjs";
|
|
|
|
import {MessageEmbed} from "discord.js";
|
|
|
|
|
2021-04-05 12:21:27 +00:00
|
|
|
export default new NamedCommand({
|
2021-03-31 01:40:29 +00:00
|
|
|
description: "Calculates a specified math expression.",
|
2021-04-10 17:07:55 +00:00
|
|
|
run: "Please provide a calculation.",
|
|
|
|
any: new RestCommand({
|
2021-04-11 09:11:21 +00:00
|
|
|
async run({send, combined}) {
|
2021-04-10 17:07:55 +00:00
|
|
|
let resp;
|
|
|
|
try {
|
|
|
|
resp = math.evaluate(combined);
|
|
|
|
} catch (e) {
|
|
|
|
return send("Please provide a *valid* calculation.");
|
|
|
|
}
|
|
|
|
const embed = new MessageEmbed()
|
|
|
|
.setColor(0xffffff)
|
|
|
|
.setTitle("Math Calculation")
|
|
|
|
.addField("Input", `\`\`\`js\n${combined}\`\`\``)
|
|
|
|
.addField("Output", `\`\`\`js\n${resp}\`\`\``);
|
|
|
|
return send(embed);
|
2021-03-31 01:40:29 +00:00
|
|
|
}
|
2021-04-10 17:07:55 +00:00
|
|
|
})
|
2021-03-31 01:40:29 +00:00
|
|
|
});
|