use crate::handlers::{Handler, MainDialogue, PackagedHandler}; use sea_orm::prelude::*; use std::{future::Future, sync::Arc}; use teloxide::{adaptors::Throttle, prelude::*}; use tokio::sync::Mutex; #[inline] pub fn package_handler(f: H, previous: impl Into>) -> PackagedHandler where H: FnOnce(Throttle, Message, DatabaseConnection, MainDialogue, T) -> F + Send + Sync + 'static, F: Future> + Send + 'static, { Arc::new(Mutex::new(Some(Handler { handler: Box::new(move |bot, msg, db, dialogue, val| { Box::pin(f(bot, msg, db, dialogue, val)) }), previous: previous.into(), }))) } pub async fn delete_message(bot: Throttle, msg: Message) { let _ = bot.delete_message(msg.chat.id, msg.id).await; } #[inline] pub async fn delete_optional(bot: &Throttle, msg: &Option) { if let Some(msg) = msg { let _ = bot.delete_message(msg.chat.id, msg.id).await; } }