Moved handler.func.is_none check to the top

This commit is contained in:
StNicolay 2023-07-15 00:07:59 +03:00
parent 916b20e33c
commit 667f8b64fb
Signed by: StNicolay
GPG Key ID: 9693D04DCD962B0D
3 changed files with 17 additions and 15 deletions

View File

@ -21,6 +21,11 @@ where
) -> BoxFuture<'a, crate::Result<Option<Message>>>,
{
let mut handler = next.lock().await;
if handler.func.is_none() {
let _ = dialogue.exit().await;
return Err(HandlerUsed.into());
}
delete_optional(&bot, handler.previous.as_ref()).await;
let text = match msg.text() {
@ -40,11 +45,6 @@ where
return Ok(());
}
if handler.func.is_none() {
let _ = dialogue.exit().await;
return Err(HandlerUsed.into());
}
if let Some(failure_message) = check(&bot, &msg, &db, text).await? {
handler.previous = Some(failure_message);
return Ok(());

View File

@ -28,7 +28,13 @@ pub async fn get_existing_name(
next: PackagedHandler<String>,
) -> crate::Result<()> {
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
let mut handler = next.lock().await;
if handler.func.is_none() {
let _ = dialogue.exit().await;
return Err(HandlerUsed.into());
}
delete_optional(&bot, handler.previous.as_ref()).await;
let text = match msg.text() {
@ -54,11 +60,6 @@ pub async fn get_existing_name(
return Ok(());
}
if handler.func.is_none() {
let _ = dialogue.exit().await;
return Err(HandlerUsed.into());
}
if let Some(failure_message) = check_name(&bot, &msg, &db, text, user_id).await? {
handler.previous = Some(failure_message);
return Ok(());

View File

@ -114,7 +114,13 @@ pub async fn get_user(
next: PackagedHandler<User>,
) -> crate::Result<()> {
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
let mut handler = next.lock().await;
if handler.func.is_none() {
let _ = dialogue.exit().await;
return Err(HandlerUsed.into());
}
delete_optional(&bot, handler.previous.as_ref()).await;
if let Some("/cancel") = msg.text().map(str::trim) {
@ -125,11 +131,6 @@ pub async fn get_user(
return Ok(());
}
if handler.func.is_none() {
let _ = dialogue.exit().await;
return Err(HandlerUsed.into());
}
let document = match msg.document() {
Some(document) => document,
None => {