Updated generic and get_document to close dialogue on /cancel and errors
This commit is contained in:
parent
996dca00fb
commit
5f34cfb109
@ -25,17 +25,22 @@ where
|
||||
) -> PinnedFuture<'a, crate::Result<bool>>,
|
||||
{
|
||||
let handler = next.lock().await.take();
|
||||
let previous = handler
|
||||
.as_ref()
|
||||
.and_then(|handler| handler.previous.as_ref());
|
||||
let previous = handler.as_ref().and_then(|h| h.previous.as_ref());
|
||||
delete_optional(&bot, previous).await;
|
||||
if text == "/cancel" {
|
||||
if text.trim_end() == "/cancel" {
|
||||
dialogue.exit().await?;
|
||||
bot.send_message(msg.chat.id, "Successfully cancelled")
|
||||
.reply_markup(deletion_markup())
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
let handler = handler.ok_or(HandlerUsed)?;
|
||||
let handler = match handler {
|
||||
Some(handler) => handler,
|
||||
None => {
|
||||
let _ = dialogue.exit().await;
|
||||
return Err(HandlerUsed.into());
|
||||
}
|
||||
};
|
||||
match check(&bot, &msg, &db, &text).await {
|
||||
Ok(true) => (),
|
||||
Ok(false) => {
|
||||
@ -47,5 +52,9 @@ where
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
(handler.handler)(bot, msg, db, dialogue, text).await
|
||||
if let Err(err) = (handler.handler)(bot, msg, db, dialogue.clone(), text).await {
|
||||
let _ = dialogue.exit().await;
|
||||
return Err(err);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -14,17 +14,22 @@ pub async fn get_document(
|
||||
next: PackagedHandler<()>,
|
||||
) -> crate::Result<()> {
|
||||
let handler = next.lock().await.take();
|
||||
let previous = handler
|
||||
.as_ref()
|
||||
.and_then(|handler| handler.previous.as_ref());
|
||||
let previous = handler.as_ref().and_then(|h| h.previous.as_ref());
|
||||
delete_optional(&bot, previous).await;
|
||||
if let Some("/cancel") = msg.text().map(str::trim_end) {
|
||||
dialogue.exit().await?;
|
||||
bot.send_message(msg.chat.id, "Successfully cancelled")
|
||||
.reply_markup(deletion_markup())
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
let handler = handler.ok_or(HandlerUsed)?;
|
||||
let handler = match handler {
|
||||
Some(handler) => handler,
|
||||
None => {
|
||||
let _ = dialogue.exit().await;
|
||||
return Err(HandlerUsed.into());
|
||||
}
|
||||
};
|
||||
if msg.document().is_none() {
|
||||
bot.send_message(msg.chat.id, "You didn't send a file")
|
||||
.reply_markup(deletion_markup())
|
||||
@ -32,5 +37,9 @@ pub async fn get_document(
|
||||
dialogue.exit().await?;
|
||||
return Ok(());
|
||||
}
|
||||
(handler.handler)(bot, msg, db, dialogue, ()).await
|
||||
if let Err(err) = (handler.handler)(bot, msg, db, dialogue.clone(), ()).await {
|
||||
let _ = dialogue.exit().await;
|
||||
return Err(err);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user