send2streamer/profanity.js

35 lines
1.2 KiB
JavaScript
Raw Normal View History

// Word-level profanity filter: matches whole words against a root list
// (so a root like "еб" only censors words that start with it, not every
// word containing that substring, e.g. "тебя", "победа").
// Deliberately simple (no leetspeak/homoglyph handling) — extend PROFANE_ROOTS
// below if you need broader coverage.
const PROFANE_ROOTS = [
// Russian
'хуй', 'хуе', 'хуё', 'хуя', 'хует',
'пизд',
'бля',
'еб', 'ёб',
'муда', 'мудак', 'мудило',
'пидор', 'пидар', 'пидр',
'гондон', 'гандон',
'долбоеб', 'долбоёб',
'сука', 'суки', 'суке', 'суку', 'суками',
// English
'fuck', 'shit', 'bitch', 'cunt', 'dick', 'asshole', 'bastard',
'whore', 'slut', 'nigger', 'nigga', 'faggot', 'motherfuck',
];
const WORD_RE = /[а-яёА-ЯЁa-zA-Z]+/g;
function isProfaneWord(word) {
const normalized = word.toLowerCase();
return PROFANE_ROOTS.some((root) => normalized.startsWith(root));
}
function censorText(text, replacement) {
return text.replace(WORD_RE, (word) => (isProfaneWord(word) ? replacement : word));
}
module.exports = { censorText };