Levels by watch time: Viewer, Regular (10 h), Veteran (50 h)

Replaces the cassette-themed point levels. Watch time = our ticks + StreamElements
import; points only rank the leaderboard, bits/subs do not buy a level.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bashy 2026-11-22 17:56:22 +02:00
parent 024934f09f
commit a3e862e9c2
3 changed files with 12 additions and 8 deletions

View file

@ -16,11 +16,11 @@ const VALUE = {
streakPer: 5, streakMax: 100,
};
const LEVELS = [ // cassette theme
{ min: 0, name: 'Newcomer' }, { min: 500, name: 'Regular' }, { min: 2000, name: 'Tape Collector' },
{ min: 6000, name: 'Mixtape Maker' }, { min: 15000, name: 'Side B Legend' },
// Levels by watch time (our ticks + StreamElements import), not points: bits/subs do not buy a level.
const LEVELS = [
{ minHours: 0, name: 'Viewer' }, { minHours: 10, name: 'Regular' }, { minHours: 50, name: 'Veteran' },
];
const levelOf = p => [...LEVELS].reverse().find(l => p >= l.min);
const levelOf = watchMinutes => [...LEVELS].reverse().find(l => watchMinutes >= l.minHours * 60);
const has = t => !!db.raw().prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name = ?").get(t);
const all = (sql, ...a) => db.raw().prepare(sql).all(...a);
@ -46,12 +46,15 @@ function everyone() {
add(x, 'chat', (r.scored || 0) * VALUE.chat); add(x, 'first message', r.intro ? VALUE.intro : 0);
}
if (has('watch_user')) for (const r of all('SELECT user_id, user_login, user_name, ticks FROM watch_user')) {
add(get(r.user_id, r.user_login, r.user_name), 'watching', (r.ticks || 0) * VALUE.watchTick);
const x = get(r.user_id, r.user_login, r.user_name);
x.watchMinutes = (x.watchMinutes || 0) + (r.ticks || 0) * 5;
add(x, 'watching', (r.ticks || 0) * VALUE.watchTick);
}
// StreamElements watch time imported once (seimport.js): login + minutes, counted like our ticks
if (has('watch_import')) for (const r of all('SELECT user_login, minutes FROM watch_import')) {
const x = get(null, r.user_login, null);
x.importedMinutes = (x.importedMinutes || 0) + r.minutes;
x.watchMinutes = (x.watchMinutes || 0) + r.minutes;
add(x, 'watching (StreamElements)', Math.floor(r.minutes / 5) * VALUE.watchTick);
}
if (has('stream_checkin')) for (const r of all('SELECT user_id, COUNT(*) n FROM stream_checkin GROUP BY user_id')) {
@ -71,7 +74,7 @@ function everyone() {
case 'watch_streak': add(x, 'watch streak', Math.min(VALUE.streakMax, r.amount * VALUE.streakPer)); break;
}
}
for (const x of v.values()) x.level = levelOf(x.total);
for (const x of v.values()) x.level = levelOf(x.watchMinutes || 0);
return v;
}