Split GroupServ into one file per command
REGISTER/DROP/INFO/LIST/ADD/DEL/FLAGS each move to their own file; the two shared guards (login check, can-manage) stay in lib.rs beside the dispatcher. No behaviour change.
This commit is contained in:
parent
feba6700cb
commit
1916e5fce5
8 changed files with 207 additions and 179 deletions
20
modules/groupserv/src/register.rs
Normal file
20
modules/groupserv/src/register.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
use fedserv_api::{Sender, ServiceCtx, Store};
|
||||
|
||||
// REGISTER <!group>: create a group with you as its founder.
|
||||
pub fn handle(me: &str, from: &Sender, name: Option<&str>, ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
let Some(acc) = super::account(me, from, ctx) else { return };
|
||||
let Some(name) = name else {
|
||||
ctx.notice(me, from.uid, "Syntax: REGISTER <!group>");
|
||||
return;
|
||||
};
|
||||
if !name.starts_with('!') || name.len() < 2 {
|
||||
ctx.notice(me, from.uid, "A group name starts with \x02!\x02, e.g. \x02!staff\x02.");
|
||||
return;
|
||||
}
|
||||
let acc = acc.to_string();
|
||||
match db.group_register(name, &acc) {
|
||||
Ok(()) => ctx.notice(me, from.uid, format!("Group \x02{name}\x02 registered — you're the founder.")),
|
||||
Err(fedserv_api::ChanError::Exists) => ctx.notice(me, from.uid, format!("\x02{name}\x02 is already registered.")),
|
||||
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue