The assigned bot now enforces kickers on channel lines: KICK <#channel> CAPS ON [min [percent]], and BOLDS/COLORS/UNDERLINES/REVERSES/ITALICS for control-code formatting. DONTKICKOPS exempts channel operators. A tripping line is kicked by the bot itself. Kicker config is a typed KickerSettings struct on the channel (event- sourced like ChanSettings) with a violation() check; the engine runs it on every channel PRIVMSG. Factored the founder-or-admin gate into a shared require_channel_admin helper (assign/set/kick).
34 lines
1.6 KiB
Rust
34 lines
1.6 KiB
Rust
use fedserv_api::{Sender, ServiceCtx, Store};
|
|
|
|
// ASSIGN <#channel> <bot> / UNASSIGN <#channel>: put a bot in a channel (or take
|
|
// it out). Channel founder only (or a services admin).
|
|
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store, assigning: bool) {
|
|
let Some(&chan) = args.get(1) else {
|
|
let syntax = if assigning { "Syntax: ASSIGN <#channel> <bot>" } else { "Syntax: UNASSIGN <#channel>" };
|
|
ctx.notice(me, from.uid, syntax);
|
|
return;
|
|
};
|
|
if !super::require_channel_admin(me, from, chan, ctx, db) {
|
|
return;
|
|
}
|
|
if !assigning {
|
|
match db.unassign_bot(chan) {
|
|
Ok(true) => ctx.notice(me, from.uid, format!("The bot has left \x02{chan}\x02.")),
|
|
Ok(false) => ctx.notice(me, from.uid, format!("\x02{chan}\x02 has no bot assigned.")),
|
|
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
|
|
}
|
|
return;
|
|
}
|
|
let Some(&bot) = args.get(2) else {
|
|
ctx.notice(me, from.uid, "Syntax: ASSIGN <#channel> <bot>");
|
|
return;
|
|
};
|
|
let Some(botnick) = db.bots().into_iter().find(|b| b.nick.eq_ignore_ascii_case(bot)).map(|b| b.nick) else {
|
|
ctx.notice(me, from.uid, format!("There's no bot named \x02{bot}\x02. See \x02BOT LIST\x02."));
|
|
return;
|
|
};
|
|
match db.assign_bot(chan, &botnick) {
|
|
Ok(()) => ctx.notice(me, from.uid, format!("Bot \x02{botnick}\x02 is now assigned to \x02{chan}\x02.")),
|
|
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
|
|
}
|
|
}
|