2020-04-17 17:23:13 +02:00
|
|
|
const { inspect } = require('util');
|
|
|
|
const { username } = require('os').userInfo();
|
|
|
|
|
|
|
|
let _storage = null; //eslint-disable-line no-unused-vars
|
|
|
|
|
|
|
|
const { Command, Argument } = require('../../../../interfaces/');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Evaluate extends Command {
|
|
|
|
|
|
|
|
constructor(client) {
|
|
|
|
|
|
|
|
super(client, {
|
|
|
|
name: 'evaluate',
|
|
|
|
module: 'developer',
|
|
|
|
aliases: [
|
|
|
|
'eval',
|
|
|
|
'e'
|
|
|
|
],
|
|
|
|
restricted: true,
|
|
|
|
description: "Evaluates javascript code.",
|
|
|
|
arguments: [
|
|
|
|
new Argument(client, {
|
|
|
|
name: 'log',
|
|
|
|
type: 'BOOLEAN',
|
|
|
|
types: ['FLAG'],
|
|
|
|
description: "Logs the output in the console."
|
|
|
|
}),
|
|
|
|
new Argument(client, {
|
|
|
|
name: 'hide',
|
|
|
|
type: 'BOOLEAN',
|
|
|
|
types: ['FLAG'],
|
|
|
|
description: "Hides the output from the channel."
|
|
|
|
})
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2020-05-05 01:06:27 +02:00
|
|
|
|
2020-04-17 17:23:13 +02:00
|
|
|
|
|
|
|
async execute(message, { params, args }) {
|
|
|
|
|
|
|
|
params = params.join(' ');
|
|
|
|
|
|
|
|
try {
|
|
|
|
let evaled = eval(params);
|
|
|
|
if(evaled instanceof Promise) await evaled;
|
|
|
|
if(typeof evaled !== 'string') evaled = inspect(evaled);
|
|
|
|
|
|
|
|
evaled = evaled
|
|
|
|
.replace(new RegExp(this.client.token, 'g'), '<redacted>')
|
|
|
|
.replace(new RegExp(username, 'g'), '<redacted>');
|
|
|
|
|
|
|
|
if(args.log) this.client.logger.debug(`[${message.author.tag}] Evaluation Result: ${evaled}`);
|
|
|
|
|
2020-05-01 16:12:45 +02:00
|
|
|
if (evaled.length > 1850) {
|
|
|
|
console.log(evaled);
|
|
|
|
evaled = `${evaled.substring(0, 1850)}...`;
|
|
|
|
}
|
|
|
|
await message.respond(`Evaluation was successful.\`\`\`js\n${evaled}\`\`\``,
|
2020-05-05 01:06:27 +02:00
|
|
|
{ emoji: 'success' }
|
|
|
|
);
|
2020-04-17 17:23:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
} catch(error) {
|
|
|
|
|
2020-05-01 16:12:45 +02:00
|
|
|
let msg = `${error}${error.stack ? `\n${error.stack}` : ''}`;
|
2020-04-17 17:23:13 +02:00
|
|
|
|
2020-05-01 16:12:45 +02:00
|
|
|
if(args.log) this.client.logger.debug(`[${message.author.tag}] Evaluation Failed: ${msg}`);
|
2020-04-17 17:23:13 +02:00
|
|
|
|
2020-05-01 16:12:45 +02:00
|
|
|
if(msg.length > 2000) msg = `${msg.substring(0, 1900)}...`;
|
2020-05-05 01:06:27 +02:00
|
|
|
await message.respond(`Evaluation failed.\`\`\`js\n${msg}\`\`\``,
|
|
|
|
{ emoji: 'failure' }
|
|
|
|
);
|
2020-04-17 17:23:13 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Evaluate;
|