From c296e020b04fa7ae960c07c83106837bd528135c Mon Sep 17 00:00:00 2001 From: Bashy Date: Sun, 22 Nov 2026 17:31:17 +0200 Subject: [PATCH] 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 --- docs/PLANS.md | 3 ++- src/chatlog.js | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/PLANS.md b/docs/PLANS.md index 2567cd2..600a1db 100644 --- a/docs/PLANS.md +++ b/docs/PLANS.md @@ -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, 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 "forget this viewer" button for removal requests (`chatlog.forgetUser()` exists). diff --git a/src/chatlog.js b/src/chatlog.js index a2f2d34..aa61c94 100644 --- a/src/chatlog.js +++ b/src/chatlog.js @@ -13,7 +13,8 @@ // // 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. -// 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 RAW_DAYS = 30; @@ -84,16 +85,18 @@ async function load7tv(twitchId) { if (next.size) seventv = next; } +// Settings → Hidden chatters: counted, but left out of shown statistics and leaderboards function hiddenUsers() { 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 function onMessage(e) { init(); if (e.broadcaster_user_id) load7tv(e.broadcaster_user_id).catch(() => {}); 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 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 login = String(d.user_login || d.chatter_user_login || username || a?.user || '').toLowerCase(); if (!id && !login) return; // anonymous gifts / cheers - if (hiddenUsers().includes(login)) return; const key = id ? String(id) : `name:${login}`; 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) @@ -194,4 +196,4 @@ function forgetUser(userIdOrLogin) { 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 };