BotServ: COPY <#src> <#dst> to clone bot config
Copies a channel's kickers, badword list, greet and nobot settings onto another channel (founder-or-admin on both). Cheap because the config is a typed KickerSettings + Vec<String>, not a bag of stringly extensibles.
This commit is contained in:
parent
0edc4d4e87
commit
c8be5b4e95
5 changed files with 83 additions and 0 deletions
17
botserv/src/copy.rs
Normal file
17
botserv/src/copy.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
use fedserv_api::{Sender, ServiceCtx, Store};
|
||||
|
||||
// COPY <#source> <#dest>: copy a channel's bot configuration — kickers,
|
||||
// badwords, greet and nobot — onto another. Requires founder-or-admin on both.
|
||||
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
let (Some(&src), Some(&dst)) = (args.get(1), args.get(2)) else {
|
||||
ctx.notice(me, from.uid, "Syntax: COPY <#source> <#dest>");
|
||||
return;
|
||||
};
|
||||
if !super::require_channel_admin(me, from, src, ctx, db) || !super::require_channel_admin(me, from, dst, ctx, db) {
|
||||
return;
|
||||
}
|
||||
match db.copy_bot_config(src, dst) {
|
||||
Ok(()) => ctx.notice(me, from.uid, format!("Copied \x02{src}\x02's bot settings (kickers, badwords, greet, nobot) to \x02{dst}\x02.")),
|
||||
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,8 @@ mod set;
|
|||
mod kick;
|
||||
#[path = "badwords.rs"]
|
||||
mod badwords;
|
||||
#[path = "copy.rs"]
|
||||
mod copy;
|
||||
|
||||
// Shared gate: the sender may administer <chan>'s bot options only as its
|
||||
// founder or a services admin. Notices and returns false on failure.
|
||||
|
|
@ -60,6 +62,7 @@ impl Service for BotServ {
|
|||
Some("SET") => set::handle(me, from, args, ctx, db),
|
||||
Some("KICK") => kick::handle(me, from, args, ctx, db),
|
||||
Some("BADWORDS") => badwords::handle(me, from, args, ctx, db),
|
||||
Some("COPY") => copy::handle(me, from, args, ctx, db),
|
||||
Some("HELP") | None => ctx.notice(me, from.uid, "BotServ keeps service bots for your channels: \x02ASSIGN\x02 <#channel> <bot> puts a bot in your channel, \x02UNASSIGN\x02 <#channel> removes it, \x02INFO\x02 <bot|#channel> shows details, \x02SAY\x02/\x02ACT\x02 <#channel> <text> speaks through the bot, \x02SET\x02 <#channel> GREET <on|off> toggles greets, \x02KICK\x02 <#channel> <type> <on|off> configures kickers, \x02BADWORDS\x02 <#channel> ADD|DEL|LIST manages badword regexes. 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.")),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue