From acedbffdad6db589f1609c8f910e86f46f8c4a2b Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Thu, 2 Dec 2021 13:15:08 +0000 Subject: [PATCH] Migrate eval command --- .env.template | 1 + commands/eval.js | 25 ------------------------- src/commands/eval.ts | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 25 deletions(-) delete mode 100644 commands/eval.js create mode 100644 src/commands/eval.ts diff --git a/.env.template b/.env.template index a588213..4d566fd 100644 --- a/.env.template +++ b/.env.template @@ -11,6 +11,7 @@ BOT_PREFIX=v! BOT_VER=3.0 BOT_AUTHOR=Vylpes BOT_DATE=28 Nov 2021 +BOT_OWNERID=147392775707426816 CORE_VER=2.0.2 diff --git a/commands/eval.js b/commands/eval.js deleted file mode 100644 index bdd46e1..0000000 --- a/commands/eval.js +++ /dev/null @@ -1,25 +0,0 @@ -const { command } = require('vylbot-core'); -const { MessageEmbed } = require('discord.js'); - -class evaluate extends command { - constructor() { - super("evaluate"); - super.description = "Evaluates an expression"; - super.category = "Administration"; - super.requiredConfigs = "ownerid"; - } - - evaluate(context) { - if (context.message.author.id == context.client.config.eval.ownerid) { - const result = eval(context.arguments.join(" ")); - - const embed = new MessageEmbed() - .setDescription(result) - .setColor(0x3050ba); - - context.message.channel.send(embed); - } - } -} - -module.exports = evaluate; diff --git a/src/commands/eval.ts b/src/commands/eval.ts new file mode 100644 index 0000000..0c8154f --- /dev/null +++ b/src/commands/eval.ts @@ -0,0 +1,32 @@ +import { Command, ICommandContext } from "vylbot-core"; +import ErrorEmbed from "../helpers/ErrorEmbed"; +import PublicEmbed from "../helpers/PublicEmbed"; + +export default class Evaluate extends Command { + constructor() { + super(); + + super._category = "Owner"; + } + + public override execute(context: ICommandContext) { + if (context.message.author.id != process.env.BOT_OWNERID) { + return; + } + + const stmt = context.args; + + console.log(`Eval Statement: ${stmt.join(" ")}`); + + try { + const result = eval(stmt.join(" ")); + + const embed = new PublicEmbed(context, "", result); + embed.SendToCurrentChannel(); + } + catch (err: any) { + const errorEmbed = new ErrorEmbed(context, err); + errorEmbed.SendToCurrentChannel(); + } + } +} \ No newline at end of file