2021-06-19 22:41:51 +02:00
|
|
|
const { inspect } = require('util');
|
|
|
|
const { username } = require('os').userInfo();
|
|
|
|
|
|
|
|
const Command = require('../Command');
|
2021-12-22 23:52:06 +01:00
|
|
|
const Util = require('../Util');
|
2021-06-19 22:41:51 +02:00
|
|
|
|
|
|
|
class Eval extends Command {
|
|
|
|
|
2021-10-22 09:35:04 +02:00
|
|
|
constructor (client) {
|
2021-06-19 22:41:51 +02:00
|
|
|
super(client, {
|
|
|
|
name: 'eval',
|
2021-10-22 09:35:04 +02:00
|
|
|
aliases: [ 'e' ]
|
2021-06-19 22:41:51 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-10-22 09:35:04 +02:00
|
|
|
async execute (message, { clean }) {
|
2021-06-19 22:41:51 +02:00
|
|
|
|
2021-12-22 23:52:06 +01:00
|
|
|
const { sudo } = this.client._options;
|
2021-10-22 09:35:04 +02:00
|
|
|
const { guild, author, member, client, channel } = message; // eslint-disable-line no-unused-vars
|
2021-12-22 23:52:06 +01:00
|
|
|
const roleIds = member.roles.cache.map(r => r.id);
|
|
|
|
if (!Util.arrayIncludesAny(roleIds, sudo) && !sudo.includes(author.id)) return;
|
2021-06-19 22:41:51 +02:00
|
|
|
|
|
|
|
try {
|
2021-10-22 09:35:04 +02:00
|
|
|
let evaled = eval(clean); // eslint-disable-line no-eval
|
2021-11-29 11:29:09 +01:00
|
|
|
if (evaled instanceof Promise) evaled = await evaled;
|
2021-06-19 22:41:51 +02:00
|
|
|
if (typeof evaled !== 'string') evaled = inspect(evaled);
|
|
|
|
|
|
|
|
evaled = evaled
|
|
|
|
.replace(new RegExp(this.client.token, 'gu'), '<redacted>')
|
|
|
|
.replace(new RegExp(username, 'gu'), '<redacted>');
|
|
|
|
|
2021-10-22 09:35:04 +02:00
|
|
|
// if (args.log) guild._debugLog(`[${message.author.tag}] Evaluation Success: ${evaled}`);
|
2021-06-19 22:41:51 +02:00
|
|
|
|
|
|
|
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}` : ''}`;
|
|
|
|
|
2021-10-22 09:35:04 +02:00
|
|
|
// if (args.log) guild._debugLog(`[${message.author.tag}] Evaluation Fail: ${msg}`);
|
2021-06-19 22:41:51 +02:00
|
|
|
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;
|