From 6a37d010b8877f74af4a43d23518de02e9d50d42 Mon Sep 17 00:00:00 2001 From: Jean Date: Mon, 13 Jul 2026 14:07:47 +0000 Subject: [PATCH] BotServ: add INFO command INFO describes a bot and lists the channels it serves; INFO <#channel> shows which bot is assigned to a channel. Own file, wired into the dispatcher. --- botserv/src/info.rs | 41 +++++++++++++++++++++++++++++++++++++++++ botserv/src/lib.rs | 5 ++++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 botserv/src/info.rs diff --git a/botserv/src/info.rs b/botserv/src/info.rs new file mode 100644 index 0000000..206cc0b --- /dev/null +++ b/botserv/src/info.rs @@ -0,0 +1,41 @@ +use fedserv_api::{Sender, ServiceCtx, Store}; + +// INFO — describe a bot and list the channels it serves. +// INFO <#channel> — show which bot (if any) is assigned to a channel. +pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &dyn Store) { + let Some(&target) = args.get(1) else { + ctx.notice(me, from.uid, "Syntax: INFO "); + return; + }; + + if target.starts_with('#') { + let Some(chan) = db.channel(target) else { + ctx.notice(me, from.uid, format!("\x02{target}\x02 isn't registered.")); + return; + }; + match chan.assigned_bot { + Some(bot) => ctx.notice(me, from.uid, format!("\x02{target}\x02 is served by bot \x02{bot}\x02.")), + None => ctx.notice(me, from.uid, format!("\x02{target}\x02 has no bot assigned. Assign one with \x02ASSIGN\x02 {target} .")), + } + return; + } + + let Some(bot) = db.bots().into_iter().find(|b| b.nick.eq_ignore_ascii_case(target)) else { + ctx.notice(me, from.uid, format!("There's no bot named \x02{target}\x02. See \x02BOT LIST\x02.")); + return; + }; + let channels: Vec = db + .channels() + .into_iter() + .filter(|c| c.assigned_bot.as_deref().is_some_and(|b| b.eq_ignore_ascii_case(&bot.nick))) + .map(|c| c.name) + .collect(); + + ctx.notice(me, from.uid, format!("Bot \x02{}\x02 — {}@{}", bot.nick, bot.user, bot.host)); + ctx.notice(me, from.uid, format!(" Real name: {}", bot.gecos)); + if channels.is_empty() { + ctx.notice(me, from.uid, " Not assigned to any channel."); + } else { + ctx.notice(me, from.uid, format!(" Serving {} channel(s): {}", channels.len(), channels.join(", "))); + } +} diff --git a/botserv/src/lib.rs b/botserv/src/lib.rs index 027fdc9..f374512 100644 --- a/botserv/src/lib.rs +++ b/botserv/src/lib.rs @@ -8,6 +8,8 @@ use fedserv_api::{NetView, Sender, Service, ServiceCtx, Store}; mod bot; #[path = "assign.rs"] mod assign; +#[path = "info.rs"] +mod info; pub struct BotServ { pub uid: String, @@ -30,7 +32,8 @@ impl Service for BotServ { Some("BOT") => bot::handle(me, from, args, ctx, db), Some("ASSIGN") => assign::handle(me, from, args, ctx, db, true), Some("UNASSIGN") => assign::handle(me, from, args, ctx, db, false), - Some("HELP") | None => ctx.notice(me, from.uid, "BotServ keeps service bots for your channels: \x02ASSIGN\x02 <#channel> puts a bot in your channel, \x02UNASSIGN\x02 <#channel> removes it. Operators also have \x02BOT\x02 ADD|DEL|LIST."), + Some("INFO") => info::handle(me, from, args, ctx, db), + Some("HELP") | None => ctx.notice(me, from.uid, "BotServ keeps service bots for your channels: \x02ASSIGN\x02 <#channel> puts a bot in your channel, \x02UNASSIGN\x02 <#channel> removes it, \x02INFO\x02 shows details. Operators also have \x02BOT\x02 ADD|DEL|LIST."), Some(other) => ctx.notice(me, from.uid, format!("I don't know the command \x02{other}\x02. Try \x02HELP\x02.")), } }