BotServ kickers: times-to-ban (TTB) + BANEXPIRE
KICK <#channel> TTB <n> makes the bot ban a user after they've been kicked n times (by any kicker) instead of only kicking; SET <#channel> BANEXPIRE <duration|off> controls how long that ban lasts. One clear per-channel knob rather than Anope's per-kicker ttb array. The kick count rides in the existing ephemeral per-user chatter state, so it's dropped when the user parts or quits. On the ban the bot sets +b on an ideal host mask and, if BANEXPIRE is set, queues an unban that is swept off the next event — no timer thread. Ban time is injectable for tests.
This commit is contained in:
parent
ca95184359
commit
ec3205bf75
5 changed files with 225 additions and 63 deletions
|
|
@ -1,15 +1,42 @@
|
|||
use fedserv_api::{ChanSetting, Sender, ServiceCtx, Store};
|
||||
use fedserv_api::{parse_duration, ChanSetting, Sender, ServiceCtx, Store};
|
||||
|
||||
// SET <#channel> <option> <on|off>: per-channel bot options. Founder-or-admin.
|
||||
// Currently: GREET (show members' personal greets when they join).
|
||||
// SET <#channel> <option> <value>: per-channel bot options. Founder-or-admin.
|
||||
// GREET <on|off> (show members' greets on join), BANEXPIRE <duration|off> (how
|
||||
// long kicker bans last).
|
||||
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
let (Some(&chan), Some(option)) = (args.get(1), args.get(2)) else {
|
||||
ctx.notice(me, from.uid, "Syntax: SET <#channel> GREET <ON|OFF>");
|
||||
ctx.notice(me, from.uid, "Syntax: SET <#channel> <GREET <ON|OFF> | BANEXPIRE <duration|off>>");
|
||||
return;
|
||||
};
|
||||
if !super::require_channel_admin(me, from, chan, ctx, db) {
|
||||
return;
|
||||
}
|
||||
|
||||
// BANEXPIRE takes a duration, not ON/OFF.
|
||||
if option.eq_ignore_ascii_case("BANEXPIRE") {
|
||||
let Some(&arg) = args.get(3) else {
|
||||
ctx.notice(me, from.uid, "Syntax: SET <#channel> BANEXPIRE <duration|off> (e.g. 30m, 2h, off).");
|
||||
return;
|
||||
};
|
||||
let secs = if matches!(arg.to_ascii_lowercase().as_str(), "off" | "none" | "0") {
|
||||
0
|
||||
} else {
|
||||
match parse_duration(arg) {
|
||||
Some(s) => s.min(u32::MAX as u64) as u32,
|
||||
None => {
|
||||
ctx.notice(me, from.uid, format!("\x02{arg}\x02 isn't a valid duration. Try 30m, 2h, 7d or \x02off\x02."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
match db.set_ban_expire(chan, secs) {
|
||||
Ok(()) if secs == 0 => ctx.notice(me, from.uid, format!("Kicker bans in \x02{chan}\x02 won't expire automatically.")),
|
||||
Ok(()) => ctx.notice(me, from.uid, format!("Kicker bans in \x02{chan}\x02 will expire after \x02{arg}\x02.")),
|
||||
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let on = match args.get(3).map(|s| s.to_ascii_uppercase()).as_deref() {
|
||||
Some("ON") | Some("TRUE") => true,
|
||||
Some("OFF") | Some("FALSE") => false,
|
||||
|
|
@ -24,6 +51,6 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db:
|
|||
Ok(()) => ctx.notice(me, from.uid, format!("Greet messages are now \x02off\x02 in \x02{chan}\x02.")),
|
||||
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
|
||||
},
|
||||
other => ctx.notice(me, from.uid, format!("Unknown option \x02{other}\x02. Available: \x02GREET\x02.")),
|
||||
other => ctx.notice(me, from.uid, format!("Unknown option \x02{other}\x02. Available: \x02GREET\x02, \x02BANEXPIRE\x02.")),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue