modmail/structure/commands/Eval.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-06-19 22:41:51 +02:00
const { inspect } = require('util');
const { username } = require('os').userInfo();
const Command = require('../Command');
class Eval extends Command {
constructor(client) {
super(client, {
name: 'eval',
aliases: ['e']
});
}
async execute(message, { clean }) {
2021-06-19 22:59:42 +02:00
const { guild, author, member, client, channel } = message; //eslint-disable-line no-unused-vars
2021-06-19 22:41:51 +02:00
try {
let evaled = eval(clean); //eslint-disable-line no-eval
if (evaled instanceof Promise) await evaled;
if (typeof evaled !== 'string') evaled = inspect(evaled);
evaled = evaled
.replace(new RegExp(this.client.token, 'gu'), '<redacted>')
.replace(new RegExp(username, 'gu'), '<redacted>');
//if (args.log) guild._debugLog(`[${message.author.tag}] Evaluation Success: ${evaled}`);
if (evaled.length > 1850) {
evaled = `${evaled.substring(0, 1850)}...`;
}
2021-06-19 22:59:42 +02:00
await channel.send(
2021-06-19 22:41:51 +02:00
`Evaluation was successful.\`\`\`js\n${evaled}\`\`\``,
{ emoji: 'success' }
);
} catch (error) {
let msg = `${error}${error.stack ? `\n${error.stack}` : ''}`;
//if (args.log) guild._debugLog(`[${message.author.tag}] Evaluation Fail: ${msg}`);
if (msg.length > 2000) msg = `${msg.substring(0, 1900)}...`;
2021-06-19 22:59:42 +02:00
await channel.send(
2021-06-19 22:41:51 +02:00
`Evaluation failed.\`\`\`js\n${msg}\`\`\``,
{ emoji: 'failure' }
);
}
}
}
module.exports = Eval;