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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user