TTS redeems, skip button, per-source chat placement

- Redeem variations can have a TTS voice: the viewer's text is cleaned
  (links out, repeats collapsed, max length, blocked words -> not read),
  spoken as "<name> says: ..." and shown as the big paper note; the
  variation's sound is not played when TTS is on (picker greyed out)
- Settings: TTS max length, say-the-name, blocked words (never sent to
  overlay pages: db.getOverlaySettings)
- Dashboard "Skip current alert" -> /alerts/skip -> overlay skips it
- db.migrate()/addColumn: new columns on existing databases
- Chat: ?chat=left,top,width,height and ?chatflow=up per browser source
  (e.g. the Intermission panel); default unchanged

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bashy 2026-11-21 14:34:41 +02:00
parent b5a81bdb15
commit 4fda6060bf
16 changed files with 228 additions and 28 deletions

View file

@ -10,6 +10,7 @@ function init() {
db.pragma('journal_mode = WAL');
db.pragma('foreign_keys = ON');
createSchema();
migrate();
seedSettings();
seedVariations();
console.log(`[db] Initialised — path: ${DB_PATH}`);
@ -122,6 +123,21 @@ function createSchema() {
`);
}
// columns added after the first deploy: ALTER only when missing, so existing databases keep their data
function addColumn(table, col, def) {
if (!db.prepare(`PRAGMA table_info(${table})`).all().some(c => c.name === col)) {
db.exec(`ALTER TABLE ${table} ADD COLUMN ${col} ${def}`);
console.log(`[db] Added ${table}.${col}`);
}
}
function migrate() {
addColumn('reward_variations', 'tts_voice_id', 'INTEGER'); // tts_voices.id; NULL = no TTS
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
}
function seedSettings() {
const row = db.prepare('SELECT id FROM settings WHERE id = 1').get();
if (!row) {
@ -172,6 +188,12 @@ function getSettings() {
return db.prepare('SELECT * FROM settings WHERE id = 1').get();
}
// what overlay pages get: everything except server-only values (the overlay URL is public)
function getOverlaySettings() {
const { tts_blocklist, ...rest } = getSettings();
return rest;
}
function updateSettings(fields) {
const cols = Object.keys(fields).map(k => `${k} = @${k}`).join(', ');
db.prepare(`UPDATE settings SET ${cols} WHERE id = 1`).run(fields);
@ -241,7 +263,7 @@ function getMatchingActions(eventType, eventDetail) {
}
// Redeem variations
const VARIATION_FIELDS = ['name', 'rarity', 'sound', 'volume', 'polaroid', 'caption', 'art', 'enabled'];
const VARIATION_FIELDS = ['name', 'rarity', 'sound', 'volume', 'polaroid', 'caption', 'art', 'enabled', 'tts_voice_id'];
function getAllVariations() {
return db.prepare('SELECT * FROM reward_variations ORDER BY kind, title, id').all();
@ -297,7 +319,10 @@ function updateTtsVoice(id, name, config) {
}
function deleteTtsVoice(id) {
db.prepare('DELETE FROM tts_voices WHERE id = ?').run(id);
db.transaction(() => {
db.prepare('UPDATE reward_variations SET tts_voice_id = NULL WHERE tts_voice_id = ?').run(id);
db.prepare('DELETE FROM tts_voices WHERE id = ?').run(id);
})();
}
// Activity log
@ -321,7 +346,7 @@ function getActivityLog(limit = 50) {
module.exports = {
init,
upsertUser, getUserById, getPrimaryUser, updateUserTokens,
getSettings, updateSettings,
getSettings, getOverlaySettings, updateSettings,
getAllMedia, getMediaFile, createMedia, deleteMedia,
getAllActions, getAction, createAction, toggleAction, deleteAction, getMatchingActions,
getAllVariations, getVariationsFor, getVariation, createVariation, updateVariation, renameTrigger, deleteVariation,