feat: better handling for message edits
Code Analysis / SonarQube (push) Failing after 18s
Node.js CI / Lint and Test (push) Failing after 33s

This commit is contained in:
2025-07-08 13:43:14 -07:00
parent c47c46e69a
commit 91d7a1ef28
4 changed files with 39 additions and 7 deletions
+7 -7
View File
@@ -4,6 +4,7 @@ import { ExtendedClient } from "../../interfaces/ExtendedClient";
import { getConfig } from "../../modules/data/getConfig";
import { customSubstring } from "../../utils/customSubstring";
import { errorHandler } from "../../utils/errorHandler";
import { generateDiff } from "../../modules/events/generateDiff";
/**
* Handles a message edit event.
@@ -46,16 +47,15 @@ export const onMessageEdit = async (
return;
}
const diffContent
= (oldMessage.content ?? newMessage.content) === null
? "This message appears to have no content."
: generateDiff(oldMessage.content ?? "", newMessage.content ?? "");
await logChannel.send({
content: `${author?.tag} (${author?.id}) edited their message in in <#${
channel.id
}>:\n\n**Old Content:**\n\`${customSubstring(
oldMessage.content,
1750
)}\`\n\n**New content:**\n\`${customSubstring(
newMessage.content,
1750
)}\`\n\n${newMessage.url}`,
}>:\`\`\`diff\n${customSubstring(diffContent, 4000)}\n\`\`\``,
allowedMentions: { parse: [] }
});
} catch (err) {
+22
View File
@@ -0,0 +1,22 @@
import { diffSentences } from "diff";
/**
* Module to generate a diff string from two strings.
* @param old - The old string.
* @param updated - The new string.
* @returns The diff string, formatted.
*/
export const generateDiff = (old: string, updated: string): string => {
return diffSentences(old, updated).
map((element) => {
if (element.added) {
return `+ ${element.value}`;
}
if (element.removed) {
return `- ${element.value}`;
}
return "";
}).
filter(Boolean).
join("\n");
};