From b2da193ace6444cf356f8d14f9f2f6d497140299 Mon Sep 17 00:00:00 2001 From: oog <90022594+OOGSMAN@users.noreply.github.com> Date: Mon, 8 Aug 2022 18:01:15 -0700 Subject: [PATCH] Create snipe --- snipe | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 snipe diff --git a/snipe b/snipe new file mode 100644 index 0000000..3e97449 --- /dev/null +++ b/snipe @@ -0,0 +1,162 @@ +"license": "MIT", + "dependencies": { + "@discordjs/rest": "^0.1.0-canary.0", + "discord-api-types": "^0.22.0", + "discord.js": "^13.1.0" + } + }, + 1 +package.json +@@ -20,6 +20,7 @@ + "homepage": "https://github.com/DankMemer/sniper#readme", + "dependencies": { + "@discordjs/rest": "^0.1.0-canary.0", + "discord-api-types": "^0.22.0", + "discord.js": "^13.1.0" + } +} + 38 +scripts/register.js +@@ -5,40 +5,44 @@ const { token, application_id } = require("../config.json"); + +const guild = process.argv[2]; + +const channelOption = { + type: 7, // text channel + name: "channel", + description: "The channel to snipe", +}; +const commands = [ + { + name: "snipe", + description: "Shows the last deleted message from a specified channel!", + options: [ + channelOption, + { + type: 7, // text channel + name: "channel", + description: "The channel to snipe", + type: 3, // string + name: "options", + description: "Other parts of the deleted message, if present", + choices: [ + { + name: "embeds", + value: "embeds", + }, + { + name: "attachments", + value: "attachments", + }, + ], + }, + ], + }, + { + name: "editsnipe", + description: "Shows the last edited message from a specified channel!", + options: [ + { + type: 7, // text channel + name: "channel", + description: "The channel to snipe", + }, + ], + options: [channelOption], + }, + { + name: "reactionsnipe", + description: + "Shows the last removed reaction from a specified channel!", + options: [ + { + type: 7, // text channel + name: "channel", + description: "The channel to snipe", + }, + ], + options: [channelOption], + }, +]; + + 49 +src/index.js +@@ -8,6 +8,7 @@ const client = new Client({ + partials: ["MESSAGE", "REACTION", "USER"], +}); +const { token } = require("../config.json"); +const Paginator = require("./paginator"); + +const snipes = {}; +const editSnipes = {}; +@@ -19,20 +20,21 @@ const formatEmoji = (emoji) => { + : `[:${emoji.name}:](${emoji.url})`; // bot cannot use the emoji +}; + +process.on("unhandledRejection", console.error); // prevent exit on error + +client.on("ready", () => { + console.log(`[sniper] :: Logged in as ${client.user.tag}.`); +}); + +client.on("messageDelete", async (message) => { + if (message.partial || (message.embeds.length && !message.content)) return; // content is null or deleted embed + if (message.partial) return; // content is null or deleted embed + + snipes[message.channel.id] = { + author: message.author, + content: message.content, + embeds: message.embeds, + attachments: [...message.attachments.values()].map((a) => a.proxyURL), + createdAt: message.createdTimestamp, + image: message.attachments.first() + ? message.attachments.first().proxyURL + : null, + }; +}); + +@@ -68,14 +70,37 @@ client.on("interactionCreate", async (interaction) => { + + if (!snipe) return interaction.reply("There's nothing to snipe!"); + + const embed = new MessageEmbed() + .setAuthor(snipe.author.tag) + .setFooter(`#${channel.name}`) + .setTimestamp(snipe.createdAt); + snipe.content ? embed.setDescription(snipe.content) : null; + snipe.image ? embed.setImage(snipe.image) : null; + + await interaction.reply({ embeds: [embed] }); + const type = interaction.options.getString("options"); + + if (type === "embeds") { + if (!snipe.embeds.length) + return interaction.reply("The message has no embeds!"); + const paginator = new Paginator( + snipe.embeds.map((e) => ({ embeds: [e] })) + ); + await paginator.start({ interaction }); + } else if (type === "attachments") { + if (!snipe.attachments.length) + return interaction.reply("The message has no embeds!"); + const paginator = new Paginator( + snipe.attachments.map((a) => ({ content: a })) + ); + await paginator.start({ interaction }); + } else { + const embed = new MessageEmbed() + .setAuthor(snipe.author.tag) + .setFooter(`#${channel.name}`) + .setTimestamp(snipe.createdAt); + if (snipe.content) embed.setDescription(snipe.content); + if (snipe.attachments.length) embed.setImage(snipe.attachments[0]); + if (snipe.attachments.length || snipe.embeds.length) + embed.addField( + "Extra Info", + `*Message also contained \`${snipe.embeds.length}\` embeds and \`${snipe.attachments.length}\` attachments.*` + ); + + await interaction.reply({ embeds: [embed] }); + } + } else if (interaction.commandName === "editsnipe") { + const snipe = editSnipes[channel.id];