use echo_api::Store; use echo_api::{Sender, ServiceCtx}; use echo_api::NetView; // DROP : 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 "); 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 = inherited.iter().map(|(c, s)| format!("{c} -> {s}")).collect(); ctx.notice(me, from.uid, format!("Channels passed to their successor: {}.", list.join(", "))); } }