thaldrin/src/discord/commands/developer/eval.ts

31 lines
883 B
TypeScript
Raw Normal View History

2021-09-11 11:36:51 +00:00
import { Context } from "../../../utils/types";
import { Command } from '@thaldrin/eu';
import clean from "../../../utils/clean"
2021-04-04 15:17:46 +00:00
export = class Eval extends Command {
constructor() {
super({
2021-04-08 00:43:17 +00:00
name: "eval",
2021-04-04 15:17:46 +00:00
description: "Evaluate JS code directly from the process.",
aliases: [
'ev',
'e'
],
cooldown: 0,
dev: true,
guild: false
})
}
async command(ctx: Context) {
2021-04-04 15:17:46 +00:00
let code = ctx.args.join(" ")
try {
let evaled = await eval(code)
if (typeof evaled != 'string') {
evaled = (await import("util")).inspect(evaled, false, 1)
}
return ctx.channel.send(`\`\`\`js\n${clean(evaled)}\n\`\`\``)
2021-04-04 15:17:46 +00:00
} catch (error) {
console.error(error)
2021-04-04 15:17:46 +00:00
}
}
}