Promote BotServ BOTSTATS to a StatServ pseudo-service
Stats now have their own service. StatServ answers /msg StatServ <#channel> (per-channel activity — lines + top talkers, founder-or-admin) and /msg StatServ SERVER (the shared cross-service counter registry + gauges, operators only). The shared counter map moved from the engine onto the network view so both StatServ (via NetView::stat_counters) and the gRPC Stats API read one source. BotServ's BOTSTATS command is removed; the per-channel activity is still recorded in the dispatch loop.
This commit is contained in:
parent
ad61addb84
commit
04f927d3db
12 changed files with 168 additions and 28 deletions
|
|
@ -22,8 +22,6 @@ mod badwords;
|
|||
mod copy;
|
||||
#[path = "trigger.rs"]
|
||||
mod trigger;
|
||||
#[path = "stats.rs"]
|
||||
mod stats;
|
||||
|
||||
// Shared gate: the sender may administer <chan>'s bot options only as its
|
||||
// founder or a services admin. Notices and returns false on failure.
|
||||
|
|
@ -68,7 +66,6 @@ impl Service for BotServ {
|
|||
Some("BADWORDS") => badwords::handle(me, from, args, ctx, db),
|
||||
Some("COPY") => copy::handle(me, from, args, ctx, db),
|
||||
Some("TRIGGER") => trigger::handle(me, from, args, ctx, db),
|
||||
Some("BOTSTATS") | Some("STATS") => stats::handle(me, from, args, ctx, net, db),
|
||||
Some("HELP") | None => ctx.notice(me, from.uid, "BotServ keeps service bots for your channels: \x02ASSIGN\x02 <#channel> <bot> puts a bot in your channel, \x02UNASSIGN\x02 <#channel> removes it, \x02INFO\x02 <bot|#channel> shows details, \x02SAY\x02/\x02ACT\x02 <#channel> <text> speaks through the bot, \x02SET\x02 <#channel> GREET <on|off> toggles greets, \x02KICK\x02 <#channel> <type> <on|off> configures kickers (with \x02TEST\x02/\x02WARN\x02/\x02TTB\x02), \x02BADWORDS\x02 and \x02TRIGGER\x02 <#channel> ADD|DEL|LIST manage badword regexes and auto-responses, \x02COPY\x02 <#src> <#dst> clones settings. Operators also have \x02BOT\x02 ADD|CHANGE|DEL|LIST."),
|
||||
Some(other) => ctx.notice(me, from.uid, format!("I don't know the command \x02{other}\x02. Try \x02HELP\x02.")),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
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));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue