Activity replay, HUDFX in the overlay, chat filter, redeem art fix
- Dashboard Recent activity: readable details (reward name, cost, variation,
rarity, TTS, viewer message; sub tier/months; bits; raids; polls), local
times, and a Replay button. Each row now stores the overlay message that was
shown (activity_log.replay_json); older redeem/raid rows are rebuilt from the
raw Twitch event.
- Fix: redeem alerts lost polaroid/art/emote since 4fda606 (they had ended up
inside a comment), so sticker art, Power-up emotes and sound-only were gone.
- HUDFX embedded in the overlay with ?ext=hudfx (opt-in per OBS source): its
page is served from our domain with the camcorder CSS, its settings API is
forwarded, its Web Worker is started from a same-origin stand-in (the alert
box needs it; blob: workers break the site CSP), and the box sits in the
alert corner. The HUDFX URL is a field on the Settings page.
- Blerp cassette CSS kept with it (src/ext/blerp.css, pasted into the Blerp
OBS source; Blerp itself cannot be embedded: its realtime server only
accepts its own site).
- On-screen chat: Settings -> Hidden chatters and Hide ! commands.
- Outgoing raids are logged with a line in the server log.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5f61b1ebe1
commit
19a0965eb2
16 changed files with 671 additions and 35 deletions
124
src/activity.js
Normal file
124
src/activity.js
Normal file
|
|
@ -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 };
|
||||
Loading…
Add table
Add a link
Reference in a new issue