thaldrin/DiscordModules/Developers/eval.js

81 lines
2.0 KiB
JavaScript
Raw Normal View History

2019-11-10 08:42:09 +00:00
const Command = require('../../src/structures/Command');
const { table } = require('quick.db');
const Servers = new table('servers');
const Users = new table('users');
const Bot = new table('bot');
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
const clean = (text) => {
if (typeof text == 'string')
return text.replace(/`/g, '`' + String.fromCharCode(8203)).replace(/@/g, '@' + String.fromCharCode(8203));
else return text;
2019-10-14 11:19:41 +00:00
};
module.exports = class Eval extends Command {
2019-11-10 08:42:09 +00:00
constructor() {
super({
name: 'eval',
description: 'Run JavaScript code directly from the process.',
aliases: [ 'ev', 'e' ],
module: 'Developers',
cooldown: 0,
guildOnly: false,
developerOnly: true
});
}
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
async command(ctx) {
if (!ctx.args.length) return;
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
const client = ctx.client;
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
let code = ctx.args.join(' ');
let silent = false;
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
if (code.endsWith('-s')) (code = code.split('-s')[0]), (silent = true);
if (code.endsWith('--silent')) (code = code.split('--silent')[0]), (silent = true);
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
try {
let evaled = await eval(code);
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
if (typeof evaled != 'string')
evaled = require('util').inspect(evaled, false, await ctx.db.backend.get('eval'));
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
evaled.replace(new RegExp(client.token.replace(/\./g, '\\.', 'g')), 'uwu');
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
if (!silent) {
ctx
.send(`\`\`\`js\n${clean(evaled)}\n\`\`\``)
.then(async (m) => {
await m.react('📥');
await m.react('🗑');
})
.catch((err) => {
ctx
.send(`\`Content is over 2,000 characters: react to upload to Hastebin\``)
.then(async (m) => {
client.lastEval = clean(evaled);
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
await m.react('📥');
await m.react('🗑');
});
});
}
} catch (error) {
ctx
.send(`\`\`\`js\n${clean(error)}\n\`\`\``)
.then(async (m) => {
await m.react('📥');
await m.react('🗑');
})
.catch((err) => {
ctx.send(`\`Content is over 2,000 characters: react to upload to Hastebin\``).then(async (m) => {
client.lastEval = clean(error);
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
await m.react('📥');
await m.react('🗑');
});
});
}
}
2019-10-14 11:19:41 +00:00
};