TTS blocklist: starter list of slurs/TOS phrases, whole-word matching
- src/tts-blocklist.txt: slurs, self-harm/threat phrases, sexual violence, hate slogans (no normal swearing); merged into Settings once (tts_blocklist_seeded), editable there afterwards - Matching is now whole words/phrases with plurals, look-alike swaps and spaced-out letters, so raccoon / spicy / therapist / grape are fine Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
cf90b6be54
commit
9e356b0875
5 changed files with 90 additions and 11 deletions
17
src/db.js
17
src/db.js
|
|
@ -12,6 +12,7 @@ function init() {
|
|||
createSchema();
|
||||
migrate();
|
||||
seedSettings();
|
||||
seedTtsBlocklist();
|
||||
seedVariations();
|
||||
console.log(`[db] Initialised — path: ${DB_PATH}`);
|
||||
}
|
||||
|
|
@ -136,6 +137,20 @@ function migrate() {
|
|||
addColumn('settings', 'tts_max_chars', 'INTEGER DEFAULT 200'); // longer redeem text is cut
|
||||
addColumn('settings', 'tts_blocklist', "TEXT DEFAULT ''"); // words/phrases, one per line or comma-separated
|
||||
addColumn('settings', 'tts_say_name', 'INTEGER DEFAULT 1'); // "<name> says: ..." before the message
|
||||
addColumn('settings', 'tts_blocklist_seeded', 'INTEGER DEFAULT 0'); // starter list copied in once
|
||||
}
|
||||
|
||||
// Put the starter TTS blocklist (src/tts-blocklist.txt) into the settings ONCE; after that it is the user's list
|
||||
// (clearing or editing it in Settings is respected).
|
||||
function seedTtsBlocklist() {
|
||||
const s = db.prepare('SELECT tts_blocklist, tts_blocklist_seeded FROM settings WHERE id = 1').get();
|
||||
if (!s || s.tts_blocklist_seeded) return;
|
||||
const starter = require('fs').readFileSync(require('path').join(__dirname, 'tts-blocklist.txt'), 'utf8')
|
||||
.split('\n').map(l => l.trim()).filter(l => l && !l.startsWith('#'));
|
||||
const mine = String(s.tts_blocklist || '').split(/[\n,]/).map(w => w.trim()).filter(Boolean);
|
||||
const merged = [...mine, ...starter.filter(w => !mine.some(m => m.toLowerCase() === w.toLowerCase()))];
|
||||
db.prepare('UPDATE settings SET tts_blocklist = ?, tts_blocklist_seeded = 1 WHERE id = 1').run(merged.join('\n'));
|
||||
console.log(`[db] TTS blocklist: added ${merged.length - mine.length} starter words`);
|
||||
}
|
||||
|
||||
function seedSettings() {
|
||||
|
|
@ -190,7 +205,7 @@ function getSettings() {
|
|||
|
||||
// what overlay pages get: everything except server-only values (the overlay URL is public)
|
||||
function getOverlaySettings() {
|
||||
const { tts_blocklist, ...rest } = getSettings();
|
||||
const { tts_blocklist, tts_blocklist_seeded, ...rest } = getSettings();
|
||||
return rest;
|
||||
}
|
||||
|
||||
|
|
|
|||
56
src/tts-blocklist.txt
Normal file
56
src/tts-blocklist.txt
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
# Starter TTS blocklist: slurs and phrases that can get a channel in trouble under Twitch's rules when read aloud.
|
||||
# Copied ONCE into Settings -> TTS redeems -> Blocked words (on first start after this was added); edit it there.
|
||||
# Matching (src/tts.js prepareViewerText): whole words, not case-sensitive, plurals (-s/-es/-z) included,
|
||||
# simple swaps (0->o 1->i 3->e 4->a 5->s 7->t @->a $->s) and spaced-out letters (k y s) caught.
|
||||
# Normal swearing is deliberately not here.
|
||||
|
||||
# racial / ethnic slurs
|
||||
nigger
|
||||
nigga
|
||||
sandnigger
|
||||
chink
|
||||
gook
|
||||
spic
|
||||
wetback
|
||||
beaner
|
||||
kike
|
||||
raghead
|
||||
towelhead
|
||||
coon
|
||||
jigaboo
|
||||
porch monkey
|
||||
paki
|
||||
|
||||
# homophobic / transphobic
|
||||
faggot
|
||||
fag
|
||||
dyke
|
||||
tranny
|
||||
shemale
|
||||
|
||||
# ableist
|
||||
retard
|
||||
retarded
|
||||
|
||||
# self-harm / threats
|
||||
kys
|
||||
kill yourself
|
||||
kill urself
|
||||
kill your self
|
||||
neck yourself
|
||||
hang yourself
|
||||
go die
|
||||
|
||||
# sexual violence / minors
|
||||
rape
|
||||
rapist
|
||||
pedo
|
||||
pedophile
|
||||
child porn
|
||||
|
||||
# hate slogans
|
||||
heil hitler
|
||||
sieg heil
|
||||
1488
|
||||
white power
|
||||
gas the jews
|
||||
21
src/tts.js
21
src/tts.js
|
|
@ -87,7 +87,15 @@ function cleanText(text) {
|
|||
// Returns { text, blocked }. blocked = a blocklist word was found: do not read anything.
|
||||
const LEET = { 0: 'o', 1: 'i', 3: 'e', 4: 'a', 5: 's', 7: 't', '@': 'a', $: 's', '!': 'i' };
|
||||
function parseBlocklist(list) {
|
||||
return String(list || '').split(/[\n,]/).map(w => w.trim().toLowerCase()).filter(Boolean);
|
||||
return String(list || '').split(/[\n,]/).map(w => w.trim().toLowerCase()).filter(w => w && !w.startsWith('#'));
|
||||
}
|
||||
// lowercase, look-alike swaps, spaced-out letters joined ("k y s" -> "kys"), only letters/digits, single spaces
|
||||
function normalizeForMatch(text) {
|
||||
return ' ' + String(text).toLowerCase()
|
||||
.replace(/[013457@$!]/g, c => LEET[c] || c)
|
||||
.replace(/(^|[^a-z0-9\u00c0-\u024f])((?:[a-z][\s.\-_*]+){2,}[a-z])(?![a-z])/g, (_, pre, letters) => pre + letters.replace(/[^a-z]/g, ''))
|
||||
.replace(/([a-z])\1{2,}/g, '$1') // niiiice -> nice
|
||||
.replace(/[^a-z0-9\u00c0-\u024f]+/g, ' ').trim() + ' ';
|
||||
}
|
||||
function prepareViewerText(input, { maxChars = 200, blocklist = '' } = {}) {
|
||||
let t = cleanText(input)
|
||||
|
|
@ -98,13 +106,12 @@ function prepareViewerText(input, { maxChars = 200, blocklist = '' } = {}) {
|
|||
.replace(/\s+/g, ' ').trim();
|
||||
const max = Math.max(20, Math.min(MAX_CHARS, maxChars | 0 || 200));
|
||||
if (t.length > max) t = t.slice(0, max).replace(/\s+\S*$/, '') + '…';
|
||||
const plain = t.toLowerCase().replace(/[013457@$!]/g, c => LEET[c] || c);
|
||||
const words = ' ' + plain.replace(/[^a-z0-9\u00c0-\u024f]+/g, ' ') + ' ';
|
||||
const squashed = plain.replace(/[^a-z\u00c0-\u024f]+/g, '');
|
||||
// whole words/phrases only (so "raccoon", "spicy", "therapist" are fine), plurals included
|
||||
const hay = normalizeForMatch(t);
|
||||
const blocked = parseBlocklist(blocklist).some(w => {
|
||||
const ww = w.replace(/[013457@$!]/g, c => LEET[c] || c);
|
||||
return ww.length >= 4 ? squashed.includes(ww.replace(/[^a-z\u00c0-\u024f]+/g, '')) // longer words: also when spaced out
|
||||
: words.includes(' ' + ww.replace(/[^a-z0-9\u00c0-\u024f]+/g, ' ').trim() + ' ');
|
||||
const term = normalizeForMatch(w).trim();
|
||||
if (!term) return false;
|
||||
return new RegExp(` ${term.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?:s|es|z)? `).test(hay);
|
||||
});
|
||||
return { text: t, blocked };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue