feat(ai-moderation): use per-server nickname (displayName) in analysis payload

- resolveDisplayName(): member.displayName from captured metadata,
  falls back to global username
- Applied to context lines, target message blocks, and media message
  blocks — LLM sees the name the channel actually sees (nickname can
  carry moderation signal itself)
This commit is contained in:
asepharyana
2026-08-10 11:36:37 +07:00
parent 4049ab4201
commit ecbb538c9f
5 changed files with 52 additions and 3 deletions
@@ -5,6 +5,7 @@ import { describe, expect, it } from "vitest";
import {
buildConversationContext,
buildLocationContext,
formatMessageForPrompt,
} from "../src/modules/ai-moderation/conversationContext.js";
import { extractOgMeta } from "../src/modules/ai-moderation/urlFetcher.js";
import type { MessageRecord } from "../src/modules/message-capture/types.js";
@@ -139,6 +140,30 @@ describe("buildConversationContext — recency gating", () => {
});
});
describe("formatMessageForPrompt — server nickname (displayName)", () => {
it("renders member.displayName when captured (per-server nickname)", () => {
const m = msg("n1", NOW - MIN);
m.metadata = JSON.stringify({
member: {
displayName: "Si Goblok Server",
roles: [],
joinedTimestamp: null,
},
});
const line = formatMessageForPrompt(m, "context");
expect(line).toContain("user=Si Goblok Server");
expect(line).not.toContain("user_user_n1");
});
it("falls back to global username when displayName missing", () => {
const line = formatMessageForPrompt(
msg("n2", NOW - MIN, "halo"),
"context",
);
expect(line).toContain("user=user_n2");
});
});
describe("buildLocationContext — channel/thread/nsfw enrichment", () => {
it("renders channel name + thread name from captured metadata", () => {
const t = target();