Added ask_name_handler
This commit is contained in:
parent
255f29bfad
commit
010ac62a74
@ -25,31 +25,4 @@ handler!(
|
|||||||
State::GetMasterPass,
|
State::GetMasterPass,
|
||||||
get_master_pass
|
get_master_pass
|
||||||
);
|
);
|
||||||
|
ask_name_handler!(pub delete(), "Send the name of the account to delete", get_account_name);
|
||||||
/// Handles /delete command
|
|
||||||
pub async fn delete(
|
|
||||||
bot: Throttle<Bot>,
|
|
||||||
msg: Message,
|
|
||||||
dialogue: MainDialogue,
|
|
||||||
db: DatabaseConnection,
|
|
||||||
) -> crate::Result<()> {
|
|
||||||
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
|
||||||
let markup = account_markup(user_id, &db).await?;
|
|
||||||
if markup.keyboard.is_empty() {
|
|
||||||
bot.send_message(msg.chat.id, "No accounts found")
|
|
||||||
.reply_markup(deletion_markup())
|
|
||||||
.await?;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
let previous = bot
|
|
||||||
.send_message(msg.chat.id, "Send the name of the account to delete")
|
|
||||||
.reply_markup(markup)
|
|
||||||
.await?;
|
|
||||||
dialogue
|
|
||||||
.update(State::GetExistingName(Handler::new(
|
|
||||||
get_account_name,
|
|
||||||
&previous,
|
|
||||||
)))
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
@ -32,31 +32,4 @@ async fn get_master_pass(
|
|||||||
}
|
}
|
||||||
|
|
||||||
handler!(get_account_name(name:String), "Send master password", State::GetMasterPass, get_master_pass);
|
handler!(get_account_name(name:String), "Send master password", State::GetMasterPass, get_master_pass);
|
||||||
|
ask_name_handler!(pub get_account(), "Send the name of the account to get", get_account_name);
|
||||||
/// Handles /get_account command
|
|
||||||
pub async fn get_account(
|
|
||||||
bot: Throttle<Bot>,
|
|
||||||
msg: Message,
|
|
||||||
dialogue: MainDialogue,
|
|
||||||
db: DatabaseConnection,
|
|
||||||
) -> crate::Result<()> {
|
|
||||||
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
|
||||||
let markup = account_markup(user_id, &db).await?;
|
|
||||||
if markup.keyboard.is_empty() {
|
|
||||||
bot.send_message(msg.chat.id, "No accounts found")
|
|
||||||
.reply_markup(deletion_markup())
|
|
||||||
.await?;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
let previous = bot
|
|
||||||
.send_message(msg.chat.id, "Send the name of the account to get")
|
|
||||||
.reply_markup(markup)
|
|
||||||
.await?;
|
|
||||||
dialogue
|
|
||||||
.update(State::GetExistingName(Handler::new(
|
|
||||||
get_account_name,
|
|
||||||
&previous,
|
|
||||||
)))
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
@ -7,7 +7,7 @@ macro_rules! handler {
|
|||||||
msg: Message,
|
msg: Message,
|
||||||
_: DatabaseConnection,
|
_: DatabaseConnection,
|
||||||
dialogue: MainDialogue,
|
dialogue: MainDialogue,
|
||||||
$($param: $type,)*
|
$($param: $type),*
|
||||||
) -> $crate::Result<()> {
|
) -> $crate::Result<()> {
|
||||||
let previous = bot.send_message(msg.chat.id, $message).await?;
|
let previous = bot.send_message(msg.chat.id, $message).await?;
|
||||||
dialogue
|
dialogue
|
||||||
@ -20,3 +20,36 @@ macro_rules! handler {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! ask_name_handler {
|
||||||
|
($v: vis $function_name: ident ($($param: ident: $type: ty),*), $message: literal, $next_func: ident) => {
|
||||||
|
$v async fn $function_name(
|
||||||
|
bot: Throttle<Bot>,
|
||||||
|
msg: Message,
|
||||||
|
dialogue: MainDialogue,
|
||||||
|
db: DatabaseConnection,
|
||||||
|
$($param: $type),*
|
||||||
|
) -> $crate::Result<()> {
|
||||||
|
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
||||||
|
let markup = account_markup(user_id, &db).await?;
|
||||||
|
if markup.keyboard.is_empty() {
|
||||||
|
bot.send_message(msg.chat.id, "No accounts found")
|
||||||
|
.reply_markup(deletion_markup())
|
||||||
|
.await?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let previous = bot
|
||||||
|
.send_message(msg.chat.id, $message)
|
||||||
|
.reply_markup(markup)
|
||||||
|
.await?;
|
||||||
|
dialogue
|
||||||
|
.update(State::GetExistingName(Handler::new(
|
||||||
|
$next_func,
|
||||||
|
&previous,
|
||||||
|
)))
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
pub(crate) use crate::{
|
pub(crate) use crate::{
|
||||||
|
ask_name_handler,
|
||||||
commands::Command,
|
commands::Command,
|
||||||
errors::*,
|
errors::*,
|
||||||
handler,
|
handler,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user