Stats per stream and period, public stats page, dashboard settings, Card alert style
Statistics - Per day and per stream statistics (src/periodstats.js, one generic stat_day table), backfilled once from the older tables; Stream / Week / Month / Year / All time views, Community and Streams tabs. - Viewer count every 5 minutes and title / category history per stream (EventSub channel.update): viewer graph, games played (donut), games in the streams list. - Twitch sync (src/twitchsync.js): followers with follow dates, current subs, mods, VIPs, all-time bits, channel emotes, past streams from VODs. Twitch analytics CSV import (src/twitchcsv.js). - Public stats page on its own host (Settings -> Stats and data): no message text, no bots, !hideme / !showme opt-out. Viewer page: roles, follow age, sub status, bits, a menu for rarely used actions. - StreamElements watch-time importer removed (already imported minutes stay as a baseline). Dashboard - Settings and Actions with a left sidebar; each settings page saves only its own fields. Connections (Twitch, StreamElements token now set here, HUDFX), OBS links (hidden behind an eye toggle) with a link builder, Chat (sound picked from the media library), TTS, Stats and data, Backup (export / import the whole setup), Advanced. Time zone setting for the stats pages. - Actions -> Alerts: alert style, pictures, sounds, bits tiers and card colours, stored in the database (src/theme.js); an old file-based theme is imported once. Alert preview page (/actions/alerts/preview, tools/preview/export.js for a static copy). - Old /actions page removed; Actions = Redeems / Alerts / TTS voices / Media. Alerts - New plain Card style for everyone (public/alerts/card.js); Polaroid, Cassette and the TTS letter stay as optional looks. Redeem variations can be Card, Cassette, Sound only or Video. Repo - No channel data in git: the channel's art, stickers and sounds stay on disk (gitignored) and are picked in the dashboard; examples for the server config (apache.example.sh, .env.example). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5bf4bffaa0
commit
c481ca92cb
57 changed files with 3080 additions and 774 deletions
233
views/alerts_setup.ejs
Normal file
233
views/alerts_setup.ejs
Normal file
|
|
@ -0,0 +1,233 @@
|
|||
<% const J = x => JSON.stringify(x).replace(/</g, '\\u003c'); %>
|
||||
<style>
|
||||
.al-grid { display:grid; grid-template-columns:minmax(150px, 200px) minmax(0, 1fr) minmax(0, 1fr) auto; gap:.5rem 1rem; align-items:center; }
|
||||
.al-grid .hd { font-size:.75rem; color:var(--pico-muted-color); text-transform:uppercase; letter-spacing:.06em; }
|
||||
.al-grid select { margin:0; font-size:.88rem; padding:.3rem .5rem; height:auto; }
|
||||
.al-name { font-weight:600; font-size:.92rem; }
|
||||
.al-name small { display:block; font-weight:400; color:var(--pico-muted-color); font-size:.78rem; }
|
||||
.pk { display:flex; align-items:center; gap:.4rem; }
|
||||
.pk img { width:34px; height:34px; object-fit:contain; border-radius:6px; background:rgba(255,255,255,.06); flex:none; }
|
||||
.pk img[src=""] { visibility:hidden; }
|
||||
.pk button, .btn-xs { width:auto; margin:0; padding:.2rem .55rem; font-size:.78rem; }
|
||||
@media (max-width: 900px) { .al-grid { grid-template-columns:1fr 1fr; } .al-grid .hd { display:none; } }
|
||||
.set-row > .seg { justify-self:start; }
|
||||
.set-row.stack { grid-template-columns:1fr; }
|
||||
.tiers .pk select { min-width:200px; }
|
||||
.seg { display:inline-flex; border:1px solid var(--pico-muted-border-color); border-radius:8px; overflow:hidden; }
|
||||
.seg label { margin:0; padding:.35rem .9rem; cursor:pointer; font-size:.88rem; border-left:1px solid var(--pico-muted-border-color); }
|
||||
.seg label:first-child { border-left:0; }
|
||||
.seg input { display:none; }
|
||||
.seg label:has(input:checked) { background:var(--pico-primary-background); color:#fff; }
|
||||
.tiers { width:100%; font-size:.86rem; }
|
||||
.tiers td, .tiers th { padding:.3rem .4rem; vertical-align:middle; }
|
||||
.tiers input, .tiers select { margin:0; padding:.25rem .4rem; font-size:.85rem; height:auto; }
|
||||
.savebar-al { position:sticky; bottom:0; display:flex; gap:.8rem; align-items:center; padding:.7rem 0; background:var(--pico-background-color);
|
||||
border-top:1px solid var(--pico-muted-border-color); z-index:5; }
|
||||
.savebar-al button { width:auto; margin:0; }
|
||||
.dirty { color:#e6b800; font-weight:600; }
|
||||
.backs { display:flex; flex-wrap:wrap; gap:.4rem; align-items:center; }
|
||||
.backs .b { display:flex; align-items:center; gap:.2rem; border:1px solid var(--pico-muted-border-color); border-radius:8px; padding:.15rem .3rem; }
|
||||
.backs .b img { width:30px; height:30px; object-fit:contain; }
|
||||
.colors { display:flex; gap:1rem; flex-wrap:wrap; align-items:center; }
|
||||
.colors label { display:flex; gap:.4rem; align-items:center; margin:0; font-size:.88rem; }
|
||||
.colors input[type=color] { width:2.6rem; height:2rem; padding:0; margin:0; }
|
||||
.hint { color:var(--pico-muted-color); font-size:.8rem; }
|
||||
</style>
|
||||
|
||||
<h2 class="set-h">Alerts</h2>
|
||||
<p class="set-intro"><a href="/actions/alerts/preview" target="_blank" rel="noopener" style="float:right; margin-left:1rem;">Open the preview ↗</a>What follows, subs, gifts, raids, bits, tips and the Hype Train look and sound like. Pictures and sounds come from
|
||||
<a href="/media">Media</a> (upload your own there). Changes reach OBS as soon as you save; use Test to see them.</p>
|
||||
|
||||
<div class="set-card">
|
||||
<h3>Style</h3>
|
||||
<div class="set-row">
|
||||
<div class="lbl">Alerts<small>Follows, subs, gifts, raids, bits, tips, Hype Train.</small></div>
|
||||
<span class="seg"><% for (const [v, l] of [['card', 'Card'], ['polaroid', 'Polaroid']]) { %><label><input type="radio" name="style" value="<%= v %>"><%= l %></label><% } %></span>
|
||||
</div>
|
||||
<div class="set-row">
|
||||
<div class="lbl">New redeem variations<small>Look of variations you add on Redeems (each variation can still be changed there).</small></div>
|
||||
<span class="seg"><% for (const [v, l] of [['card', 'Card'], ['cassette', 'Cassette']]) { %><label><input type="radio" name="redeemStyle" value="<%= v %>"><%= l %></label><% } %></span>
|
||||
</div>
|
||||
<div class="set-row">
|
||||
<div class="lbl">Read-aloud redeems<small>Variations with a TTS voice.</small></div>
|
||||
<span class="seg"><% for (const [v, l] of [['card', 'Card'], ['letter', 'Letter']]) { %><label><input type="radio" name="ttsStyle" value="<%= v %>"><%= l %></label><% } %></span>
|
||||
</div>
|
||||
<div class="set-row">
|
||||
<div class="lbl">Card colours</div>
|
||||
<div class="colors">
|
||||
<label><input type="color" data-k="card.accent"> accent</label>
|
||||
<label><input type="color" data-k="card.bg"> background</label>
|
||||
<label><input type="color" data-k="card.text"> text</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="set-row">
|
||||
<div class="lbl">Volume<small>Alert sounds (a bits tier can have its own).</small></div>
|
||||
<div class="set-inline"><input type="range" min="0" max="1" step="0.05" data-k="volume" style="max-width:240px;"><span id="vol-out" class="hint"></span></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="set-card">
|
||||
<h3>Events</h3>
|
||||
<div class="al-grid" id="events">
|
||||
<span class="hd">Event</span><span class="hd">Picture</span><span class="hd">Sound</span><span class="hd"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="set-card">
|
||||
<h3>Bits</h3>
|
||||
<div class="set-row">
|
||||
<div class="lbl">No alert under</div>
|
||||
<div class="set-inline"><input type="number" min="1" data-k="bitsMin" style="max-width:7rem;"> <span class="hint">bits</span></div>
|
||||
</div>
|
||||
<div class="set-row stack">
|
||||
<div class="lbl">Tiers<small>The highest tier the cheer reaches is used.</small></div>
|
||||
<div>
|
||||
<div style="overflow-x:auto;"><table class="tiers"><thead><tr><th>From</th><th>Picture</th><th>Sound</th><th>Volume</th><th>Badge</th><th>Hearts</th><th></th></tr></thead><tbody id="tiers"></tbody></table></div>
|
||||
<div class="set-inline"><button type="button" class="outline btn-xs" id="tier-add">+ Add tier</button>
|
||||
<button type="button" class="outline btn-xs" data-test="bits-120">Test 120 bits</button><button type="button" class="outline btn-xs" data-test="bits-500">Test 500 bits</button></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="set-card">
|
||||
<h3>Extras</h3>
|
||||
<div class="set-row">
|
||||
<div class="lbl">Corner sticker<small>Polaroid: sticker on the photo's corner (and the extra ones for big alerts).</small></div>
|
||||
<div class="pk" data-pick="heart" data-type="image"></div>
|
||||
</div>
|
||||
<div class="set-row">
|
||||
<div class="lbl">Photos behind<small>Polaroid: photos fanned out behind multi-month subs, gift bombs and raids.</small></div>
|
||||
<div class="backs" id="backs"></div>
|
||||
</div>
|
||||
<div class="set-row">
|
||||
<div class="lbl">Raid send-off picture<small>When the raided channel has no picture.</small></div>
|
||||
<div class="pk" data-pick="raidFallback" data-type="image"></div>
|
||||
</div>
|
||||
<div class="set-row">
|
||||
<div class="lbl">Default redeem sticker<small>Card and Cassette redeems whose variation has no picture.</small></div>
|
||||
<div class="pk" data-pick="defaultSticker" data-type="image"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="savebar-al">
|
||||
<button type="button" id="save">Save</button>
|
||||
<span id="state" class="hint">No changes</span>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(() => {
|
||||
let T = <%- J(theme) %>;
|
||||
const IMAGES = <%- J(images.map(m => ({ url: m.url, label: m.label }))) %>;
|
||||
const SOUNDS = <%- J(sounds.map(m => ({ url: m.url, label: m.label }))) %>;
|
||||
const EVENTS = [
|
||||
['follow', 'Follow', '', 'follow', 'follow'], ['sub', 'New sub', '', 'sub', 'sub-new'], ['resub', 'Resub', 'sound: same as New sub', null, 'sub-resub'],
|
||||
['prime', 'Prime sub', 'sound: same as New sub', null, 'sub-prime'], ['gift', 'Gift subs', '', 'gift', 'gift-10'],
|
||||
['streak', 'Watch streak', '', 'streak', 'streak'], ['raid', 'Raid', '', 'raid', 'raid'], ['tip', 'Tip', 'StreamElements', 'tip', 'tip-25'],
|
||||
['hype', 'Hype Train', 'start sound', 'hypeBegin', 'hype-begin'],
|
||||
[null, 'Hype Train level up', '', 'hypeLevel', 'hype-level'], [null, 'Hype Train end', '', 'hypeEnd', 'hype-end'],
|
||||
];
|
||||
const esc = s => String(s ?? '').replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]));
|
||||
const get = k => k.split('.').reduce((o, p) => o?.[p], T);
|
||||
const set = (k, v) => { const ps = k.split('.'); let o = T; ps.slice(0, -1).forEach(p => { o = o[p] = o[p] || {}; }); o[ps.at(-1)] = v; dirty(); };
|
||||
const state = document.getElementById('state');
|
||||
const dirty = () => { state.textContent = 'Unsaved changes'; state.className = 'dirty'; };
|
||||
|
||||
// a picker: select from the media library (+ thumbnail / play button); onChange(url)
|
||||
let audio = null;
|
||||
function picker(type, value, onChange) {
|
||||
const list = type === 'image' ? IMAGES : SOUNDS;
|
||||
const w = document.createElement('span'); w.className = 'pk';
|
||||
const opts = ['<option value="">— none —</option>', ...list.map(m => `<option value="${esc(m.url)}">${esc(m.label)}</option>`)];
|
||||
if (value && !list.some(m => m.url === value)) opts.push(`<option value="${esc(value)}">${esc(value.split('/').pop())} (missing)</option>`);
|
||||
w.innerHTML = (type === 'image' ? `<img src="${esc(value || '')}" alt="">` : '') + `<select>${opts.join('')}</select>` + (type === 'audio' ? '<button type="button" class="outline" title="Play">▶</button>' : '');
|
||||
const sel = w.querySelector('select'); sel.value = value || '';
|
||||
sel.addEventListener('change', () => { if (type === 'image') w.querySelector('img').src = sel.value; onChange(sel.value); });
|
||||
if (type === 'audio') w.querySelector('button').addEventListener('click', () => { audio?.pause(); if (sel.value) { audio = new Audio(sel.value); audio.volume = T.volume ?? .8; audio.play(); } });
|
||||
return w;
|
||||
}
|
||||
const testBtn = key => { const b = document.createElement('button'); b.type = 'button'; b.className = 'outline btn-xs'; b.textContent = 'Test'; b.dataset.test = key; return b; };
|
||||
|
||||
function render() {
|
||||
// style radios, colours, numbers
|
||||
for (const n of ['style', 'redeemStyle', 'ttsStyle']) document.querySelectorAll(`input[name=${n}]`).forEach(r => { r.checked = r.value === T[n]; });
|
||||
document.querySelectorAll('[data-k]').forEach(i => { i.value = get(i.dataset.k) ?? ''; });
|
||||
document.getElementById('vol-out').textContent = Math.round((T.volume ?? .8) * 100) + '%';
|
||||
// events grid
|
||||
const g = document.getElementById('events');
|
||||
g.querySelectorAll(':scope > :not(.hd)').forEach(x => x.remove());
|
||||
for (const [artKey, label, sub, soundKey, test] of EVENTS) {
|
||||
const name = document.createElement('div'); name.className = 'al-name'; name.innerHTML = esc(label) + (sub ? `<small>${esc(sub)}</small>` : '');
|
||||
g.append(name,
|
||||
artKey ? picker('image', T.art[artKey], v => { T.art[artKey] = v; dirty(); }) : document.createElement('span'),
|
||||
soundKey ? picker('audio', T.sounds[soundKey], v => { T.sounds[soundKey] = v; dirty(); }) : Object.assign(document.createElement('span'), { className: 'hint', textContent: '' }),
|
||||
testBtn(test));
|
||||
}
|
||||
// bits tiers
|
||||
const tb = document.getElementById('tiers'); tb.innerHTML = '';
|
||||
T.bitsTiers.forEach((t, i) => {
|
||||
const tr = document.createElement('tr');
|
||||
tr.innerHTML = `<td><input type="number" min="1" value="${t.min}" style="width:6rem"></td><td></td><td></td>
|
||||
<td><input type="number" min="0" max="1" step="0.05" value="${t.volume ?? ''}" placeholder="default" style="width:6rem"></td>
|
||||
<td><input type="color" value="${esc(t.badge || '#8a8aa8')}" style="width:2.4rem; height:1.8rem; padding:0"></td>
|
||||
<td><select style="width:4rem">${[0, 1, 2, 3].map(h => `<option ${h === t.hearts ? 'selected' : ''}>${h}</option>`).join('')}</select></td>
|
||||
<td><button type="button" class="outline btn-xs" title="Remove tier">✕</button></td>`;
|
||||
tr.children[1].append(picker('image', t.art, v => { t.art = v; dirty(); }));
|
||||
tr.children[2].append(picker('audio', t.sound, v => { t.sound = v; dirty(); }));
|
||||
const [min, , , vol, badge, hearts] = [...tr.children].map(td => td.querySelector('input, select'));
|
||||
min.addEventListener('input', () => { t.min = +min.value || 1; dirty(); });
|
||||
vol.addEventListener('input', () => { t.volume = vol.value === '' ? null : +vol.value; dirty(); });
|
||||
badge.addEventListener('input', () => { t.badge = badge.value; dirty(); });
|
||||
hearts.addEventListener('change', () => { t.hearts = +hearts.value; dirty(); });
|
||||
tr.querySelector('button').addEventListener('click', () => { T.bitsTiers.splice(i, 1); dirty(); render(); });
|
||||
tb.append(tr);
|
||||
});
|
||||
// single pickers
|
||||
document.querySelectorAll('[data-pick]').forEach(el => {
|
||||
const key = el.dataset.pick, type = el.dataset.type;
|
||||
const w = picker(type, T[key], v => { T[key] = v; dirty(); });
|
||||
w.dataset.pick = key; w.dataset.type = type;
|
||||
el.replaceWith(w);
|
||||
});
|
||||
// photos behind
|
||||
const bk = document.getElementById('backs'); bk.innerHTML = '';
|
||||
T.back.forEach((u, i) => {
|
||||
const b = document.createElement('span'); b.className = 'b';
|
||||
b.innerHTML = `<img src="${esc(u)}" alt="" title="${esc(u.split('/').pop())}"><button type="button" class="outline btn-xs" title="Remove">✕</button>`;
|
||||
b.querySelector('button').addEventListener('click', () => { T.back.splice(i, 1); dirty(); render(); });
|
||||
bk.append(b);
|
||||
});
|
||||
const add = picker('image', '', v => { if (v) { T.back.push(v); dirty(); render(); } });
|
||||
add.querySelector('select').options[0].textContent = '+ add a photo';
|
||||
bk.append(add);
|
||||
}
|
||||
|
||||
document.querySelectorAll('input[name=style], input[name=redeemStyle], input[name=ttsStyle]').forEach(r => r.addEventListener('change', () => { T[r.name] = r.value; dirty(); }));
|
||||
document.querySelectorAll('[data-k]').forEach(i => i.addEventListener('input', () => {
|
||||
set(i.dataset.k, i.type === 'number' || i.type === 'range' ? +i.value : i.value);
|
||||
if (i.dataset.k === 'volume') document.getElementById('vol-out').textContent = Math.round(i.value * 100) + '%';
|
||||
}));
|
||||
document.getElementById('tier-add').addEventListener('click', () => { T.bitsTiers.push({ min: 1, art: '', sound: '', volume: null, badge: '#8a8aa8', hearts: 0 }); dirty(); render(); });
|
||||
|
||||
async function save() {
|
||||
state.textContent = 'Saving…'; state.className = 'hint';
|
||||
try {
|
||||
const r = await fetch('/actions/alerts', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(T) });
|
||||
const j = await r.json();
|
||||
if (!j.ok) throw new Error(j.error || r.status);
|
||||
T = j.theme; render();
|
||||
state.textContent = 'Saved'; state.className = 'hint';
|
||||
} catch (e) { state.textContent = 'Save failed: ' + e.message; state.className = 'dirty'; }
|
||||
}
|
||||
document.getElementById('save').addEventListener('click', save);
|
||||
document.addEventListener('keydown', e => { if ((e.ctrlKey || e.metaKey) && e.key === 's') { e.preventDefault(); save(); } });
|
||||
window.addEventListener('beforeunload', e => { if (state.classList.contains('dirty')) { e.preventDefault(); e.returnValue = ''; } });
|
||||
// test buttons: save first, then play the sample on the overlay
|
||||
document.addEventListener('click', async e => {
|
||||
const b = e.target.closest('[data-test]'); if (!b) return;
|
||||
if (state.classList.contains('dirty')) await save();
|
||||
const r = await fetch('/alerts/test/' + encodeURIComponent(b.dataset.test), { method: 'POST' });
|
||||
const l = b.textContent; b.textContent = r.ok ? 'Sent' : 'Failed'; setTimeout(() => { b.textContent = l; }, 1200);
|
||||
});
|
||||
render();
|
||||
})();
|
||||
</script>
|
||||
Loading…
Add table
Add a link
Reference in a new issue