Added delete_all command
This commit is contained in:
parent
a2fae8bb89
commit
b5e003e1d7
@ -12,7 +12,6 @@ async fn get_master_pass(
|
|||||||
dialogue: MainDialogue,
|
dialogue: MainDialogue,
|
||||||
previous: Message,
|
previous: Message,
|
||||||
name: String,
|
name: String,
|
||||||
_: String,
|
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
let _ = bot.delete_message(previous.chat.id, previous.id).await;
|
let _ = bot.delete_message(previous.chat.id, previous.id).await;
|
||||||
dialogue.exit().await?;
|
dialogue.exit().await?;
|
||||||
@ -37,8 +36,8 @@ async fn get_account_name(
|
|||||||
.await?;
|
.await?;
|
||||||
dialogue
|
dialogue
|
||||||
.update(State::GetMasterPass(package_handler(
|
.update(State::GetMasterPass(package_handler(
|
||||||
move |bot, msg, db, dialogue, master_pass| {
|
move |bot, msg, db, dialogue, _| {
|
||||||
get_master_pass(bot, msg, db, dialogue, previous, name, master_pass)
|
get_master_pass(bot, msg, db, dialogue, previous, name)
|
||||||
},
|
},
|
||||||
)))
|
)))
|
||||||
.await?;
|
.await?;
|
||||||
|
45
src/handlers/commands/delete_all.rs
Normal file
45
src/handlers/commands/delete_all.rs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
use crate::{
|
||||||
|
entity::{account, prelude::*},
|
||||||
|
handlers::{utils::package_handler, MainDialogue, State},
|
||||||
|
};
|
||||||
|
use sea_orm::prelude::*;
|
||||||
|
use teloxide::{adaptors::Throttle, prelude::*};
|
||||||
|
|
||||||
|
async fn get_master_pass(
|
||||||
|
bot: Throttle<Bot>,
|
||||||
|
msg: Message,
|
||||||
|
db: DatabaseConnection,
|
||||||
|
dialogue: MainDialogue,
|
||||||
|
previous: Message,
|
||||||
|
) -> crate::Result<()> {
|
||||||
|
let _ = bot.delete_message(previous.chat.id, previous.id).await;
|
||||||
|
dialogue.exit().await?;
|
||||||
|
let user_id = msg.from().unwrap().id.0;
|
||||||
|
Account::delete_many()
|
||||||
|
.filter(account::Column::UserId.eq(user_id))
|
||||||
|
.exec(&db)
|
||||||
|
.await?;
|
||||||
|
MasterPass::delete_by_id(user_id).exec(&db).await?;
|
||||||
|
bot.send_message(msg.chat.id, "Everything was deleted")
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn delete_all(
|
||||||
|
bot: Throttle<Bot>,
|
||||||
|
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(package_handler(
|
||||||
|
move |bot, msg, db, dialogue, _| get_master_pass(bot, msg, db, dialogue, previous),
|
||||||
|
)))
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
mod add_account;
|
mod add_account;
|
||||||
mod default;
|
mod default;
|
||||||
mod delete;
|
mod delete;
|
||||||
|
mod delete_all;
|
||||||
mod get_account;
|
mod get_account;
|
||||||
mod get_accounts;
|
mod get_accounts;
|
||||||
mod help;
|
mod help;
|
||||||
@ -9,6 +10,7 @@ mod set_master_pass;
|
|||||||
pub use add_account::add_account;
|
pub use add_account::add_account;
|
||||||
pub use default::default;
|
pub use default::default;
|
||||||
pub use delete::delete;
|
pub use delete::delete;
|
||||||
|
pub use delete_all::delete_all;
|
||||||
pub use get_account::get_account;
|
pub use get_account::get_account;
|
||||||
pub use get_accounts::get_accounts;
|
pub use get_accounts::get_accounts;
|
||||||
pub use help::help;
|
pub use help::help;
|
||||||
|
@ -29,6 +29,8 @@ enum Command {
|
|||||||
SetMasterPass,
|
SetMasterPass,
|
||||||
#[command()]
|
#[command()]
|
||||||
Delete,
|
Delete,
|
||||||
|
#[command()]
|
||||||
|
DeleteAll,
|
||||||
}
|
}
|
||||||
|
|
||||||
type MainDialogue = Dialogue<State, InMemStorage<State>>;
|
type MainDialogue = Dialogue<State, InMemStorage<State>>;
|
||||||
@ -73,7 +75,8 @@ pub fn get_dispatcher(
|
|||||||
.branch(case![Command::GetAccount].endpoint(commands::get_account))
|
.branch(case![Command::GetAccount].endpoint(commands::get_account))
|
||||||
.branch(case![Command::GetAccounts].endpoint(commands::get_accounts))
|
.branch(case![Command::GetAccounts].endpoint(commands::get_accounts))
|
||||||
.branch(case![Command::SetMasterPass].endpoint(commands::set_master_pass))
|
.branch(case![Command::SetMasterPass].endpoint(commands::set_master_pass))
|
||||||
.branch(case![Command::Delete].endpoint(commands::delete));
|
.branch(case![Command::Delete].endpoint(commands::delete))
|
||||||
|
.branch(case![Command::DeleteAll].endpoint(commands::delete_all));
|
||||||
|
|
||||||
let message_handler = Update::filter_message()
|
let message_handler = Update::filter_message()
|
||||||
.map_async(utils::delete_message)
|
.map_async(utils::delete_message)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user