const { MessageEmbed, Permissions, MessageAttachment } = require("discord.js"); const { red, black } = require("../../other/texts/colors.json"); const { inspect } = require("util"); const { Type } = require("@extreme_hero/deeptype"); function clean(text) { if (typeof text === 'string') { text = text .replace(/`/g, `\`${String.fromCharCode(8203)}`) .replace(/@/g, `@${String.fromCharCode(8203)}`) .replace(new RegExp(process.env.TOKEN, 'gi'), '****') } return text; } module.exports = { config: { name: "eval", aliases: ['ev'], usage: "eval", category: "owner", description: "Evaluates a command.", noalias: "No Aliases", accessableby: "Developers" }, run: async (bot, message, args) => { if (!message.channel.permissionsFor(message.guild.me).has([Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.EMBED_LINKS])) return; if (message.author.id != "528256079101034506") return; const msg = message; let embedError = new MessageEmbed() .setColor(red) if (!args.length) { embedError.setDescription("❌ I need a code to evaluate."); return await message.channel.send({ embeds: [embedError] }); }; let code = args.join(' '); code = code.replace(/[“”]/g, '"').replace(/[‘’]/g, "'"); let evaled; try { const start = process.hrtime(); evaled = eval(code); if (evaled instanceof Promise) evaled = await evaled; const stop = process.hrtime(start); const response = [ `**Output:** \`\`\`js\n${clean(inspect(evaled, { depth: 0 }))}\n\`\`\``, `**Type:** \`\`\`ts\n${new Type(evaled).is}\n\`\`\``, `**Time Taken:** \`\`\`${(((stop[0] * 1e9) + stop[1])) / 1e6}ms \`\`\`` ]; const res = response.join('\n'); if (res.length < 2000) { await msg.channel.send({ content: res }) } else { const output = new MessageAttachment(Buffer.from(res), 'output.txt'); await msg.channel.send({ content: output }) } } catch (error) { return await message.channel.send({ content: `Error: \`\`\`xl\n${clean(error)}\n\`\`\`` }); } }, };