Chat stats: count bots too; hide them only when showing statistics

Hidden chatters are now counted like everyone else; statistics pages and
leaderboards filter them at display time (chatlog.isHidden / hiddenUsers), so
editing the list applies immediately without losing data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bashy 2026-11-22 17:31:17 +02:00
parent 2991c88d9e
commit c296e020b0
2 changed files with 8 additions and 5 deletions

View file

@ -76,6 +76,7 @@ Estimate: about half a day once chat is read server-side.
Status: **logging built 2026-11-22** (src/chatlog.js), with her choices: per-viewer counts (messages, per day, Status: **logging built 2026-11-22** (src/chatlog.js), with her choices: per-viewer counts (messages, per day,
emotes incl. 7TV, !commands, first/last seen) parsed as messages arrive; raw messages kept **30 days** only; emotes incl. 7TV, !commands, first/last seen) parsed as messages arrive; raw messages kept **30 days** only;
moderation removes stored text; hidden chatters (bots) not counted. Viewer actions are counted too moderation removes stored text; hidden chatters (bots) are counted but must be left out of shown
statistics and leaderboards (filter at display time with chatlog.isHidden()). Viewer actions are counted too
(chat_action: rewards + points, Power-ups + bits, cheers, subs, gifts, follows, raids, watch streaks, tips). Still to do: a statistics page, and a (chat_action: rewards + points, Power-ups + bits, cheers, subs, gifts, follows, raids, watch streaks, tips). Still to do: a statistics page, and a
"forget this viewer" button for removal requests (`chatlog.forgetUser()` exists). "forget this viewer" button for removal requests (`chatlog.forgetUser()` exists).

View file

@ -13,7 +13,8 @@
// //
// Moderation: a deleted message, a timeout/ban (clear_user_messages) or a chat clear removes the stored text at // Moderation: a deleted message, a timeout/ban (clear_user_messages) or a chat clear removes the stored text at
// once (Twitch developer rules); the counts stay, they hold no message content. // once (Twitch developer rules); the counts stay, they hold no message content.
// Accounts in Settings → Hidden chatters (bots) are not counted. // Accounts in Settings → Hidden chatters (bots) ARE counted, but statistics pages / leaderboards must leave them
// out when showing data: use isHidden(login) / hiddenUsers() there (changing the list then applies at once).
const db = require('./db'); const db = require('./db');
const RAW_DAYS = 30; const RAW_DAYS = 30;
@ -84,16 +85,18 @@ async function load7tv(twitchId) {
if (next.size) seventv = next; if (next.size) seventv = next;
} }
// Settings → Hidden chatters: counted, but left out of shown statistics and leaderboards
function hiddenUsers() { function hiddenUsers() {
return String(db.getSettings().chat_hidden_users || '').toLowerCase().split(/[\s,]+/).filter(Boolean); return String(db.getSettings().chat_hidden_users || '').toLowerCase().split(/[\s,]+/).filter(Boolean);
} }
const isHidden = login => hiddenUsers().includes(String(login || '').toLowerCase());
// one chat message: count it, keep the raw copy // one chat message: count it, keep the raw copy
function onMessage(e) { function onMessage(e) {
init(); init();
if (e.broadcaster_user_id) load7tv(e.broadcaster_user_id).catch(() => {}); if (e.broadcaster_user_id) load7tv(e.broadcaster_user_id).catch(() => {});
const login = String(e.chatter_user_login || '').toLowerCase(); const login = String(e.chatter_user_login || '').toLowerCase();
if (!e.chatter_user_id || hiddenUsers().includes(login)) return; if (!e.chatter_user_id) return;
const text = String(e.message?.text || ''); const text = String(e.message?.text || '');
const at = new Date().toISOString(), day = at.slice(0, 10); const at = new Date().toISOString(), day = at.slice(0, 10);
@ -161,7 +164,6 @@ function onAction(eventType, detail, username, data, replay) {
const id = d.user_id || d.chatter_user_id || null; const id = d.user_id || d.chatter_user_id || null;
const login = String(d.user_login || d.chatter_user_login || username || a?.user || '').toLowerCase(); const login = String(d.user_login || d.chatter_user_login || username || a?.user || '').toLowerCase();
if (!id && !login) return; // anonymous gifts / cheers if (!id && !login) return; // anonymous gifts / cheers
if (hiddenUsers().includes(login)) return;
const key = id ? String(id) : `name:${login}`; const key = id ? String(id) : `name:${login}`;
const amount = Number(act.amount) || 0, at = new Date().toISOString(); const amount = Number(act.amount) || 0, at = new Date().toISOString();
db.raw().prepare(`INSERT INTO chat_action (user_key, user_login, user_name, action, item, uses, amount, unit, first_at, last_at) db.raw().prepare(`INSERT INTO chat_action (user_key, user_login, user_name, action, item, uses, amount, unit, first_at, last_at)
@ -194,4 +196,4 @@ function forgetUser(userIdOrLogin) {
return u || n ? 1 : 0; return u || n ? 1 : 0;
} }
module.exports = { init, onMessage, onAction, onDelete, onClearUser, onClear, prune, forgetUser, RAW_DAYS }; module.exports = { init, onMessage, onAction, onDelete, onClearUser, onClear, prune, forgetUser, hiddenUsers, isHidden, RAW_DAYS };