2021-04-05 12:21:27 +00:00
|
|
|
import {Command, NamedCommand} 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 13:34:55 +00:00
|
|
|
async run({send, message, channel, guild, author, member, client, args}) {
|
|
|
|
if (!args[0]) return send("Please provide a calculation.");
|
2021-03-31 01:40:29 +00:00
|
|
|
let resp;
|
|
|
|
try {
|
2021-04-05 12:21:27 +00:00
|
|
|
resp = math.evaluate(args.join(" "));
|
2021-03-31 01:40:29 +00:00
|
|
|
} catch (e) {
|
2021-04-10 13:34:55 +00:00
|
|
|
return send("Please provide a *valid* calculation.");
|
2021-03-31 01:40:29 +00:00
|
|
|
}
|
|
|
|
const embed = new MessageEmbed()
|
|
|
|
.setColor(0xffffff)
|
|
|
|
.setTitle("Math Calculation")
|
2021-04-05 12:21:27 +00:00
|
|
|
.addField("Input", `\`\`\`js\n${args.join("")}\`\`\``)
|
2021-03-31 01:40:29 +00:00
|
|
|
.addField("Output", `\`\`\`js\n${resp}\`\`\``);
|
2021-04-10 13:34:55 +00:00
|
|
|
return send(embed);
|
2021-03-31 01:40:29 +00:00
|
|
|
}
|
|
|
|
});
|