All checks were successful
CI / check (push) Successful in 3m59s
SET <#channel> SUCCESSOR <account>|OFF names an account that inherits the channel if the founder's account is dropped or expires, instead of the channel being released. Adds a ChannelInfo.successor field + event, and centralises the founder-gone channel release into a single release_founded_channels store method used by DROP, expiry, and the gossip account-gone path so all three transfer consistently.
37 lines
1.6 KiB
Rust
37 lines
1.6 KiB
Rust
use echo_api::Store;
|
|
use echo_api::{Sender, ServiceCtx};
|
|
use echo_api::NetView;
|
|
|
|
// DROP <password>: delete your account. Re-authenticates as confirmation, releases
|
|
// and drops the channels you found, and logs you out.
|
|
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net: &dyn NetView, db: &mut dyn Store) {
|
|
let Some(account) = from.account else {
|
|
ctx.notice(me, from.uid, "You need to be logged in. Identify to NickServ first.");
|
|
return;
|
|
};
|
|
let Some(&password) = args.get(1) else {
|
|
ctx.notice(me, from.uid, "Syntax: DROP <password>");
|
|
return;
|
|
};
|
|
if db.authenticate(account, password).is_none() {
|
|
ctx.notice(me, from.uid, "Invalid password.");
|
|
return;
|
|
}
|
|
// A channel with a successor is inherited; the rest are dropped and released.
|
|
let (inherited, dropped) = db.release_founded_channels(account);
|
|
for chan in &dropped {
|
|
ctx.channel_mode("", chan, "-r"); // server-sourced: release the registered mode
|
|
}
|
|
let _ = db.drop_account(account);
|
|
for uid in net.uids_logged_into(account) {
|
|
ctx.logout(&uid);
|
|
}
|
|
ctx.notice(me, from.uid, format!("Your account \x02{account}\x02 has been dropped."));
|
|
if !dropped.is_empty() {
|
|
ctx.notice(me, from.uid, format!("Channels released: {}.", dropped.join(", ")));
|
|
}
|
|
if !inherited.is_empty() {
|
|
let list: Vec<String> = inherited.iter().map(|(c, s)| format!("{c} -> {s}")).collect();
|
|
ctx.notice(me, from.uid, format!("Channels passed to their successor: {}.", list.join(", ")));
|
|
}
|
|
}
|