Added the check that accounts exist for /get_account and /delete
This commit is contained in:
parent
4b49d820fc
commit
2976d7f9f3
@ -1,12 +1,25 @@
|
||||
use crate::prelude::*;
|
||||
use tokio::task::spawn_blocking;
|
||||
|
||||
#[inline]
|
||||
pub async fn delete(bot: Throttle<Bot>, msg: Message, db: DatabaseConnection) -> crate::Result<()> {
|
||||
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
||||
|
||||
bot.send_message(msg.chat.id, "Choose the account to delete")
|
||||
.reply_markup(menu_markup("delete", user_id, &db).await?)
|
||||
let names: Vec<String> = Account::get_names(user_id, &db)
|
||||
.await?
|
||||
.try_collect()
|
||||
.await?;
|
||||
|
||||
if names.is_empty() {
|
||||
bot.send_message(msg.chat.id, "You don't have any accounts")
|
||||
.reply_markup(deletion_markup())
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let markup = spawn_blocking(|| menu_markup_sync("delete", names)).await?;
|
||||
bot.send_message(msg.chat.id, "Choose the account to delete")
|
||||
.reply_markup(markup)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
use crate::prelude::*;
|
||||
use tokio::task::spawn_blocking;
|
||||
|
||||
#[inline]
|
||||
pub async fn get_account(
|
||||
@ -8,9 +9,21 @@ pub async fn get_account(
|
||||
) -> crate::Result<()> {
|
||||
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
||||
|
||||
bot.send_message(msg.chat.id, "Choose the account to get")
|
||||
.reply_markup(menu_markup("decrypt", user_id, &db).await?)
|
||||
let names: Vec<String> = Account::get_names(user_id, &db)
|
||||
.await?
|
||||
.try_collect()
|
||||
.await?;
|
||||
|
||||
if names.is_empty() {
|
||||
bot.send_message(msg.chat.id, "You don't have any accounts")
|
||||
.reply_markup(deletion_markup())
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let markup = spawn_blocking(|| menu_markup_sync("decrypt", names)).await?;
|
||||
bot.send_message(msg.chat.id, "Choose the account to get")
|
||||
.reply_markup(markup)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user