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:
Bashy 2026-11-21 15:09:12 +02:00
parent cf90b6be54
commit 9e356b0875
5 changed files with 90 additions and 11 deletions

View file

@ -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;
}