Haha-Yes/commands/owner/eval.js

46 lines
968 B
JavaScript
Raw Normal View History

2018-12-30 01:20:24 +01:00
const { Command } = require('discord-akairo');
class EvalCommand extends Command {
2019-01-02 08:09:45 +01:00
constructor() {
super('eval', {
aliases: ['eval'],
category: 'owner',
args: [
{
id: 'eval',
2019-01-14 11:41:15 +01:00
type: 'string',
match: 'rest'
2019-01-02 08:09:45 +01:00
}
],
ownerOnly: 'true',
description: {
2018-12-30 01:20:24 +01:00
content: 'Execute javascript',
usage: '[code]',
examples: ['message.channel.send(\'Hi\')']
}
2019-01-02 08:09:45 +01:00
});
}
2018-12-30 01:20:24 +01:00
2019-01-02 08:09:45 +01:00
async exec(message, args) {
const clean = text => {
if (typeof(text) === 'string')
return text.replace(/`/g, '`' + String.fromCharCode(8203)).replace(/@/g, '@' + String.fromCharCode(8203));
else
return text;
};
2018-12-30 01:20:24 +01:00
2019-01-02 08:09:45 +01:00
try {
const code = args.eval;
let evaled = eval(code);
if (typeof evaled !== 'string')
evaled = require('util').inspect(evaled);
message.channel.send(clean(evaled), {code:'xl'});
} catch (err) {
message.channel.send(`\`ERROR\` \`\`\`xl\n${clean(err)}\n\`\`\``);
}
}
2018-12-30 01:20:24 +01:00
}
module.exports = EvalCommand;