Updated delete_message.rs to send a message if the deletion fails and added a function to just get a handler to chain with the schema
This commit is contained in:
parent
9365c75e6e
commit
8307bee4cf
@ -1,17 +1,26 @@
|
|||||||
use teloxide::{adaptors::Throttle, prelude::*};
|
use crate::handlers::markups::deletion_markup;
|
||||||
|
use teloxide::{adaptors::Throttle, dispatching::DpHandlerDescription, prelude::*};
|
||||||
|
|
||||||
/// Deletes the message from the callback
|
/// Deletes the message from the callback
|
||||||
pub async fn run(bot: Throttle<Bot>, q: CallbackQuery) -> crate::Result<()> {
|
async fn run(bot: Throttle<Bot>, q: CallbackQuery) -> crate::Result<()> {
|
||||||
match q.message {
|
if let Some(msg) = q.message {
|
||||||
Some(msg) => {
|
if let Err(err) = bot.delete_message(msg.chat.id, msg.id).await {
|
||||||
bot.delete_message(msg.chat.id, msg.id).await?;
|
let _ = bot
|
||||||
Ok(())
|
.send_message(msg.chat.id, "Error deleting the message")
|
||||||
|
.reply_markup(deletion_markup())
|
||||||
|
.await;
|
||||||
|
return Err(err.into());
|
||||||
}
|
}
|
||||||
None => Ok(()),
|
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Filters the delete_message callbacks
|
/// Filters the delete_message callbacks
|
||||||
pub fn filter(q: CallbackQuery) -> bool {
|
fn filter(q: CallbackQuery) -> bool {
|
||||||
matches!(q.data.as_deref(), Some("delete_message"))
|
matches!(q.data.as_deref(), Some("delete_message"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets a handler for deleting the message
|
||||||
|
pub fn get_handler() -> Handler<'static, DependencyMap, crate::Result<()>, DpHandlerDescription> {
|
||||||
|
dptree::filter(filter).endpoint(run)
|
||||||
|
}
|
||||||
|
@ -115,9 +115,8 @@ pub fn get_dispatcher(
|
|||||||
.branch(command_handler)
|
.branch(command_handler)
|
||||||
.branch(endpoint(commands::default));
|
.branch(endpoint(commands::default));
|
||||||
|
|
||||||
let callback_handler = Update::filter_callback_query()
|
let callback_handler =
|
||||||
.filter(callbacks::delete_message::filter)
|
Update::filter_callback_query().chain(callbacks::delete_message::get_handler());
|
||||||
.endpoint(callbacks::delete_message::run);
|
|
||||||
|
|
||||||
let handler = dptree::entry()
|
let handler = dptree::entry()
|
||||||
.branch(message_handler)
|
.branch(message_handler)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user