Added menu endpoints
This commit is contained in:
23
src/commands/menu.rs
Normal file
23
src/commands/menu.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use crate::prelude::*;
|
||||
use tokio::task::spawn_blocking;
|
||||
|
||||
pub async fn menu(bot: Throttle<Bot>, msg: Message, db: DatabaseConnection) -> crate::Result<()> {
|
||||
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
||||
|
||||
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?;
|
||||
}
|
||||
|
||||
let markup = spawn_blocking(|| menu_markup(names)).await?;
|
||||
bot.send_message(msg.chat.id, "Choose your account")
|
||||
.reply_markup(markup)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
@ -10,6 +10,7 @@ mod get_account;
|
||||
mod get_accounts;
|
||||
mod help;
|
||||
mod import;
|
||||
mod menu;
|
||||
mod set_master_pass;
|
||||
mod start;
|
||||
|
||||
@ -23,6 +24,7 @@ pub use get_account::get_account;
|
||||
pub use get_accounts::get_accounts;
|
||||
pub use help::help;
|
||||
pub use import::import;
|
||||
pub use menu::menu;
|
||||
pub use set_master_pass::set_master_pass;
|
||||
pub use start::start;
|
||||
|
||||
@ -56,6 +58,8 @@ pub enum Command {
|
||||
Import,
|
||||
#[command(description = "generates 10 secure passwords")]
|
||||
GenPassword,
|
||||
#[command(description = "gives you a menu to manage your accounts")]
|
||||
Menu,
|
||||
#[command(description = "cancels the current action")]
|
||||
Cancel,
|
||||
}
|
||||
|
Reference in New Issue
Block a user