Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

snipe #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 162 additions & 0 deletions snipe
Original file line number Diff line number Diff line change
@@ -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];