2023-05-03 18:08:14 +00:00
|
|
|
use sea_orm::prelude::*;
|
|
|
|
use teloxide::{adaptors::Throttle, prelude::*};
|
|
|
|
|
2023-05-27 23:21:50 +00:00
|
|
|
use crate::handlers::{utils::validate_field, MainDialogue};
|
2023-05-03 18:08:14 +00:00
|
|
|
|
2023-05-09 17:27:58 +00:00
|
|
|
/// Function to handle GetPassword state
|
2023-05-03 18:08:14 +00:00
|
|
|
pub async fn get_password(
|
|
|
|
bot: Throttle<Bot>,
|
|
|
|
msg: Message,
|
|
|
|
db: DatabaseConnection,
|
|
|
|
dialogue: MainDialogue,
|
2023-05-23 18:09:28 +00:00
|
|
|
next: super::PackagedHandler<String>,
|
2023-05-03 18:08:14 +00:00
|
|
|
) -> crate::Result<()> {
|
|
|
|
super::generic::generic(
|
|
|
|
bot,
|
|
|
|
msg,
|
|
|
|
db,
|
|
|
|
dialogue,
|
2023-05-07 16:04:48 +00:00
|
|
|
|bot, msg, _, password| {
|
|
|
|
Box::pin(async move {
|
|
|
|
let is_valid = validate_field(password);
|
|
|
|
if !is_valid {
|
2023-05-27 23:21:50 +00:00
|
|
|
let msg = bot
|
|
|
|
.send_message(msg.chat.id, "Invalid password. Try again")
|
2023-05-07 16:04:48 +00:00
|
|
|
.await?;
|
2023-05-27 23:21:50 +00:00
|
|
|
return Ok(Some(msg));
|
2023-05-07 16:04:48 +00:00
|
|
|
}
|
2023-05-27 23:21:50 +00:00
|
|
|
Ok(None)
|
2023-05-07 16:04:48 +00:00
|
|
|
})
|
|
|
|
},
|
2023-05-30 11:21:04 +00:00
|
|
|
"Couldn't get the text of the message. Send the master password again",
|
2023-05-03 18:08:14 +00:00
|
|
|
next,
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
}
|