New edit and delete logs
diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts
index b7eb745..3ead1c5 100644
--- a/src/events/interactionCreate.ts
+++ b/src/events/interactionCreate.ts
@@ -46,16 +46,60 @@
: false;
return await modifySuggestion(interaction, value);
}
- if (interaction.customId === "log:edit") {
- const attachment = interaction.message.embeds[0]?.image;
- console.log(attachment)
+ if (interaction.customId === "log:message.edit") {
+ await interaction.channel?.messages.fetch({ message: interaction.message.id, force: true });
+ const attachment = interaction.message.embeds[0]?.image ?? interaction.message.attachments.first();
if (!attachment) return;
- const attachmentData = await (await fetch(attachment.url)).text()
- console.log(attachmentData)
+ const attachmentData = await (await fetch(attachment.url)).text();
const decoded = atob(attachmentData);
- console.log("decoded", decoded)
- const json = JSON.parse(decoded);
- console.log("json", json)
+ const json = (
+ JSON.parse(decoded) as { data: { count: number; value: string; added?: boolean; removed?: boolean }[] }
+ ).data;
+ // "Before" is everything where added is false
+ // "After" is everything where removed is false
+ const before: string = json
+ .filter((d) => !d.added)
+ .map((d) => d.value)
+ .join("");
+ const after: string = json
+ .filter((d) => !d.removed)
+ .map((d) => d.value)
+ .join("");
+ const { renderDateFooter } = client.logger;
+ await interaction.reply({
+ embeds: [
+ new EmojiEmbed()
+ .setTitle("Before")
+ .setDescription(before)
+ .setStatus("Danger")
+ .setEmoji("ICONS.OPP.ADD"),
+ new EmojiEmbed()
+ .setTitle("After")
+ .setDescription(after)
+ .setStatus("Success")
+ .setEmoji("ICONS.ADD")
+ .setFooter({ text: `Edited at ${renderDateFooter(interaction.message.createdTimestamp!)}` }) // Created timestamp of the log is when the edit was made
+ ],
+ ephemeral: true
+ });
+ } else if (interaction.customId === "log:message.delete") {
+ await interaction.channel?.messages.fetch({ message: interaction.message.id, force: true });
+ const attachment = interaction.message.embeds[0]?.image ?? interaction.message.attachments.first();
+ if (!attachment) return;
+ const attachmentData = await (await fetch(attachment.url)).text();
+ const decoded = atob(attachmentData);
+ const json = JSON.parse(decoded) as { data: string };
+ await interaction.reply({
+ embeds: [
+ new EmojiEmbed()
+ .setTitle("Message")
+ .setDescription(json.data)
+ .setStatus("Danger")
+ .setEmoji("MESSAGE.DELETE")
+ .setFooter({ text: `Deleted at ${client.logger.renderDateFooter(Date.now())}` })
+ ],
+ ephemeral: true
+ });
}
switch (interaction.customId) {
case "rolemenu": {
diff --git a/src/events/messageDelete.ts b/src/events/messageDelete.ts
index b847400..8188a67 100644
--- a/src/events/messageDelete.ts
+++ b/src/events/messageDelete.ts
@@ -1,5 +1,6 @@
import type { NucleusClient } from "../utils/client.js";
-import Discord, { AuditLogEvent, GuildAuditLogsEntry, Message, User } from "discord.js";
+import Discord, { AuditLogEvent, ButtonStyle, GuildAuditLogsEntry, Message, User } from "discord.js";
+import { imageDataEasterEgg } from "../utils/defaults.js";
export const event = "messageDelete";
@@ -33,6 +34,7 @@
if (config) {
attachmentJump = ` [[View attachments]](${config})`;
}
+ const imageData = JSON.stringify({ data: message.content, extra: imageDataEasterEgg }, null, 2);
const data = {
meta: {
type: "messageDelete",
@@ -40,7 +42,9 @@
calculateType: "messageDelete",
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
- timestamp: Date.now()
+ timestamp: Date.now(),
+ imageData: imageData,
+ buttons: [{ buttonText: "View text", buttonId: "log:message.delete", buttonStyle: ButtonStyle.Secondary }]
},
separate: {
start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*"
diff --git a/src/events/messageEdit.ts b/src/events/messageEdit.ts
index f61a873..35de994 100644
--- a/src/events/messageEdit.ts
+++ b/src/events/messageEdit.ts
@@ -3,6 +3,7 @@
import type Discord from "discord.js";
import * as diff from "diff";
import addPlural from "../utils/plurals.js";
+import { imageDataEasterEgg } from "../utils/defaults.js";
export const event = "messageUpdate";
@@ -10,16 +11,8 @@
if (newMessage.author.id === client.user!.id) return;
if (newMessage.author.bot) return;
if (!newMessage.guild) return;
- const {
- log,
- isLogging,
- NucleusColors,
- entry,
- renderUser,
- renderDelta,
- renderNumberDelta,
- renderChannel
- } = client.logger;
+ const { log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderNumberDelta, renderChannel } =
+ client.logger;
const replyTo: MessageReference | null = newMessage.reference;
const newContent = newMessage.cleanContent.replaceAll("`", "‘");
const oldContent = oldMessage.cleanContent.replaceAll("`", "‘");
@@ -72,14 +65,15 @@
return;
}
const differences = diff.diffChars(oldContent, newContent);
- const charsAdded = (differences.filter((d) => d.added).map((d) => d.count)).reduce((a, b) => a! + b!, 0)!;
- const charsRemoved = (differences.filter((d) => d.removed).map((d) => d.count)).reduce((a, b) => a! + b!, 0)!;
- const imageData = JSON.stringify({data: differences, extra: "The image in this embed contains data about the below log.\n" +
- "It isn't designed to be read by humans, but you can decode " +
- "it with any base64 decoder, and then read it as JSON.\n" +
- "We use base 64 to get around people using virus tests and the file being blocked, and an image to have the embed hidden (files can't be suppressed)\n" +
- "If you've got to this point and are reading this hidden message, you should come and work with us " +
- "at https://discord.gg/w35pXdrxKW (Internal development server) and let us know how you got here."}, null, 2)
+ const charsAdded = differences
+ .filter((d) => d.added)
+ .map((d) => d.count)
+ .reduce((a, b) => a! + b!, 0)!;
+ const charsRemoved = differences
+ .filter((d) => d.removed)
+ .map((d) => d.count)
+ .reduce((a, b) => a! + b!, 0)!;
+ const imageData = JSON.stringify({ data: differences, extra: imageDataEasterEgg }, null, 2);
const data = {
meta: {
type: "messageUpdate",
@@ -88,7 +82,7 @@
color: NucleusColors.yellow,
emoji: "MESSAGE.EDIT",
timestamp: newMessage.editedTimestamp,
- buttons: [{ buttonText: "View Changes", buttonStyle: ButtonStyle.Secondary, buttonId: `log:edit` }],
+ buttons: [{ buttonText: "View Changes", buttonStyle: ButtonStyle.Secondary, buttonId: `log:message.edit` }],
imageData: imageData
},
separate: {