fix(discord-gateway): handle forwarded message content via messageSnapshots

Two-layer fix for forwarded messages showing as empty/clean:

Layer 1 (messageMetadata.ts): getReferencedMessageContent() now falls
back to message.messageSnapshots Collection when channel.messages.cache
lookup fails. Discord stores forward content in message_snapshots API
field, not in message.content.

Layer 2 (moderationBuilders.ts): buildReferenceXml() now parses msg.
metadata JSON to extract reference.content when DB getMessageById()
fails (cross-server forwards not in local DB).

Previously: forward messages captured with empty parentContent →
LLM saw no reference text → '99% confidence, pesan kosong'.
Now: forward content flows through capture → metadata → analysis.
This commit is contained in:
MythEclipse
2026-06-23 23:27:23 +07:00
parent ed4a506ca7
commit d5c22a3959
2 changed files with 40 additions and 4 deletions
@@ -48,6 +48,7 @@ export async function buildReferenceXml(msg: MessageRecord): Promise<string> {
let parentContent = "";
if (msg.reference_message_id) {
// 1. Try DB first — works for messages captured in the same server
try {
const parent = await getMessageById(msg.reference_message_id);
if (parent) {
@@ -55,7 +56,22 @@ export async function buildReferenceXml(msg: MessageRecord): Promise<string> {
parentContent = parentText.slice(0, 500);
}
} catch {
// Parent fetch failed — still inject reference with available info
// Parent fetch failed — fall through to metadata
}
// 2. Fall back to metadata — works for forwards from other servers/channels
// where the original message was never captured in this DB.
// The capture phase stores the snapshot content in metadata.reference.content.
if (!parentContent && msg.metadata) {
try {
const meta = JSON.parse(msg.metadata);
const refContent = meta?.reference?.content;
if (refContent && typeof refContent === "string") {
parentContent = refContent.slice(0, 500);
}
} catch {
// Metadata parse failed — no fallback available
}
}
}