34 lines
1.0 KiB
Rust
34 lines
1.0 KiB
Rust
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<H, F, T>(f: H, previous: impl Into<Option<Message>>) -> PackagedHandler<T>
|
|
where
|
|
H: FnOnce(Throttle<Bot>, Message, DatabaseConnection, MainDialogue, T) -> F
|
|
+ Send
|
|
+ Sync
|
|
+ 'static,
|
|
F: Future<Output = crate::Result<()>> + 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<Bot>, msg: Message) {
|
|
let _ = bot.delete_message(msg.chat.id, msg.id).await;
|
|
}
|
|
|
|
#[inline]
|
|
pub async fn delete_optional(bot: &Throttle<Bot>, msg: &Option<Message>) {
|
|
if let Some(msg) = msg {
|
|
let _ = bot.delete_message(msg.chat.id, msg.id).await;
|
|
}
|
|
}
|