70 lines
2.4 KiB
TypeScript
70 lines
2.4 KiB
TypeScript
/* eslint-disable no-eval */
|
|
import axios from 'axios';
|
|
import { Message } from 'eris';
|
|
import { inspect } from 'util';
|
|
import { Client } from '..';
|
|
import { Command } from '../class';
|
|
|
|
export default class Eval extends Command {
|
|
constructor(client: Client) {
|
|
super(client);
|
|
this.name = 'eval';
|
|
this.aliases = ['e'];
|
|
this.description = 'Evaluate JavaScript code';
|
|
this.enabled = true;
|
|
this.permissions = { users: ['253600545972027394', '278620217221971968', '239261547959025665'] };
|
|
this.guildOnly = false;
|
|
}
|
|
|
|
public async run(message: Message) {
|
|
try {
|
|
const args = message.content.slice(this.client.config.prefix.length).trim().split(' ').slice(1);
|
|
let evalString = args.join(' ').trim();
|
|
let evaled: any;
|
|
let depth = 0;
|
|
|
|
if (args[0] && args[0].startsWith('-d')) {
|
|
depth = Number(args[0].replace('-d', ''));
|
|
if (!depth || depth < 0) depth = 0;
|
|
args.shift();
|
|
evalString = args.join(' ').trim();
|
|
}
|
|
if (args[0] === '-a') {
|
|
args.shift();
|
|
evalString = `(async () => { ${args.join(' ').trim()} })()`;
|
|
}
|
|
|
|
try {
|
|
evaled = await eval(evalString);
|
|
if (typeof evaled !== 'string') {
|
|
evaled = inspect(evaled, { depth });
|
|
}
|
|
if (evaled === undefined) {
|
|
evaled = 'undefined';
|
|
}
|
|
} catch (error) {
|
|
evaled = error.stack;
|
|
}
|
|
|
|
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');
|
|
|
|
|
|
const display = this.client.util.splitString(evaled, 1975);
|
|
if (display[5]) {
|
|
try {
|
|
const { data } = await axios.post('https://snippets.cloud.libraryofcode.org/documents', display.join(''));
|
|
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) {
|
|
return message.channel.createMessage(`${this.client.stores.emojis.error} ${error}`);
|
|
}
|
|
}
|
|
|
|
return display.forEach((m) => message.channel.createMessage(`\`\`\`js\n${m}\n\`\`\``));
|
|
} catch (error) {
|
|
return this.client.util.handleError(error, message, this);
|
|
}
|
|
}
|
|
}
|