pass_manager/src/callbacks/delete_message.rs

26 lines
850 B
Rust

use crate::markups::deletion_markup;
use teloxide::{adaptors::Throttle, dispatching::DpHandlerDescription, prelude::*};
/// Deletes the message from the callback
async fn run(bot: Throttle<Bot>, q: CallbackQuery) -> crate::Result<()> {
if let Some(msg) = q.message {
if bot.delete_message(msg.chat.id, msg.id).await.is_err() {
bot.send_message(msg.chat.id, "Error deleting the message")
.reply_markup(deletion_markup())
.await?;
}
}
Ok(())
}
/// Filters the delete_message callbacks
fn filter(q: CallbackQuery) -> bool {
matches!(q.data.as_deref(), Some("delete_message"))
}
/// Gets a handler for deleting the message
#[inline]
pub fn get_handler() -> Handler<'static, DependencyMap, crate::Result<()>, DpHandlerDescription> {
dptree::filter(filter).endpoint(run)
}