diff --git a/modules/README.md b/modules/README.md index 7b5e502..137ddec 100644 --- a/modules/README.md +++ b/modules/README.md @@ -16,4 +16,4 @@ stay flat (`crate::proto`, `crate::nickserv`, `crate::chanserv`). ## Naming A service directory holds its pseudoclient file plus, as commands are split out, -one file per command with the service prefix: `ns_register.rs`, `cs_mode.rs`, etc. +one file per command: `register.rs`, `mode.rs`, etc. diff --git a/modules/chanserv/chanserv.rs b/modules/chanserv/chanserv.rs index 18d3667..812afea 100644 --- a/modules/chanserv/chanserv.rs +++ b/modules/chanserv/chanserv.rs @@ -1,6 +1,9 @@ use crate::engine::db::{ChanError, ChannelInfo, Db}; use crate::engine::service::{Sender, Service, ServiceCtx}; +#[path = "mode.rs"] +mod mode; + pub struct ChanServ { pub uid: String, } @@ -123,30 +126,7 @@ impl Service for ChanServ { Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."), } } - Some("MODE") => { - let Some(&chan) = args.get(1) else { - ctx.notice(me, from.uid, "Syntax: MODE <#channel> , e.g. MODE #chan +nt"); - return; - }; - if args.len() <= 2 { - ctx.notice(me, from.uid, "Syntax: MODE <#channel> , e.g. MODE #chan +nt"); - return; - } - let founder = match db.channel(chan) { - Some(info) => info.founder.clone(), - None => { - ctx.notice(me, from.uid, format!("\x02{chan}\x02 isn't registered.")); - return; - } - }; - if from.account != Some(founder.as_str()) { - ctx.notice(me, from.uid, format!("Only \x02{chan}\x02's founder can change its modes.")); - return; - } - let modes = args[2..].join(" "); - ctx.channel_mode(me, chan, &modes); - ctx.notice(me, from.uid, format!("Set \x02{modes}\x02 on \x02{chan}\x02.")); - } + Some("MODE") => mode::handle(me, from, args, ctx, db), Some("HELP") => ctx.notice(me, from.uid, "ChanServ registers and looks after channels. Commands: \x02REGISTER\x02 <#channel>, \x02INFO\x02 <#channel>, \x02MODE\x02 <#channel> , \x02MLOCK\x02 <#channel> [modes], \x02DROP\x02 <#channel>."), Some(other) => ctx.notice(me, from.uid, format!("I don't know the command \x02{other}\x02. Try \x02HELP\x02.")), None => {} diff --git a/modules/chanserv/mode.rs b/modules/chanserv/mode.rs new file mode 100644 index 0000000..4c8713a --- /dev/null +++ b/modules/chanserv/mode.rs @@ -0,0 +1,28 @@ +use crate::engine::db::Db; +use crate::engine::service::{Sender, ServiceCtx}; + +// MODE <#channel> : the founder sets channel modes via ChanServ. +pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &mut Db) { + let Some(&chan) = args.get(1) else { + ctx.notice(me, from.uid, "Syntax: MODE <#channel> , e.g. MODE #chan +nt"); + return; + }; + if args.len() <= 2 { + ctx.notice(me, from.uid, "Syntax: MODE <#channel> , e.g. MODE #chan +nt"); + return; + } + let founder = match db.channel(chan) { + Some(info) => info.founder.clone(), + None => { + ctx.notice(me, from.uid, format!("\x02{chan}\x02 isn't registered.")); + return; + } + }; + if from.account != Some(founder.as_str()) { + ctx.notice(me, from.uid, format!("Only \x02{chan}\x02's founder can change its modes.")); + return; + } + let modes = args[2..].join(" "); + ctx.channel_mode(me, chan, &modes); + ctx.notice(me, from.uid, format!("Set \x02{modes}\x02 on \x02{chan}\x02.")); +}