From be37e998e58ee425d0fe0759724dc8dfa4f492d2 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 18 Feb 2021 15:22:32 +0100 Subject: [PATCH] h --- commands/eval.js | 52 ++++++++++++++++++++++++++++++++++++++++++++ util/eventHandler.js | 2 +- util/wit.js | 14 ++++-------- 3 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 commands/eval.js diff --git a/commands/eval.js b/commands/eval.js new file mode 100644 index 0000000..81efd5c --- /dev/null +++ b/commands/eval.js @@ -0,0 +1,52 @@ +const Discord = require('discord.js'); +const { inspect } = require('util'); +const { logger, client } = require('../'); + +module.exports.meta = { + name: 'eval', + aliases: ['e'] +} + +/** + * @param {Discord.Message} message + * @param {Array} args + */ +module.exports.run = async (message, args) => { + const ownerID = process.env.OWNER_ID; + if (!ownerID) return message.channel.send('Error: Bot owner is not configured. Set `OWNER_ID` env var.'); + if (ownerID != message.author.id) { + logger.warn(`${message.author.tag} ${message.author.id} => Not bot owner`); + return; + } + + try { + const exec = args.join(' '); + if (!exec) return message.channel.send('What do you want me to do, dumbass'); + + eval( + `(async () => {` + + `${exec.replace(/(```\w*\n)|\n```$/g, '')}\n` + + `})()` + ) + .then(res => { + if (res == undefined) + message.react('✅') + .catch(() => message.channel.send('```js\nundefined\n```')); + else + message.channel.send( + `\`\`\`js\n${ + inspect(res) + .replace(new RegExp(client.token, 'g'), '[Token removed]') + .slice(0, 1989) + }\n\`\`\`` + ); + }) + .catch(e => { + message.channel.send(`\`\`\`js\n${(e && e.name && e.message ? `${e.name}: ${e.message}` : `Error: ${e}`).slice(0, 1989)}\n\`\`\``) + .catch(a => message.channel.send(a)); + }); + } catch(e) { + message.channel.send(`\`\`\`js\n${(e && e.name && e.message ? `${e.name}: ${e.message}` : `Error: ${e}`).slice(0, 1989)}\n\`\`\``) + .catch(a => message.channel.send(a)); + } +} diff --git a/util/eventHandler.js b/util/eventHandler.js index 59c85d4..0368781 100644 --- a/util/eventHandler.js +++ b/util/eventHandler.js @@ -47,7 +47,7 @@ client.on('message', message => { ) return; } - else if (cmd.meta?.epicOnly && !message.member.roles.cache.get('718862546395988078')) { + else if (cmd.meta?.epicOnly && !message.member?.roles.cache.get('718862546395988078')) { logger.warn(`${message.author.tag} => Refusing to run epic only command`); message.channel.send( new Discord.MessageEmbed() diff --git a/util/wit.js b/util/wit.js index 71db1e5..d749ba9 100644 --- a/util/wit.js +++ b/util/wit.js @@ -19,7 +19,7 @@ const coinsDB = require('./karma').coins; /** * @param {Message} message */ -module.exports.execute = function(message) { +module.exports.execute = async (message) => { if (!message.content) return; if (message.content.length > 280) return randomAward(); @@ -38,14 +38,8 @@ module.exports.execute = function(message) { return; // Spam a fuckton of awards - message.react('731564182079799306').then(() => { - message.react('719181283393142786').catch().then(() => { - message.react('731192828415443116').catch().then(() => { - message.react('731192829262692372').catch().then(() => { - message.react('731192942080950333').catch().then(() => { - message.react('731508866273247252').catch().then(() => { - message.react('716021350883393566').catch(); - })})})})})}); + ['731564182079799306', '719181283393142786', '731192828415443116', '731192829262692372', '731192942080950333', '731508866273247252', '716021350883393566'] + .forEach(async id => await message.react(id)); break; case 'upvote': message.react('719181283393142786'); @@ -65,7 +59,7 @@ module.exports.execute = function(message) { }) .catch(error => { console.error(error); - message.channel.send('Wit.ai error:\n' + error); + message.channel.send(`Wit.ai error:\n\`\`\`js\n${error}\`\`\``); }); function randomAward(multiplier) { if (!multiplier) multiplier = 1;