cloudservices/src/commands/eval.ts

59 lines
2.0 KiB
TypeScript
Raw Normal View History

2019-10-21 19:58:56 -04:00
/* eslint-disable no-eval */
import { Message } from 'eris';
import { inspect } from 'util';
import axios from 'axios';
2019-10-28 16:21:04 -04:00
import { Client } from '..';
2019-10-21 19:58:56 -04:00
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'] };
}
2019-10-28 16:21:04 -04:00
public async run(message: Message, args: string[]) {
2019-10-21 19:58:56 -04:00
try {
2019-10-28 16:21:04 -04:00
// const evalMessage = message.content.slice(this.client.config.prefix.length).split(' ').slice(1).join(' ');
2019-10-21 19:58:56 -04:00
let evaled: any;
try {
2019-10-28 16:21:04 -04:00
evaled = await eval(args.join(' ').trim());
if (typeof evaled !== 'string') {
evaled = inspect(evaled, { depth: 0 });
}
if (evaled === undefined) {
evaled = 'undefined';
}
2019-10-21 19:58:56 -04:00
} catch (error) {
2019-10-28 16:21:04 -04:00
evaled = error.stack;
2019-10-21 19:58:56 -04:00
}
2019-10-28 16:21:04 -04:00
/*
2019-10-21 19:58:56 -04:00
if (output) {
2019-10-28 16:21:04 -04:00
output = output.replace(RegExp(this.client.config.prefix, 'gi'), 'juul');
output = output.replace(RegExp(this.client.config.emailPass, 'gi'), 'juul');
output = output.replace(RegExp(this.client.config.cloudflare, 'gi'), 'juul');
2019-10-21 19:58:56 -04:00
}
2019-10-28 16:21:04 -04:00
*/
2019-10-21 19:58:56 -04:00
2019-10-28 16:21:04 -04:00
const display = this.client.util.splitString(evaled, 1975);
2019-10-21 19:58:56 -04:00
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 output can be found on https://snippets.cloud.libraryofcode.org/${data.key}`);
} catch (error) {
return message.channel.createMessage(`${this.client.stores.emojis.error} ${error}`);
}
2019-10-21 19:58:56 -04:00
}
2019-10-21 20:20:11 -04:00
return display.forEach((m) => message.channel.createMessage(`\`\`\`js\n${m}\n\`\`\``));
2019-10-21 19:58:56 -04:00
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
}