27 lines
865 B
Rust
27 lines
865 B
Rust
use crate::prelude::*;
|
|
use teloxide::{dispatching::DpHandlerDescription, dptree::Handler};
|
|
|
|
/// 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?;
|
|
}
|
|
}
|
|
bot.answer_callback_query(q.id).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)
|
|
}
|