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": {