2021-09-06 12:38:25 +02:00
|
|
|
const Discord = require("discord.js");
|
|
|
|
module.exports = {
|
|
|
|
name: "eval",
|
|
|
|
category: "Owner",
|
|
|
|
usage: "(Code)",
|
|
|
|
Owner: true,
|
|
|
|
description: "Eval something",
|
|
|
|
type: "CHAT_INPUT",
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
type: 3,
|
|
|
|
name: "code",
|
|
|
|
description: "The code to eval",
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
],
|
2021-11-18 18:56:42 +01:00
|
|
|
run: async (client, interaction, args, utils) => {
|
|
|
|
const code = args[0];
|
2021-09-06 12:38:25 +02:00
|
|
|
function CheckFilter(object) {
|
|
|
|
if (typeof object === "string") {
|
|
|
|
object = object.replace(
|
2021-11-18 18:56:42 +01:00
|
|
|
new RegExp(`${client.token || process.env.TOKEN}`, "gi"),
|
2021-09-06 12:38:25 +02:00
|
|
|
"Cannot eval Token"
|
|
|
|
);
|
|
|
|
} else if (typeof object === "object") {
|
|
|
|
if (Array.isArray(object)) {
|
|
|
|
for (let i = 0; i < object.length; i++) {
|
|
|
|
object[i] = CheckFilter(object[i]);
|
|
|
|
}
|
|
|
|
} else {
|
2021-11-18 18:56:42 +01:00
|
|
|
for (const key in object) {
|
2021-09-06 12:38:25 +02:00
|
|
|
object[key] = CheckFilter(object[key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return object;
|
|
|
|
}
|
2021-11-18 18:56:42 +01:00
|
|
|
const oldSend = Discord.TextChannel.prototype.send;
|
2021-09-06 12:38:25 +02:00
|
|
|
Discord.TextChannel.prototype.send = async function send(content, options) {
|
|
|
|
return oldSend.bind(this)(CheckFilter(content), CheckFilter(options));
|
|
|
|
};
|
|
|
|
let evaled;
|
|
|
|
try {
|
|
|
|
evaled = eval(code);
|
|
|
|
if (evaled instanceof Promise) evaled = await evaled;
|
|
|
|
} catch (err) {
|
|
|
|
evaled = err;
|
|
|
|
}
|
|
|
|
if (typeof evaled !== "string") evaled = require("util").inspect(evaled);
|
2021-11-18 18:56:42 +01:00
|
|
|
evaled = utils.chunk(evaled, 750);
|
2021-09-06 12:38:25 +02:00
|
|
|
let reactions = ["❌", "⏪", "◀️", "⏹️", "▶️", "⏩"],
|
|
|
|
page = 0,
|
|
|
|
evaledEmbed = new Discord.MessageEmbed()
|
|
|
|
.setColor(client.color)
|
|
|
|
.setDescription(`\`\`\`js\n${evaled[0]}\n\`\`\``)
|
|
|
|
.setTimestamp()
|
|
|
|
.setAuthor(
|
|
|
|
`Evaled by ${interaction.user.tag}`,
|
|
|
|
interaction.user.displayAvatarURL({ dynamic: true })
|
|
|
|
)
|
|
|
|
.addField(`Type of`, `\`\`\`js\n${typeof evaled[0]}\n\`\`\``);
|
2021-11-18 18:56:42 +01:00
|
|
|
const mainMessage = await interaction.channel.send({ embeds: [evaledEmbed] });
|
2021-09-06 12:38:25 +02:00
|
|
|
Discord.TextChannel.prototype.send = oldSend;
|
|
|
|
await Promise.all(
|
|
|
|
(evaled.length === 1 ? ["❌", "⏹️"] : reactions).map(r =>
|
|
|
|
mainMessage.react(r)
|
|
|
|
)
|
|
|
|
);
|
2021-11-18 18:56:42 +01:00
|
|
|
const filter = (reaction, user) =>
|
2021-09-06 12:38:25 +02:00
|
|
|
(evaled.length === 1 ? ["❌", "⏹️"] : reactions).some(
|
|
|
|
e => e === reaction.emoji.name
|
|
|
|
) && user.id === interaction.user.id;
|
2021-11-18 18:56:42 +01:00
|
|
|
const collector = mainMessage.createReactionCollector({
|
2021-09-17 18:28:39 +02:00
|
|
|
filter,
|
2021-11-18 18:56:42 +01:00
|
|
|
time: 999999,
|
2021-09-06 12:38:25 +02:00
|
|
|
});
|
2021-11-18 18:56:42 +01:00
|
|
|
collector.on("collect", async reaction => {
|
2021-09-06 12:38:25 +02:00
|
|
|
switch (reaction.emoji.name) {
|
|
|
|
case "❌":
|
|
|
|
await collector.stop();
|
|
|
|
return mainMessage.delete();
|
|
|
|
case "⏪":
|
|
|
|
if (evaled.length === 1 || page === 0) return;
|
|
|
|
page = 0;
|
|
|
|
break;
|
|
|
|
case "◀️":
|
|
|
|
if (evaled.length === 1) return;
|
|
|
|
if (page === 0) {
|
|
|
|
page = evaled.length - 1;
|
|
|
|
} else {
|
|
|
|
page -= 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "⏹️":
|
|
|
|
await collector.stop();
|
2021-11-18 18:56:42 +01:00
|
|
|
for (const reaction of mainMessage.reactions.cache.map(e => e)) {
|
2021-09-06 12:38:25 +02:00
|
|
|
await reaction.users.remove(client.user.id);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case "▶️":
|
|
|
|
if (evaled.length === 1) return;
|
|
|
|
if (page === evaled.length - 1) {
|
|
|
|
page = 0;
|
|
|
|
} else {
|
|
|
|
page += 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "⏩":
|
|
|
|
if (evaled.length === 1 || page === evaled.length - 1) return;
|
|
|
|
page = evaled.length - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
evaledEmbed = new Discord.MessageEmbed()
|
|
|
|
.setColor(interaction.guild.me.displayColor)
|
|
|
|
.setDescription(`\`\`\`js\n${evaled[page]}\n\`\`\``)
|
|
|
|
.addField(`Type of`, `\`\`\`js\n${typeof evaled[page]}\n\`\`\``);
|
|
|
|
|
|
|
|
await mainMessage.edit({
|
|
|
|
embeds: [evaledEmbed],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|