BotServ: BOTSTATS per-channel activity

BOTSTATS <#channel> reports the lines the bot has seen this session and
the top talkers. Tracked live in the network view (bounded per-nick map),
recorded for bot-assigned channels only, and also fed to the shared stats
registry as botserv.messages.
This commit is contained in:
Jean Chevronnet 2026-07-13 19:20:52 +00:00
parent bddf13459d
commit 766ef6ca47
No known key found for this signature in database
5 changed files with 75 additions and 0 deletions

25
botserv/src/stats.rs Normal file
View file

@ -0,0 +1,25 @@
use fedserv_api::{NetView, Sender, ServiceCtx, Store};
// BOTSTATS <#channel>: session activity the bot has seen in a channel — total
// lines and the top talkers. Founder-or-admin.
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net: &dyn NetView, db: &mut dyn Store) {
let Some(&chan) = args.get(1) else {
ctx.notice(me, from.uid, "Syntax: BOTSTATS <#channel>");
return;
};
if !super::require_channel_admin(me, from, chan, ctx, db) {
return;
}
let Some((lines, top)) = net.channel_activity(chan) else {
ctx.notice(me, from.uid, format!("No activity recorded for \x02{chan}\x02 yet."));
return;
};
ctx.notice(me, from.uid, format!("\x02{chan}\x02\x02{lines}\x02 line(s) seen this session."));
if top.is_empty() {
return;
}
ctx.notice(me, from.uid, "Top talkers:");
for (i, (nick, count)) in top.iter().enumerate() {
ctx.notice(me, from.uid, format!(" {}. \x02{nick}\x02{count}", i + 1));
}
}