Added delete_all command
This commit is contained in:
parent
a2fae8bb89
commit
b5e003e1d7
@ -12,7 +12,6 @@ async fn get_master_pass(
|
||||
dialogue: MainDialogue,
|
||||
previous: Message,
|
||||
name: String,
|
||||
_: String,
|
||||
) -> crate::Result<()> {
|
||||
let _ = bot.delete_message(previous.chat.id, previous.id).await;
|
||||
dialogue.exit().await?;
|
||||
@ -37,8 +36,8 @@ async fn get_account_name(
|
||||
.await?;
|
||||
dialogue
|
||||
.update(State::GetMasterPass(package_handler(
|
||||
move |bot, msg, db, dialogue, master_pass| {
|
||||
get_master_pass(bot, msg, db, dialogue, previous, name, master_pass)
|
||||
move |bot, msg, db, dialogue, _| {
|
||||
get_master_pass(bot, msg, db, dialogue, previous, name)
|
||||
},
|
||||
)))
|
||||
.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 default;
|
||||
mod delete;
|
||||
mod delete_all;
|
||||
mod get_account;
|
||||
mod get_accounts;
|
||||
mod help;
|
||||
@ -9,6 +10,7 @@ mod set_master_pass;
|
||||
pub use add_account::add_account;
|
||||
pub use default::default;
|
||||
pub use delete::delete;
|
||||
pub use delete_all::delete_all;
|
||||
pub use get_account::get_account;
|
||||
pub use get_accounts::get_accounts;
|
||||
pub use help::help;
|
||||
|
@ -29,6 +29,8 @@ enum Command {
|
||||
SetMasterPass,
|
||||
#[command()]
|
||||
Delete,
|
||||
#[command()]
|
||||
DeleteAll,
|
||||
}
|
||||
|
||||
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::GetAccounts].endpoint(commands::get_accounts))
|
||||
.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()
|
||||
.map_async(utils::delete_message)
|
||||
|
Loading…
Reference in New Issue
Block a user