vylbot-app/src/commands/eval.ts
Vylpes f61c4c728a
Feature/12 create tests (#102)
* Fix tests

* Update coverage

* Remove unrequired mock files

* Add about command test

* Update about tests

* Ban command tests

* eval command tests

* Start help command tests

* Add help command tests

* Add kick command tests

* Mute command tests

* Poll command tests

* Add role command tests

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Add rules command tests

* Add unmute command tests

* Add warn command tests

* Add MemberEvents tests

* Add GuildMemberUpdate tests

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Add MessageEvents tests

* Add StringTools test

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Add embed tests

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Add GitHub Actions

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Move to tslint

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Remove tslint

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Remove linting script

Signed-off-by: Ethan Lane <ethan@vylpes.com>
2022-01-30 17:03:36 +00:00

47 lines
No EOL
1.3 KiB
TypeScript

import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Command } from "../type/command";
export default class Evaluate extends Command {
constructor() {
super();
super._category = "Owner";
}
public override execute(context: ICommandContext): ICommandReturnContext {
if (context.message.author.id != process.env.BOT_OWNERID) {
return {
commandContext: context,
embeds: []
};
}
const stmt = context.args;
console.log(`Eval Statement: ${stmt.join(" ")}`);
try {
const result = eval(stmt.join(" "));
const embed = new PublicEmbed(context, "", result);
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
catch (err: any) {
const errorEmbed = new ErrorEmbed(context, err);
errorEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [errorEmbed]
};
}
}
}