Refactor code for improved readability and consistency

- Adjusted formatting in conversationContext.ts for better token estimation readability.
- Enhanced readability in indonesianTextNormalizer.ts by formatting multiline replacements.
- Reformatted badword lists and whitelists in indonesianTextNormalizer.ts for consistency.
- Improved function signatures in messageStore.ts for clarity.
- Reformatted messageCapture.ts to enhance readability of channel ID checks.
- Cleaned up error logging in messageStore.ts and retentionManager.ts for better clarity.
- Reformatted indonesianSlangLexicon.ts for consistent object formatting.
- Enhanced URL fetching regex patterns in urlFetcher.ts for better readability.
- Simplified query parameter destructuring in analyticsRoutes.ts for cleaner code.
- Improved test readability in autoDeleteManager.test.ts and indonesianTextNormalizer.test.ts by formatting expectations.
- Cleaned up whitespace in messageCaptureFilter.test.ts for consistency.
This commit is contained in:
MythEclipse
2026-05-30 15:55:01 +07:00
parent 4fa7875b80
commit 551d11ba82
18 changed files with 697 additions and 224 deletions
+17 -7
View File
@@ -46,11 +46,13 @@ function createMessage(overrides: Partial<MessageRecord> = {}): MessageRecord {
};
}
function createClient(options: {
canManageMessages?: boolean;
fetchError?: unknown;
deleteError?: unknown;
} = {}) {
function createClient(
options: {
canManageMessages?: boolean;
fetchError?: unknown;
deleteError?: unknown;
} = {},
) {
const deleteMock = vi.fn(async () => {
if (options.deleteError) throw options.deleteError;
});
@@ -113,7 +115,11 @@ describe("attemptAutoDeleteFlaggedMessage", () => {
createMessage(), // defaults to flagged
);
expect(result).toEqual({ deleted: true, skipped: false, reason: "deleted" });
expect(result).toEqual({
deleted: true,
skipped: false,
reason: "deleted",
});
expect(fetchMessageMock).toHaveBeenCalledWith("m1");
expect(deleteMock).toHaveBeenCalledTimes(1);
});
@@ -127,7 +133,11 @@ describe("attemptAutoDeleteFlaggedMessage", () => {
createMessage({ ai_status: "warn" }),
);
expect(result).toEqual({ deleted: true, skipped: false, reason: "deleted" });
expect(result).toEqual({
deleted: true,
skipped: false,
reason: "deleted",
});
expect(fetchMessageMock).toHaveBeenCalledWith("m1");
expect(deleteMock).toHaveBeenCalledTimes(1);
});
@@ -9,7 +9,9 @@ import {
describe("normalizeDiscordCustomEmoji", () => {
it("replaces static custom emoji", () => {
const result = normalizeDiscordCustomEmoji("Bersiaplah woy <:hadeh:1217434294281048185>");
const result = normalizeDiscordCustomEmoji(
"Bersiaplah woy <:hadeh:1217434294281048185>",
);
expect(result.text).toBe("Bersiaplah woy [emoji:hadeh]");
expect(result.emojiNames).toContain("hadeh");
});
@@ -61,7 +63,9 @@ describe("buildModerationTextEvidence", () => {
expect(evidence.normalized).toContain("[emoji:hadeh]");
expect(evidence.badwords).toHaveLength(0);
expect(evidence.hasBadwords).toBe(false);
expect(evidence.notes.some((n) => n.includes("no Indonesian badword"))).toBe(true);
expect(
evidence.notes.some((n) => n.includes("no Indonesian badword")),
).toBe(true);
expect(evidence.notes.some((n) => n.includes("emoji:hadeh"))).toBe(true);
expect(evidence.notes.some((n) => n.includes("casual"))).toBe(true);
});
@@ -69,7 +73,9 @@ describe("buildModerationTextEvidence", () => {
it("detects badword when present", async () => {
const evidence = await buildModerationTextEvidence("anjing loe kontol");
expect(evidence.hasBadwords).toBe(true);
expect(evidence.notes.some((n) => n.includes("badword detected"))).toBe(true);
expect(evidence.notes.some((n) => n.includes("badword detected"))).toBe(
true,
);
});
});
@@ -32,7 +32,7 @@ describe("shouldCaptureMessageLocation", () => {
{ guildId: "guild-1" },
),
).toBe(false);
expect(
shouldCaptureMessageLocation(
{ guildId: "guild-1", channelId: "1265679542144467035" },