diff --git a/src/activity.js b/src/activity.js new file mode 100644 index 0000000..77118ff --- /dev/null +++ b/src/activity.js @@ -0,0 +1,124 @@ +// Dashboard "Recent activity": readable labels for a log row, and Replay (play the row on the overlay again). +// +// Rows logged since replay_json exists carry the exact overlay message that was shown. +// Older rows only have the raw Twitch event (data_json): redeems and outgoing raids are rebuilt from it, +// other old rows cannot be replayed. +const fs = require('fs'); +const path = require('path'); + +const TIERS = { 1000: 'Tier 1', 2000: 'Tier 2', 3000: 'Tier 3' }; +const RARITY = { common: 'Common', uncommon: 'Uncommon', rare: 'Rare', ultra_rare: 'Ultra Rare' }; + +const LABEL = { + follow: 'Follow', sub: 'Sub', gift_sub: 'Gift sub', bits: 'Bits', watch_streak: 'Watch streak', + raid: 'Raid in', raid_out: 'Raid out', hype_train: 'Hype Train', tip: 'Tip', + channel_points: 'Channel points', auto_reward: 'Built-in reward', power_up: 'Power-up', + poll_begin: 'Poll started', poll_end: 'Poll ended', command: 'Command', +}; + +const REDEEM_KIND = { channel_points: 'reward', auto_reward: 'auto_reward', power_up: 'power_up' }; + +function parse(json) { try { return json ? JSON.parse(json) : null; } catch { return null; } } + +// Twitch's own reward name from the raw event (also for rows without a stored alert) +function rewardTitle(type, raw, alert) { + const { AUTO_REWARDS, POWER_UPS } = require('./redeems'); + if (alert?.reward) return alert.reward; + if (type === 'channel_points') return raw?.reward?.title || null; + if (type === 'auto_reward') return AUTO_REWARDS[raw?.reward?.type] || raw?.reward?.type || null; + if (type === 'power_up') return POWER_UPS[raw?.power_up?.type] || raw?.power_up?.type || null; + return null; +} + +// -> { label, title, tags: [string], message } +function describe(log) { + const raw = parse(log.data_json); + const replay = parse(log.replay_json); + const a = replay?.type === 'alert' ? replay.alert : null; + const t = log.event_type; + const out = { label: LABEL[t] || t, title: null, tags: [], message: null }; + + if (REDEEM_KIND[t]) { + out.title = rewardTitle(t, raw, a) || log.event_detail; + if (raw?.reward?.cost) out.tags.push(`${raw.reward.cost} points`); + else if (raw?.reward?.channel_points) out.tags.push(`${raw.reward.channel_points} points`); + else if (raw?.bits) out.tags.push(`${raw.bits} bits`); + if (a) { + if (a.variation && a.variation !== a.reward) out.tags.push(`played: ${a.variation}`); + if (a.rarity && a.rarity !== 'common') out.tags.push(RARITY[a.rarity] || a.rarity); + if (a.tts) out.tags.push('TTS'); + } + out.message = a?.input || raw?.user_input || raw?.message?.text || null; + } else if (a) { + switch (a.type) { + case 'sub': + out.title = a.prime ? 'Prime' : TIERS[a.tier] || a.tier; + if (a.months > 1) out.tags.push(`${a.months} months`); + if (a.duration > 1) out.tags.push(`${a.duration} months at once`); + out.message = a.message || null; break; + case 'gift': + out.title = a.total > 1 ? `${a.total} gift subs` : `gift to ${a.recipient || 'someone'}`; + if (TIERS[a.tier]) out.tags.push(TIERS[a.tier]); + if (!a.user) out.tags.push('anonymous'); break; + case 'bits': out.title = `${a.bits} bits`; out.message = a.message || null; break; + case 'streak': out.title = `${a.streak} streams in a row`; break; + case 'raid': out.title = `${a.viewers} viewers`; break; + case 'hype': + out.title = a.phase === 'begin' ? 'started' : a.phase === 'level' ? `level ${a.level}` : `ended at level ${a.level}`; + if (a.golden) out.tags.push('Golden Kappa'); if (a.treasure) out.tags.push('Treasure'); + if (a.top?.length) out.message = `top: ${a.top.join(', ')}`; break; + case 'tip': out.title = `${a.amount} ${a.currency}`; out.message = a.message || null; break; + } + } else if (t === 'raid_out') { + out.title = `to ${raw?.to_broadcaster_user_name || log.username || '?'}`; + if (raw?.viewers != null) out.tags.push(`${raw.viewers} viewers`); + } else if (t === 'poll_begin' || t === 'poll_end') { + out.title = raw?.title || null; + if (t === 'poll_end' && raw?.choices?.length) { + const sorted = [...raw.choices].sort((x, y) => (y.votes || 0) - (x.votes || 0)); + out.message = sorted.map(c => `${c.title}: ${c.votes ?? 0}`).join(' · '); + } + } else if (log.event_detail) { + out.title = log.event_detail; + } + if (t === 'raid_out' && replay?.raid) { + out.title = `to ${replay.raid.target}`; + out.tags = [`${replay.raid.viewers} viewers`]; + } + return out; +} + +// Can this row be replayed? (cheap check for the table; replay() does the real work) +function canReplay(log) { + if (log.replay_json) return true; + return !!log.data_json && (!!REDEEM_KIND[log.event_type] || log.event_type === 'raid_out'); +} + +const PUBLIC = path.join(__dirname, '..', 'public'); +const fileGone = url => !url || !fs.existsSync(path.join(PUBLIC, url.replace(/^\/+/, '').split('?')[0])); + +// -> the overlay message to broadcast, or null +async function replayMessage(log) { + const stored = parse(log.replay_json); + if (stored) { + if (stored.type === 'alert' && stored.alert.tts && fileGone(stored.alert.tts)) await require('./redeems').respeak(stored.alert); + return stored; + } + const raw = parse(log.data_json); + if (!raw) return null; + if (REDEEM_KIND[log.event_type]) { + const kind = REDEEM_KIND[log.event_type]; + const key = log.event_detail; + const input = raw.user_input || raw.message?.text || null; + const emote = raw.reward?.emote?.id || raw.power_up?.emote?.id || null; + const alert = await require('./redeems').rebuild(kind, key, { user: raw.user_name || raw.user_login || log.username, input, emote }); + return alert ? { type: 'alert', alert } : null; + } + if (log.event_type === 'raid_out') { + const raid = await require('./alerts').raidTarget(raw); + return { type: 'raid_card', phase: 'done', raid: { ...raid, viewers: raw.viewers } }; + } + return null; +} + +module.exports = { describe, canReplay, replayMessage }; diff --git a/src/alerts.js b/src/alerts.js index ad2b726..b24ac56 100644 --- a/src/alerts.js +++ b/src/alerts.js @@ -30,9 +30,10 @@ function legacy(alert) { function send(alert, raw = null) { if (!alert) return; console.log(`[alerts] ${alert.type} — ${alert.user ?? 'anonymous'} ${JSON.stringify({ ...alert, type: undefined, user: undefined })}`); - ws.broadcast({ type: 'alert', alert }); + const msg = { type: 'alert', alert }; + ws.broadcast(msg); const [eventType, detail] = legacy(alert); - dispatch.dispatchEvent(eventType, detail, alert.user, raw || alert); + dispatch.dispatchEvent(eventType, detail, alert.user, raw || alert, msg); } const text = m => (m && typeof m.text === 'string' && m.text.trim()) ? m.text.trim() : null; @@ -121,19 +122,21 @@ function raidStarted(raid) { pendingRaid = { ...raid, started_at: new Date().toI function raidCancelled() { if (pendingRaid) raidCard('cancel', pendingRaid); pendingRaid = null; } function getPendingRaid() { return pendingRaid; } // channel.raid from us: the raid happened (started from the dashboard or straight on Twitch) +async function raidTarget(e) { + let avatar = null; + try { + const res = await require('./twitch').helix(`/users?id=${encodeURIComponent(e.to_broadcaster_user_id)}`); + if (res.ok) avatar = (await res.json()).data?.[0]?.profile_image_url || null; + } catch { /* fallback art */ } + return { target: e.to_broadcaster_user_name || e.to_broadcaster_user_login, avatar }; +} async function raidHappened(e) { - let raid = pendingRaid; - if (!raid) { // started on Twitch directly: show the card briefly - let avatar = null; - try { - const res = await require('./twitch').helix(`/users?id=${encodeURIComponent(e.to_broadcaster_user_id)}`); - if (res.ok) avatar = (await res.json()).data?.[0]?.profile_image_url || null; - } catch { /* fallback art */ } - raid = { target: e.to_broadcaster_user_name || e.to_broadcaster_user_login, avatar }; - } - raidCard('done', { ...raid, viewers: e.viewers }); + const raid = pendingRaid || await raidTarget(e); // started on Twitch directly: show the card briefly + const msg = { type: 'raid_card', phase: 'done', raid: { ...raid, viewers: e.viewers } }; + ws.broadcast(msg); pendingRaid = null; - dispatch.dispatchEvent('raid_out', String(e.viewers), e.to_broadcaster_user_name, e); + console.log(`[alerts] raid out — ${msg.raid.target} with ${e.viewers}`); + dispatch.dispatchEvent('raid_out', String(e.viewers), e.to_broadcaster_user_name, e, msg); } // --- polls: a live card on the overlay, outside the alert queue --- @@ -252,4 +255,4 @@ function sendTest(key) { return true; } -module.exports = { send, sendTest, sendTestAlert, sendPoll, sendHypeBar, raidStarted, raidCancelled, raidHappened, getPendingRaid, fromHypeTrain, fromTip, SAMPLES, TEST_KEYS, fromFollow, fromCheer, fromBitsUse, fromChatNotification, fromOverlayNotice }; +module.exports = { raidTarget, send, sendTest, sendTestAlert, sendPoll, sendHypeBar, raidStarted, raidCancelled, raidHappened, getPendingRaid, fromHypeTrain, fromTip, SAMPLES, TEST_KEYS, fromFollow, fromCheer, fromBitsUse, fromChatNotification, fromOverlayNotice }; diff --git a/src/app.js b/src/app.js index 86564c2..72d74ac 100644 --- a/src/app.js +++ b/src/app.js @@ -49,6 +49,7 @@ function requireAuth(req, res, next) { app.use('/auth', require('./routers/auth')); app.use('/overlay', require('./routers/overlay')); +app.use('/ext', require('./routers/ext').router); // HUDFX / Blerp pages served inside the overlay (public, under the overlay id) // Now playing (Feishin) is switched off for now; uncomment to bring it back (see views/overlay.ejs). // app.use('/nowplaying', require('./routers/nowplaying')); // key-protected push from the PC helper app.use('/actions', requireAuth, require('./routers/actions')); diff --git a/src/db.js b/src/db.js index 9db1ad6..7696e72 100644 --- a/src/db.js +++ b/src/db.js @@ -138,6 +138,10 @@ function migrate() { addColumn('settings', 'tts_blocklist', "TEXT DEFAULT ''"); // words/phrases, one per line or comma-separated addColumn('settings', 'tts_say_name', 'INTEGER DEFAULT 1'); // " says: ..." before the message addColumn('settings', 'tts_blocklist_seeded', 'INTEGER DEFAULT 0'); // starter list copied in once + addColumn('activity_log', 'replay_json', 'TEXT'); + addColumn('settings', 'hudfx_overlay_url', "TEXT DEFAULT ''"); + addColumn('settings', 'chat_hidden_users', "TEXT DEFAULT 'bot_account, blerp, blerpbot, hudfx, hudfxbot, lumiastream'"); // never shown in the on-screen chat + addColumn('settings', 'chat_hide_commands', 'INTEGER DEFAULT 1'); // hide messages starting with ! // HUDFX browser source URL, embedded with ?ext=hudfx // the overlay message that was shown (dashboard Replay) } // Put the starter TTS blocklist (src/tts-blocklist.txt) into the settings ONCE; after that it is the user's list @@ -205,7 +209,7 @@ function getSettings() { // what overlay pages get: everything except server-only values (the overlay URL is public) function getOverlaySettings() { - const { tts_blocklist, tts_blocklist_seeded, ...rest } = getSettings(); + const { tts_blocklist, tts_blocklist_seeded, hudfx_overlay_url, ...rest } = getSettings(); return rest; } @@ -341,11 +345,12 @@ function deleteTtsVoice(id) { } // Activity log -function logActivity(eventType, eventDetail, username, data, actionsFired) { +function logActivity(eventType, eventDetail, username, data, actionsFired, replay = null) { db.prepare(` - INSERT INTO activity_log (event_type, event_detail, username, data_json, actions_fired) - VALUES (@event_type, @event_detail, @username, @data_json, @actions_fired) + INSERT INTO activity_log (event_type, event_detail, username, data_json, actions_fired, replay_json) + VALUES (@event_type, @event_detail, @username, @data_json, @actions_fired, @replay_json) `).run({ + replay_json: replay ? JSON.stringify(replay) : null, event_type: eventType, event_detail: eventDetail || null, username: username || null, @@ -355,7 +360,11 @@ function logActivity(eventType, eventDetail, username, data, actionsFired) { } function getActivityLog(limit = 50) { - return db.prepare('SELECT * FROM activity_log ORDER BY created_at DESC LIMIT ?').all(limit); + return db.prepare('SELECT * FROM activity_log ORDER BY created_at DESC, id DESC LIMIT ?').all(limit); +} + +function getActivity(id) { + return db.prepare('SELECT * FROM activity_log WHERE id = ?').get(id); } module.exports = { @@ -366,5 +375,5 @@ module.exports = { getAllActions, getAction, createAction, toggleAction, deleteAction, getMatchingActions, getAllVariations, getVariationsFor, getVariation, createVariation, updateVariation, renameTrigger, deleteVariation, getAllTtsVoices, getTtsVoice, createTtsVoice, updateTtsVoice, deleteTtsVoice, - logActivity, getActivityLog, + logActivity, getActivityLog, getActivity, }; diff --git a/src/dispatch.js b/src/dispatch.js index 3d3003a..41fa79e 100644 --- a/src/dispatch.js +++ b/src/dispatch.js @@ -2,7 +2,8 @@ const db = require('./db'); const ws = require('./ws'); const { isOnCooldown, setCooldown } = require('./cooldowns'); -function dispatchEvent(eventType, eventDetail = null, username = null, data = null) { +// replay: the overlay message that was shown for this event, stored so the dashboard can play it again +function dispatchEvent(eventType, eventDetail = null, username = null, data = null, replay = null) { const actions = db.getMatchingActions(eventType, eventDetail); let fired = 0; @@ -31,7 +32,7 @@ function dispatchEvent(eventType, eventDetail = null, username = null, data = nu console.log(`[dispatch] Fired action ${action.id} (${action.name}) — event: ${eventType}, user: ${username}`); } - db.logActivity(eventType, eventDetail, username, data, fired); + db.logActivity(eventType, eventDetail, username, data, fired, replay); } module.exports = { dispatchEvent }; diff --git a/src/ext/blerp.css b/src/ext/blerp.css new file mode 100644 index 0000000..ea22dca --- /dev/null +++ b/src/ext/blerp.css @@ -0,0 +1,157 @@ +/* Blerp: OBS browser source → Properties → Custom CSS (source 1920x1080, covering the whole canvas in OBS). + Looks like HeyStreamer's redeem tapes: pastel shell with screws, lined label with a SIDE A band, handwritten + title, reel window, a paper strip underneath (" shared!") and the Blerp logo as the sticker. + The sound's own picture sits in the reel window. Built only from Blerp's own elements; its swing-in stays. */ +@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@600;700&family=Nunito:wght@800;900&display=swap'); + +body { background-color: rgba(0, 0, 0, 0); margin: 0 auto; overflow: hidden; } + +/* --- position: top-left corner 85,110, 440px wide (same spot and size as the other alerts) --- */ +#blerp-alert-wrapper { justify-content: flex-start !important; align-items: flex-start !important; } +#blerp-generic-template { + width: auto !important; min-height: 0 !important; overflow: visible !important; + margin: 110px 0 0 85px !important; transform-origin: left top !important; +} + +/* --- the shell (drawn at 540x346, zoomed to 440 wide) --- */ +.blerpOuterBackground { + --shell: #ffd3dc; --shell2: #ffc1cd; --edge: #c8284f; --band: #fe295c; --bandtxt: #ffffff; + --ink: #3a2a20; --red: #b74347; --window: #3b2f45; + zoom: 0.815; + position: relative !important; width: 540px !important; height: 346px !important; + border: 3px solid var(--edge) !important; border-radius: 24px !important; overflow: visible !important; + box-shadow: 0 14px 22px rgba(0, 0, 0, .45) !important; + background: + /* screws */ + radial-gradient(circle at 20px 20px, #fff 0 3px, var(--edge) 3px 5px, #0000 6px), + radial-gradient(circle at 514px 20px, #fff 0 3px, var(--edge) 3px 5px, #0000 6px), + radial-gradient(circle at 20px 318px, #fff 0 3px, var(--edge) 3px 5px, #0000 6px), + radial-gradient(circle at 514px 318px, #fff 0 3px, var(--edge) 3px 5px, #0000 6px), + /* lined label */ + repeating-linear-gradient(#0000 0 25px, rgba(110, 130, 170, .22) 25px 26px) 42px 70px / 454px 160px no-repeat, + linear-gradient(#fffdf6, #fffdf6) 42px 30px / 454px 200px no-repeat, + linear-gradient(var(--shell), var(--shell2)) !important; +} +/* bottom part with the drive holes */ +.blerpOuterBackground::before { + content: ""; position: absolute; left: 118px; right: 118px; bottom: -3px; height: 86px; + clip-path: polygon(9% 0, 91% 0, 100% 100%, 0 100%); + background: + radial-gradient(circle at 22% 55%, var(--window) 0 8px, #0000 9px), + radial-gradient(circle at 34% 55%, var(--window) 0 8px, #0000 9px), + linear-gradient(var(--window), var(--window)) 50% 52% / 28px 24px no-repeat, + radial-gradient(circle at 66% 55%, var(--window) 0 8px, #0000 9px), + radial-gradient(circle at 78% 55%, var(--window) 0 8px, #0000 9px), + #ffadbf; +} +/* Blerp logo sticker, top-right corner, white outline like the redeem stickers */ +.blerpOuterBackground::after { + content: ""; position: absolute; right: -44px; top: -40px; width: 112px; height: 104px; z-index: 3; + background: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2244.716%22%20height%3D%2241.642%22%20viewBox%3D%220%200%2044.716%2041.642%22%3E%20%20%20%3Cg%20id%3D%22BlerpIconRed%22%20transform%3D%22translate%28-145.998%20-27%29%22%3E%20%20%20%20%20%3Cpath%20id%3D%22Path_1731%22%20data-name%3D%22Path%201731%22%20d%3D%22M37.36%2C17.914c-.91-4.766%2C3.258-8.281.4-11.831-3.881-4.815-8.637%2C1.76-12.993-.133C21.935%2C4.718%2C19.1.565%2C14.924%2C2.083s-3.683%2C6.526-5.038%2C9.285C7.751%2C15.62-.12%2C13.642%2C0%2C19.827c.094%2C4.558%2C5.542%2C4.573%2C7.91%2C8.805S4.814%2C38%2C9.728%2C42.05c5.953%2C4.914%2C11.974-5.072%2C17.2-6.986h0c5.211-1.9%2C16.266%2C1.913%2C17.67-5.705C45.745%2C23.1%2C38.25%2C22.606%2C37.36%2C17.914ZM24.021%2C27.09a9.068%2C9.068%2C0%2C0%2C1-10.308-3.461%2C1.483%2C1.483%2C0%2C0%2C1%2C1.043-2.358%2C29.169%2C29.169%2C0%2C0%2C0%2C6.556-1.587%2C29.342%2C29.342%2C0%2C0%2C0%2C6.046-3%2C1.483%2C1.483%2C0%2C0%2C1%2C2.3%2C1.1A9.062%2C9.062%2C0%2C0%2C1%2C24.021%2C27.09Z%22%20transform%3D%22translate%28146.001%2025.246%29%22%20fill%3D%22%23fe295c%22%2F%3E%20%20%20%3C%2Fg%3E%20%3C%2Fsvg%3E%20") center / contain no-repeat; + transform: rotate(10deg); + filter: drop-shadow(4px 0 0 #fff) drop-shadow(-4px 0 0 #fff) drop-shadow(0 4px 0 #fff) drop-shadow(0 -4px 0 #fff) drop-shadow(0 6px 9px rgba(0,0,0,.35)); +} + +/* --- the label (holds everything else) --- */ +.alertNewPill { + position: absolute !important; left: 42px; top: 30px; width: 454px !important; height: 200px !important; + box-sizing: border-box !important; padding: 0 !important; display: block !important; + background: transparent !important; overflow: visible !important; +} +/* SIDE A band */ +.alertNewPill::before, .alertNewPill::after { + position: absolute; top: 0; height: 40px; font: 900 19px/40px 'Nunito', sans-serif; letter-spacing: 2.5px; color: var(--bandtxt); +} +.alertNewPill::before { content: "SIDE A"; left: 0; right: 0; padding-left: 20px; background: var(--band); border-radius: 6px 6px 0 0; } +.alertNewPill::after { content: "★ BLERP"; right: 70px; } + +.innerBackgroundText { position: absolute !important; inset: 0; display: block !important; overflow: visible !important; padding: 0 !important; } +/* reel window with two white reels */ +.innerBackgroundText::before { + content: ""; position: absolute; left: 82px; top: 92px; width: 290px; height: 82px; border-radius: 41px; + border: 3px solid var(--edge); box-sizing: border-box; + background: + radial-gradient(circle at 62px 38px, var(--window) 0 6px, #fff 7px 13px, #d9d2ca 13px 16px, #fff 16px 25px, #cfc6bd 25px 27px, #5a4036 28px 33px, #0000 34px), + radial-gradient(circle at 222px 38px, var(--window) 0 6px, #fff 7px 13px, #d9d2ca 13px 16px, #fff 16px 25px, #cfc6bd 25px 27px, #5a4036 28px 33px, #0000 34px), + var(--window); +} +/* small caption under the window */ +.innerBackgroundText::after { + content: "Blerp sound"; position: absolute; left: 0; right: 0; top: 176px; text-align: center; + font: 700 27px/1 'Caveat', cursive; color: #7a6656; +} + +/* the sound's picture: a sticker in the bottom-right corner (where the redeem tapes have theirs): + thick white border, softly rounded, one corner curling up */ +#innerBackgroundImage { + position: absolute !important; left: 392px; top: 188px; z-index: 5; + width: 150px !important; height: 150px !important; margin: 0 !important; padding: 8px !important; + border: none !important; border-radius: 16px 16px 26px 16px !important; background: #fff !important; box-sizing: border-box !important; + box-shadow: 0 7px 12px rgba(0, 0, 0, .35), 0 1px 2px rgba(0, 0, 0, .25) !important; + overflow: hidden !important; +} +#innerBackgroundImageReal { width: 134px !important; height: 134px !important; border-radius: 10px 10px 18px 10px !important; object-fit: cover; } +/* curled corner, bottom right */ +#innerBackgroundImage::after { + content: ""; position: absolute; right: 0; bottom: 0; width: 34px; height: 34px; + background: linear-gradient(135deg, rgba(0, 0, 0, .18) 0%, #f4f0ea 46%, #fff 50%, #0000 51%); + border-top-left-radius: 10px; box-shadow: -2px -2px 4px rgba(0, 0, 0, .12); +} + +/* title: the sound name, handwritten on the label */ +#secondary-alert-text { + position: absolute !important; left: 24px; right: 24px; top: 42px; width: auto !important; height: auto !important; + text-align: center !important; font-family: 'Caveat', cursive !important; font-weight: 700 !important; + font-size: 48px !important; line-height: 1 !important; color: var(--ink) !important; + white-space: nowrap !important; overflow: hidden; text-overflow: ellipsis; +} + +/* " shared!" on a taped paper strip under the tape */ +#main-alert-text { + position: absolute !important; left: -6px; top: 318px; width: auto !important; height: auto !important; max-width: 470px; + padding: 10px 28px 12px !important; background: #fffdf7; transform: rotate(-2deg); + box-shadow: 0 6px 14px rgba(0, 0, 0, .35); z-index: 4; + font-family: 'Caveat', cursive !important; font-weight: 700 !important; font-size: 38px !important; line-height: 1.05 !important; + color: var(--red) !important; white-space: nowrap !important; overflow: visible !important; margin: 0 !important; min-width: 0 !important; +} +#main-alert-text::before, #main-alert-text::after { + content: ""; position: absolute; top: -12px; width: 86px; height: 28px; + background: rgba(201, 182, 228, .85); background-image: repeating-linear-gradient(45deg, #fff6 0 8px, #0000 8px 16px); +} +#main-alert-text::before { left: -26px; transform: rotate(-28deg); } +#main-alert-text::after { right: -26px; transform: rotate(24deg); } + +/* --- motion: same as HeyStreamer's tapes (public/alerts/cassette.js) --- */ +/* Blerp's own entrance ("swing") off; its exit animation stays */ +@keyframes swing { from { transform: none; } to { transform: none; } } +/* Blerp fades the text in after a delay: show it with the tape */ +.innerBackgroundText { opacity: 1 !important; transition: none !important; } + +/* tape slides in from the left with a little overshoot, settles tilted; then bobs while the sound plays */ +.blerpOuterBackground { animation: hs-tape-in 700ms cubic-bezier(.2, .8, .3, 1) both, hs-bob 420ms ease-in-out 700ms 12; } +@keyframes hs-tape-in { + 0% { transform: translateX(-620px) rotate(-14deg); opacity: 0; } + 72% { transform: translateX(18px) rotate(0deg); opacity: 1; } + 88% { transform: translateX(-4px) rotate(-2.6deg); } + 100% { transform: translateX(0) rotate(-2deg); opacity: 1; } +} +@keyframes hs-bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -2px; } } +/* stickers pop in: the picture like the redeem sticker, the logo just after */ +#innerBackgroundImage { animation: hs-img-in 380ms ease-out 650ms both; } +@keyframes hs-img-in { + 0% { transform: rotate(-22deg) scale(0); opacity: 0; } + 60% { transform: rotate(14deg) scale(1.2); opacity: 1; } + 100% { transform: rotate(7deg) scale(1); opacity: 1; } +} +.blerpOuterBackground::after { animation: hs-stk-in 380ms ease-out 780ms both; } +@keyframes hs-stk-in { + 0% { transform: rotate(-30deg) scale(0); opacity: 0; } + 60% { transform: rotate(18deg) scale(1.2); opacity: 1; } + 100% { transform: rotate(10deg) scale(1); opacity: 1; } +} +/* paper strip drops in */ +#main-alert-text { animation: hs-strip-in 320ms cubic-bezier(.3, .7, .4, 1) 850ms both; } +@keyframes hs-strip-in { + 0% { transform: translateY(-20px) rotate(-6deg) scale(1.1); opacity: 0; } + 100% { transform: translateY(0) rotate(-2deg) scale(1); opacity: 1; } +} diff --git a/src/ext/hudfx.css b/src/ext/hudfx.css new file mode 100644 index 0000000..f7a70b9 --- /dev/null +++ b/src/ext/hudfx.css @@ -0,0 +1,68 @@ +/* HUDFX: OBS browser source → Properties → Custom CSS (source 2560x1440). + The notification as a camcorder viewfinder in HUDFX colours: scanlines, corner brackets, ● REC, timecode, VCR text. + Built only from HUDFX's own elements (.alert-inner-container …); full-screen effect videos are untouched. */ +@import url('https://fonts.googleapis.com/css2?family=VT323&display=swap'); + +body { background-color: rgba(0, 0, 0, 0); margin: 0 auto; overflow: hidden; } + +div.alert-contain > div.alert-inner-container.branded { + --purple: #734ffe; --lilac: #b9a6ff; --navy: #1c1f2f; + width: 440px !important; height: auto !important; min-height: 250px !important; + padding: 58px 26px 30px !important; + border: 6px solid var(--purple) !important; border-radius: 14px !important; + box-shadow: 0 0 0 3px #0e0f18, 0 0 26px rgba(115, 79, 254, .6), 0 14px 26px rgba(0, 0, 0, .5) !important; + background: + /* corner brackets */ + linear-gradient(#fff, #fff) 14px 14px / 30px 4px no-repeat, linear-gradient(#fff, #fff) 14px 14px / 4px 30px no-repeat, + linear-gradient(#fff, #fff) right 14px top 14px / 30px 4px no-repeat, linear-gradient(#fff, #fff) right 14px top 14px / 4px 30px no-repeat, + linear-gradient(#fff, #fff) left 14px bottom 14px / 30px 4px no-repeat, linear-gradient(#fff, #fff) left 14px bottom 14px / 4px 30px no-repeat, + linear-gradient(#fff, #fff) right 14px bottom 14px / 30px 4px no-repeat, linear-gradient(#fff, #fff) right 14px bottom 14px / 4px 30px no-repeat, + /* scanlines + a soft purple glow on the screen */ + repeating-linear-gradient(0deg, rgba(255, 255, 255, .045) 0 2px, transparent 2px 4px), + radial-gradient(ellipse at 50% 45%, #2b2550 0%, #1c1f2f 70%) #1c1f2f !important; + background-color: #1c1f2f !important; /* solid screen, never see-through */ + animation: hfx-jitter 3.2s steps(1) infinite; +} +/* ● REC (blinking) and timecode */ +div.alert-contain > div.alert-inner-container.branded::before { + content: "● REC"; position: absolute; left: 28px; top: 20px; + font: 30px/1 'VT323', monospace; color: #ff3b4e; letter-spacing: 1px; text-shadow: 0 0 6px rgba(255, 59, 78, .7); + animation: hfx-blink 1s steps(1) infinite; +} +div.alert-contain > div.alert-inner-container.branded::after { + content: "▶ 0:00:13"; position: absolute; right: 28px; top: 20px; + font: 26px/1 'VT323', monospace; color: #fff; opacity: .85; +} + +.alert-media-contain { display: none !important; } /* little avatar badge on the top edge */ + +/* "Triggered " + viewer name: VCR text with a slight colour split */ +.alert-text-contain pre { + font-family: 'VT323', monospace !important; font-weight: 400 !important; + font-size: 40px !important; line-height: 1 !important; text-transform: uppercase; + color: #fff !important; white-space: pre-wrap !important; text-align: center !important; margin: 0 !important; + text-shadow: 2px 0 rgba(255, 59, 120, .75), -2px 0 rgba(80, 220, 255, .75) !important; +} +.alert-text-contain .animate__pulse pre { color: var(--lilac) !important; font-size: 36px !important; margin-top: 10px !important; } + +/* "50 bits" as the tape label strip */ +.alert-amount-contain { + background: var(--purple) !important; border-radius: 4px !important; height: auto !important; + padding: 4px 18px !important; margin-top: 18px !important; box-shadow: 0 0 12px rgba(115, 79, 254, .7) !important; +} +.alert-amount-contain pre { font-family: 'VT323', monospace !important; font-size: 30px !important; color: #fff !important; text-transform: uppercase; } + +.branded-logo-contain { opacity: .6; transform: translate(-30px, -12px); } + +@keyframes hfx-blink { 0% { opacity: 1; } 50% { opacity: 0; } } +@keyframes hfx-jitter { 0%, 100% { transform: none; } 92% { transform: translateX(2px) skewX(-1deg); } 94% { transform: translateX(-2px); } 96% { transform: none; } } + +/* Put the box where HeyStreamer's own alerts appear (top left: 85,110 on the 1920x1080 overlay, 440px wide). + This page is 2560x1440 shown at 75%, so: scale 1.45 makes the box ~440px wide on the overlay, and the layer + position puts its top-left corner at 85,110. #BCOvP… is the alert layer's id in this HUDFX overlay's settings; + :has() catches it if that id ever changes. */ +#BCOvPCnfVtwksnH8vmgmm, +.overlay-layer:has(.alert-contain) { + left: 44px !important; top: 46px !important; + transform: scale(1.45) !important; transform-origin: 0 0 !important; +} diff --git a/src/redeems.js b/src/redeems.js index e2dffa1..b9cd609 100644 --- a/src/redeems.js +++ b/src/redeems.js @@ -54,11 +54,12 @@ function toAlert(v, { user, input, emote }) { const style = spoken ? 'tts' : (STYLE[`${v.kind}:${v.key}`] || 'cassette'); const line = spoken ? LINE.tts : LINE[style]; return { - type: 'redeem', kind: v.kind, key: v.key, style, + type: 'redeem', kind: v.kind, key: v.key, style, vid: v.id, // vid: re-speak on replay if the mp3 was pruned user, reward: v.title, variation: v.name, rarity: v.rarity, input: input || null, // special styles have their own wording unless the caption was customised caption: style !== 'cassette' && v.caption === 'redeemed it! ♡' ? line : v.caption, - sound: spoken ? null : (v.sound || null), volume: v.volume, // TTS on: the voice replaces the sound polaroid: !!v.polaroid, art: v.art || null, emote: emoteUrl(emote), + sound: spoken ? null : (v.sound || null), volume: v.volume, // TTS on: the voice replaces the sound + polaroid: !!v.polaroid, art: v.art || null, emote: emoteUrl(emote), }; } @@ -106,6 +107,24 @@ function handle(kind, key, title, { user, input, emote }, raw) { return alert; } +// Dashboard Replay of an old activity row that has no stored alert: a fresh pick for the trigger, +// with the viewer's original name and text. Resolves to the alert, or null if nothing is configured. +async function rebuild(kind, key, { user, input, emote }) { + const v = pick(db.getVariationsFor(kind, key)); + if (!v) return null; + const alert = toAlert(v, { user, input, emote }); + if (v.tts_voice_id && input) await addSpeech(v, alert); + return alert; +} + +// Replay of a stored TTS alert whose mp3 was pruned: speak it again with the same variation's voice. +async function respeak(alert) { + const v = alert.vid && db.getVariation(alert.vid); + for (const k of ['tts', 'tts_ms', 'tts_env', 'tts_prefix']) delete alert[k]; + if (v && v.tts_voice_id && alert.input) await addSpeech(v, alert); + return alert; +} + // Dashboard test: one specific variation, or a random pick for the whole trigger. function test({ id, kind, key }) { const v = id ? db.getVariation(id) : pick(db.getVariationsFor(kind, key)); @@ -119,4 +138,4 @@ function test({ id, kind, key }) { return true; } -module.exports = { RARITY, AUTO_REWARDS, POWER_UPS, STYLE, pick, handle, test }; +module.exports = { RARITY, AUTO_REWARDS, POWER_UPS, STYLE, pick, handle, test, rebuild, respeak }; diff --git a/src/routers/dashboard.js b/src/routers/dashboard.js index 7e8304e..a91b33c 100644 --- a/src/routers/dashboard.js +++ b/src/routers/dashboard.js @@ -4,16 +4,33 @@ const db = require('../db'); const eventsub = require('../eventsub'); const alerts = require('../alerts'); const streamelements = require('../streamelements'); +const activity = require('../activity'); +const ws = require('../ws'); router.get('/', (req, res) => { const logs = db.getActivityLog(50); const settings = db.getSettings(); - res.render('dashboard', { logs, settings, eventsubStatus: eventsub.getStatus(), seStatus: streamelements.getStatus(), testKeys: alerts.TEST_KEYS }); + res.render('dashboard', { logs, activity, settings, eventsubStatus: eventsub.getStatus(), seStatus: streamelements.getStatus(), testKeys: alerts.TEST_KEYS }); }); // Activity table only (dashboard Reload button / auto-refresh) router.get('/activity', (req, res) => { - res.render('_activity', { layout: false, logs: db.getActivityLog(50) }); + res.render('_activity', { layout: false, logs: db.getActivityLog(50), activity }); +}); + +// Replay: play a logged event on the overlay again (queued like a real alert; not logged again, no actions fired) +router.post('/activity/:id/replay', async (req, res) => { + const log = db.getActivity(parseInt(req.params.id, 10)); + if (!log) return res.status(404).json({ ok: false, error: 'not found' }); + try { + const msg = await activity.replayMessage(log); + if (!msg) return res.json({ ok: false, error: 'nothing to replay for this event' }); + ws.broadcast(msg); + res.json({ ok: true }); + } catch (e) { + console.error('[activity] replay:', e.message); + res.status(500).json({ ok: false, error: e.message }); + } }); module.exports = router; diff --git a/src/routers/ext.js b/src/routers/ext.js new file mode 100644 index 0000000..dd585df --- /dev/null +++ b/src/routers/ext.js @@ -0,0 +1,146 @@ +// HUDFX and Blerp inside our overlay (one OBS source, one audio fader, our CSS). +// +// Their overlay pages are fetched here and served from our domain with a few things injected: +// their own files and APIs still load from their sites +// page address their apps read the overlay id from location.pathname, so it is set back to theirs +// API redirect HUDFX's settings API refuses other sites (CORS), so those calls go through /hudfx-api here +// volume every