use crate::prelude::*; use tokio::join; /// Gets the master password, deletes the accounts and the master password from DB. /// Although it doesn't use the master password, we get it to be sure that it's the user who used that command async fn get_master_pass( bot: Throttle, msg: Message, db: DatabaseConnection, dialogue: MainDialogue, _: String, ) -> crate::Result<()> { dialogue.exit().await?; let user_id = msg.from().ok_or(NoUserInfo)?.id.0; match join!( Account::delete_all(user_id, &db), MasterPass::remove(user_id, &db), ) { (Ok(_), Ok(_)) => (), (Err(err), _) | (Ok(_), Err(err)) => return Err(err.into()), }; bot.send_message(msg.chat.id, "Everything was deleted") .reply_markup(deletion_markup()) .await?; Ok(()) } /// Handles /delete_all command pub async fn delete_all( bot: Throttle, msg: Message, dialogue: MainDialogue, ) -> crate::Result<()> { let previous = bot .send_message( msg.chat.id, "Send master password to delete EVERYTHING.\nTHIS ACTION IS IRREVERSIBLE", ) .await?; dialogue .update(State::GetMasterPass(Handler::new( get_master_pass, previous, ))) .await?; Ok(()) }