Move the ChanServ MODE command into modules/chanserv/mode.rs
This commit is contained in:
parent
677963924a
commit
b299c4f02e
3 changed files with 33 additions and 25 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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> <modes>, e.g. MODE #chan +nt");
|
||||
return;
|
||||
};
|
||||
if args.len() <= 2 {
|
||||
ctx.notice(me, from.uid, "Syntax: MODE <#channel> <modes>, 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> <modes>, \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 => {}
|
||||
|
|
|
|||
28
modules/chanserv/mode.rs
Normal file
28
modules/chanserv/mode.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use crate::engine::db::Db;
|
||||
use crate::engine::service::{Sender, ServiceCtx};
|
||||
|
||||
// MODE <#channel> <modes>: 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> <modes>, e.g. MODE #chan +nt");
|
||||
return;
|
||||
};
|
||||
if args.len() <= 2 {
|
||||
ctx.notice(me, from.uid, "Syntax: MODE <#channel> <modes>, 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."));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue