Almost finished logs
diff --git a/src/config/default.ts b/src/config/default.ts
index 69de019..ea5600d 100644
--- a/src/config/default.ts
+++ b/src/config/default.ts
@@ -61,7 +61,7 @@
stats: {},
logging: {
logs: {
- enabled: false,
+ enabled: true,
channel: null,
toLog: "3fffff"
},
diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts
index 5277383..b7eb745 100644
--- a/src/events/interactionCreate.ts
+++ b/src/events/interactionCreate.ts
@@ -46,13 +46,16 @@
: false;
return await modifySuggestion(interaction, value);
}
- if (interaction.customId.startsWith("log:edit:")) {
- const messageId = interaction.customId.split(":")[2];
- const message = await interaction.channel?.messages.fetch(messageId!);
- const attachment = message?.attachments.find((a) => a.name === "log.json");
+ if (interaction.customId === "log:edit") {
+ const attachment = interaction.message.embeds[0]?.image;
+ console.log(attachment)
if (!attachment) return;
- const log = JSON.parse(Buffer.from(await (await fetch(attachment.url)).text(), 'base64').toString('binary'));
- console.log(log);
+ const attachmentData = await (await fetch(attachment.url)).text()
+ console.log(attachmentData)
+ const decoded = atob(attachmentData);
+ console.log("decoded", decoded)
+ const json = JSON.parse(decoded);
+ console.log("json", json)
}
switch (interaction.customId) {
case "rolemenu": {
diff --git a/src/events/messageEdit.ts b/src/events/messageEdit.ts
index 5964df9..f61a873 100644
--- a/src/events/messageEdit.ts
+++ b/src/events/messageEdit.ts
@@ -18,8 +18,7 @@
renderUser,
renderDelta,
renderNumberDelta,
- renderChannel,
- preLog
+ renderChannel
} = client.logger;
const replyTo: MessageReference | null = newMessage.reference;
const newContent = newMessage.cleanContent.replaceAll("`", "‘");
@@ -73,10 +72,14 @@
return;
}
const differences = diff.diffChars(oldContent, newContent);
- const charsAdded = differences.filter((x) => x.added).length;
- const charsRemoved = differences.filter((x) => x.removed).length;
- const preLogMessage = await preLog(newMessage.guild.id, JSON.stringify(differences, null, 2));
- if (!preLogMessage) return;
+ 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 data = {
meta: {
type: "messageUpdate",
@@ -85,10 +88,11 @@
color: NucleusColors.yellow,
emoji: "MESSAGE.EDIT",
timestamp: newMessage.editedTimestamp,
- changes: { messageId: `${preLogMessage.id}`, buttonText: "View Changes", buttonStyle: ButtonStyle.Secondary, buttonId: `log:edit:${preLogMessage.id}` }
+ buttons: [{ buttonText: "View Changes", buttonStyle: ButtonStyle.Secondary, buttonId: `log:edit` }],
+ imageData: imageData
},
separate: {
- start: `${charsAdded} ${addPlural(charsAdded, "character")} added, ${charsRemoved} ${addPlural(charsRemoved, "character")} removed`,
+ start: `${addPlural(charsAdded, "character")} added, ${addPlural(charsRemoved, "character")} removed`,
end: `[[Jump to message]](${newMessage.url})`
},
list: {
diff --git a/src/utils/log.ts b/src/utils/log.ts
index 325aaa8..2679fd6 100644
--- a/src/utils/log.ts
+++ b/src/utils/log.ts
@@ -4,7 +4,6 @@
import generateKeyValueList from "./generateKeyValueList.js";
import client from "./client.js";
import { DiscordAPIError } from "discord.js";
-import { Stream } from "node:stream";
import EmojiEmbed from "./generateEmojiEmbed.js";
const wait = promisify(setTimeout);
@@ -17,15 +16,8 @@
color: number;
emoji: string;
timestamp: number;
- files?: (
- | Discord.BufferResolvable
- | Stream
- | Discord.JSONEncodable<Discord.APIAttachment>
- | Discord.Attachment
- | Discord.AttachmentBuilder
- | Discord.AttachmentPayload
- )[];
- showDetails?: boolean;
+ buttons?: { buttonText: string, buttonId: string, buttonStyle: Discord.ButtonStyle }[];
+ imageData?: string;
};
list: Record<string | symbol | number, unknown>;
hidden: {
@@ -47,6 +39,13 @@
return true;
}
+const NucleusColors = {
+ red: 0xf27878,
+ yellow: 0xf2d478,
+ green: 0x68d49e,
+ blue: 0x72aef5,
+};
+
export const Logger = {
renderUser(user: Discord.User | string) {
if (typeof user === "string") user = client.users.cache.get(user)!;
@@ -86,11 +85,7 @@
renderEmoji(emoji: Discord.GuildEmoji) {
return `<${emoji.animated ? "a" : ""}:${emoji.name}:${emoji.id}> [\`:${emoji.name}:\`]`;
},
- NucleusColors: {
- red: 0xf27878,
- yellow: 0xf2d478,
- green: 0x68d49e
- },
+ NucleusColors,
async getAuditLog(
guild: Discord.Guild,
event: Discord.GuildAuditLogsResolvable,
@@ -106,22 +101,7 @@
throw e;
}
},
- async preLog(guild: string, file: string): Promise<Discord.Message | void> {
- const config = await client.database.guilds.read(guild);
- if (!config.logging.logs.channel) return;
- const channel = (await client.channels.fetch(config.logging.logs.channel)) as Discord.TextChannel | null;
- if (!channel) return;
- const message = await channel.send({
- files: [
- {
- attachment: Buffer.from(file, "base64"),
- name: "log.json"
- }
- ],
- flags: ["SuppressEmbeds"]
- });
- return message;
- },
+
async log(log: LoggerOptions): Promise<void> {
if (!(await isLogging(log.hidden.guild, log.meta.calculateType))) return;
const config = await client.database.guilds.read(log.hidden.guild);
@@ -139,6 +119,7 @@
description[key] = value;
}
});
+ console.log("imageData", log.meta.imageData)
if (channel) {
log.separate = log.separate ?? {};
const messageOptions: Parameters<Discord.TextChannel["send"]>[0] = {};
@@ -154,17 +135,29 @@
)
.setTimestamp(log.meta.timestamp)
.setColor(log.meta.color)
+ .setImage(log.meta.imageData ? "attachment://extra_log_data.json.base64" : null)
];
- if (log.meta.files) messageOptions.files = log.meta.files;
- if (log.meta.showDetails) {
- components.addComponents(
- new Discord.ButtonBuilder()
- .setCustomId("log:showDetails")
- .setLabel("Show Details")
- .setStyle(Discord.ButtonStyle.Primary)
- );
+ if (log.meta.buttons) {
+ const buttons = []
+ for (const button of log.meta.buttons) {
+ buttons.push(
+ new Discord.ButtonBuilder()
+ .setCustomId(button.buttonId)
+ .setLabel(button.buttonText)
+ .setStyle(button.buttonStyle)
+ )
+ }
+ components.addComponents(buttons);
messageOptions.components = [components];
}
+ if (log.meta.imageData) {
+ messageOptions.files = [
+ {
+ attachment: Buffer.from(btoa(log.meta.imageData), "utf-8"), // Use base 64 to prevent virus scanning (EICAR)Buffer.from(log.meta.imageData, "base64"),
+ name: "extra_log_data.json.base64"
+ }
+ ];
+ }
await channel.send(messageOptions);
}
}