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

@ -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 };