BotServ: add BOTLIST and AUTOASSIGN default bot
All checks were successful
CI / check (push) Successful in 3m33s
All checks were successful
CI / check (push) Successful in 3m33s
This commit is contained in:
parent
cd6d8b1b93
commit
dd43b9a331
12 changed files with 162 additions and 0 deletions
19
modules/botserv/src/botlist.rs
Normal file
19
modules/botserv/src/botlist.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
use echo_api::{Priv, Sender, ServiceCtx, Store};
|
||||
|
||||
// BOTLIST: show the bots a channel founder can assign. Available to everyone,
|
||||
// unlike \x02BOT LIST\x02 (operator bot administration). Private bots are hidden
|
||||
// from ordinary users but shown, flagged, to operators.
|
||||
pub fn handle(me: &str, from: &Sender, ctx: &mut ServiceCtx, db: &dyn Store) {
|
||||
let is_oper = from.privs.has(Priv::Admin);
|
||||
let bots: Vec<_> = db.bots().into_iter().filter(|b| is_oper || !b.private).collect();
|
||||
if bots.is_empty() {
|
||||
ctx.notice(me, from.uid, "No bots are available.");
|
||||
return;
|
||||
}
|
||||
ctx.notice(me, from.uid, format!("Available bots ({}):", bots.len()));
|
||||
for b in &bots {
|
||||
let flag = if b.private { " \x02[private]\x02" } else { "" };
|
||||
ctx.notice(me, from.uid, format!(" \x02{}\x02 ({}@{}){flag}", b.nick, b.user, b.host));
|
||||
}
|
||||
ctx.notice(me, from.uid, "Assign one with \x02ASSIGN <#channel> <bot>\x02.");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue