refactor(capture): DRY age-restricted check, use Set for excluded IDs

- Move isAgeRestrictedMessage to messageMetadata.ts alongside
  isAgeRestrictedMetadata — single source of truth for NSFW logic
- Replace || chain of channel IDs with a Set for O(1) lookup
- Import isAgeRestrictedMessage in capture layer instead of inline

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
MythEclipse
2026-06-12 17:03:01 +07:00
co-authored by Claude
parent ebfe942db9
commit c91f9f18cc
2 changed files with 38 additions and 35 deletions
@@ -278,6 +278,34 @@ export function isAgeRestrictedMetadata(
);
}
export function isAgeRestrictedMessage(message: Message): boolean {
try {
const channel = message.channel as {
nsfw?: boolean;
nsfwLevel?: string | number | null;
isThread?: () => boolean;
parent?: { nsfw?: boolean; nsfwLevel?: string | number | null } | null;
};
if (channel.nsfw) return true;
if (
typeof channel.nsfwLevel === "string" &&
channel.nsfwLevel.toUpperCase() === "AGE_RESTRICTED"
)
return true;
if (channel.isThread?.() && channel.parent) {
if (channel.parent.nsfw) return true;
if (
typeof channel.parent.nsfwLevel === "string" &&
channel.parent.nsfwLevel.toUpperCase() === "AGE_RESTRICTED"
)
return true;
}
} catch {
// Can't determine → allow capture
}
return false;
}
export function extractMessageMediaEvidence(
metadata: string | null | undefined,
): MessageMediaEvidence {