HostServ: vhost OFFER menu, plus SETALL/DELALL/GROUP
A curated self-serve menu: operators OFFER <host> / OFFERDEL <n>, anyone sees OFFERLIST, and a user picks one with TAKE <n> (assigned and applied at once). Offers are a global event-sourced list (VhostOfferAdded/Removed, threaded through apply like bots). SETALL/DELALL alias SET/DEL and GROUP is a no-op reassurance, since the per-account vhost already covers every grouped nick.
This commit is contained in:
parent
898461d1c2
commit
2c32dcdc63
7 changed files with 197 additions and 16 deletions
24
hostserv/src/take.rs
Normal file
24
hostserv/src/take.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
use fedserv_api::{Sender, ServiceCtx, Store};
|
||||
|
||||
// TAKE <number>: assign yourself the vhost offered at that position on the menu.
|
||||
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
let Some(account) = from.account else {
|
||||
ctx.notice(me, from.uid, "You need to identify to NickServ first.");
|
||||
return;
|
||||
};
|
||||
let Some(n) = args.get(1).and_then(|s| s.parse::<usize>().ok()) else {
|
||||
ctx.notice(me, from.uid, "Syntax: TAKE <number> (see OFFERLIST)");
|
||||
return;
|
||||
};
|
||||
let Some(host) = n.checked_sub(1).and_then(|i| db.vhost_offers().into_iter().nth(i)) else {
|
||||
ctx.notice(me, from.uid, format!("There's no offer #\x02{n}\x02. See \x02OFFERLIST\x02."));
|
||||
return;
|
||||
};
|
||||
match db.set_vhost(account, &host, "offer") {
|
||||
Ok(()) => {
|
||||
ctx.apply_vhost(from.uid, &host);
|
||||
ctx.notice(me, from.uid, format!("You now have the vhost \x02{host}\x02."));
|
||||
}
|
||||
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