BotServ: BOT CHANGE

BOT CHANGE <oldnick> <newnick> [user [host [gecos]]] renames or
re-identifies a bot; omitted fields keep the current values. A rename
moves every channel the bot was assigned to onto the new nick. reconcile
now tracks each live bot's identity hash, so a change that keeps the nick
but alters user/host/gecos quits the stale pseudo-client and reintroduces
it (rejoining its channels) — a rename does the same via the registry.
This commit is contained in:
Jean Chevronnet 2026-07-13 17:30:27 +00:00
parent ec3205bf75
commit 1cc438f4ed
No known key found for this signature in database
4 changed files with 132 additions and 3 deletions

View file

@ -1,4 +1,4 @@
use fedserv_api::{Priv, Sender, ServiceCtx, Store};
use fedserv_api::{ChanError, Priv, Sender, ServiceCtx, Store};
// BOT ADD <nick> <user> <host> [gecos] | BOT DEL <nick> | BOT LIST — manage the
// bot registry. Administering bots is oper-only (Priv::Admin).
@ -19,6 +19,25 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db:
Err(_) => ctx.notice(me, from.uid, format!("A bot named \x02{nick}\x02 already exists, or that didn't work.")),
}
}
Some("CHANGE") => {
let (Some(&old), Some(&newnick)) = (args.get(2), args.get(3)) else {
ctx.notice(me, from.uid, "Syntax: BOT CHANGE <oldnick> <newnick> [user [host [gecos]]]");
return;
};
// Omitted fields keep the bot's current values.
let Some(cur) = db.bots().into_iter().find(|b| b.nick.eq_ignore_ascii_case(old)) else {
ctx.notice(me, from.uid, format!("There's no bot named \x02{old}\x02."));
return;
};
let user = args.get(4).map(|s| s.to_string()).unwrap_or(cur.user);
let host = args.get(5).map(|s| s.to_string()).unwrap_or(cur.host);
let gecos = if args.len() > 6 { args[6..].join(" ") } else { cur.gecos };
match db.bot_change(old, newnick, &user, &host, &gecos) {
Ok(()) => ctx.notice(me, from.uid, format!("Bot \x02{old}\x02 is now \x02{newnick}\x02 (\x02{user}@{host}\x02).")),
Err(ChanError::Exists) => ctx.notice(me, from.uid, format!("A bot named \x02{newnick}\x02 already exists.")),
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
}
}
Some("DEL") => {
let Some(&nick) = args.get(2) else {
ctx.notice(me, from.uid, "Syntax: BOT DEL <nick>");
@ -41,6 +60,6 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db:
ctx.notice(me, from.uid, format!(" \x02{}\x02 ({}@{}) — {}", b.nick, b.user, b.host, b.gecos));
}
}
Some(other) => ctx.notice(me, from.uid, format!("Unknown BOT command \x02{other}\x02. Use \x02ADD\x02, \x02DEL\x02 or \x02LIST\x02.")),
Some(other) => ctx.notice(me, from.uid, format!("Unknown BOT command \x02{other}\x02. Use \x02ADD\x02, \x02CHANGE\x02, \x02DEL\x02 or \x02LIST\x02.")),
}
}