Files
RedditBot/src/services/outbound-message-safety.ts
T

31 lines
1.8 KiB
TypeScript

const SHARED_LOCATION_PATTERNS: readonly RegExp[] = [
/\b(?:i(?:'m| am)|i live|i(?:'m| am) based)\s+(?:also\s+)?(?:in|near|around)\b[^.!?\n]{0,60}\b(?:too|as well)\b/i,
/\b(?:i(?:'m| am)|i live|i(?:'m| am) based)\s+also\s+(?:in|near|around)\b/i,
/\bwe(?:'re| are)\s+(?:both\s+)?(?:in|from|based in|near)\b/i,
/\b(?:same|nearby|local)\s+(?:area|city|town|county|country|location)\b/i,
/\b(?:not (?:too )?far|close|close by|nearby|local)\s+(?:from|to)\s+you\b/i,
/\byou(?:'re| are)\s+(?:so\s+)?(?:close|close by|nearby|local)\b/i,
/\b(?:near me|close to me|in my area|down the road|my neck of the woods|practically (?:my )?neighbou?rs?)\b/i,
/\b(?:that's|that is|you(?:'re| are))\s+not (?:too )?far away\b/i,
/\b(?:only|just)\s+\d+\s*(?:miles?|minutes?|hours?)\s+away\b/i,
/\b(?:another|fellow)\s+(?:brit|briton|british|english|scottish|welsh|irish|londoner)\b/i,
/\b(?:uk|england|scotland|wales|ireland|london)\s+(?:too|as well)\b/i,
];
const IN_PERSON_INVITATION_PATTERNS: readonly RegExp[] = [
/\b(?:meet|meet up|get together)\s+(?:in person|irl|sometime|tonight|today|tomorrow|this week|this weekend)\b/i,
/\b(?:we should|we could|want to|wanna|fancy|let's|shall we)\s+(?:meet|meet up|get together|grab (?:a )?(?:drink|coffee))\b/i,
/\b(?:come over|come round|visit me|see you in person)\b/i,
];
/**
* Prevent generated messages from implying physical proximity or inviting an
* in-person meeting. Stating the configured persona location by itself remains
* valid; relating it to the recipient's location does not. Prompts separately
* prohibit mentioning the recipient's location at all.
*/
export function isSafeOutboundMessage(message: string): boolean {
return !SHARED_LOCATION_PATTERNS.some((pattern) => pattern.test(message))
&& !IN_PERSON_INVITATION_PATTERNS.some((pattern) => pattern.test(message));
}