Fix eval undefined if no args

merge-requests/4/head
Bsian 2020-01-04 11:21:53 +00:00
parent 9809f32ee0
commit 0b443e8297
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
1 changed files with 4 additions and 33 deletions

View File

@ -19,79 +19,50 @@ export default class Eval extends Command {
public async run(message: Message, args: string[]) {
try {
// const evalMessage = message.content.slice(this.client.config.prefix.length).split(' ').slice(1).join(' ');
let evalString: string;
let evalString = args.join(' ').trim();
let evaled: any;
let depth = 0;
this.client.signale.note('Received');
this.client.signale.note(message);
this.client.signale.note(args);
if (args[0] && args[0].startsWith('-d')) {
this.client.signale.note('Depth flag');
depth = Number(args[0].replace('-d', ''));
if (!depth || depth < 0) depth = 0;
this.client.signale.note('Depth set');
args.shift();
evalString = args.join(' ').trim();
this.client.signale.note('Eval reconfigured');
this.client.signale.note(args);
}
if (args[0] === '-a' || args[0] === '-async') {
this.client.signale.note('Async flag');
args.shift();
evalString = `(async () => { ${args.join(' ').trim()} })()`;
this.client.signale.note('Eval reconfigured');
this.client.signale.note(args);
}
this.client.signale.note('Main');
this.client.signale.note(args);
try {
this.client.signale.note(evalString);
evaled = await eval(evalString);
this.client.signale.note('evaluated with success');
this.client.signale.note(evaled);
this.client.signale.note(typeof evaled);
if (typeof evaled !== 'string') {
evaled = inspect(evaled, { depth });
}
if (evaled === undefined) {
this.client.signale.note('Eval undefined');
evaled = 'undefined';
}
if (typeof evaled !== 'string') {
this.client.signale.note('Eval returned not a string. Depth setting:');
this.client.signale.note(depth);
evaled = inspect(evaled, { depth });
this.client.signale.note('Inspected');
}
} catch (error) {
this.client.signale.note('Error caught');
evaled = error.stack;
}
this.client.signale.note('Eval finished');
evaled = evaled.replace(new RegExp(this.client.config.token, 'gi'), 'juul');
evaled = evaled.replace(new RegExp(this.client.config.emailPass, 'gi'), 'juul');
evaled = evaled.replace(new RegExp(this.client.config.cloudflare, 'gi'), 'juul');
this.client.signale.note('Masked');
const display = this.client.util.splitString(evaled, 1975);
this.client.signale.note('Split output');
if (display[5]) {
this.client.signale.note('Output greater than 5 messages');
try {
const { data } = await axios.post('https://snippets.cloud.libraryofcode.org/documents', display.join(''));
this.client.signale.note('Data sent');
return message.channel.createMessage(`${this.client.stores.emojis.success} Your evaluation evaled can be found on https://snippets.cloud.libraryofcode.org/${data.key}`);
} catch (error) {
this.client.signale.note('Error posting');
return message.channel.createMessage(`${this.client.stores.emojis.error} ${error}`);
}
}
this.client.signale.note('Single message');
return display.forEach((m) => message.channel.createMessage(`\`\`\`js\n${m}\n\`\`\``));
} catch (error) {
this.client.signale.note('Global error caught');
return this.client.util.handleError(error, message, this);
}
}