diff --git a/src/bots/approved_bot/modules/annotations.rs b/src/bots/approved_bot/modules/annotations.rs index 1fccfe4..0fdca2a 100644 --- a/src/bots/approved_bot/modules/annotations.rs +++ b/src/bots/approved_bot/modules/annotations.rs @@ -2,7 +2,7 @@ use std::{convert::TryInto, str::FromStr}; use futures::TryStreamExt; use regex::Regex; -use teloxide::{dispatching::UpdateFilterExt, dptree, prelude::*, types::*, adaptors::Throttle}; +use teloxide::{dispatching::UpdateFilterExt, dptree, prelude::*, types::*, adaptors::{Throttle, CacheMe}}; use tokio_util::compat::FuturesAsyncReadCompatExt; use crate::bots::{ @@ -162,7 +162,7 @@ async fn download_image( pub async fn send_annotation_handler( message: Message, - bot: Throttle, + bot: CacheMe>, command: AnnotationCommand, annotation_getter: fn(id: u32) -> Fut, ) -> BotHandlerInternal @@ -248,7 +248,7 @@ where pub async fn annotation_pagination_handler( cq: CallbackQuery, - bot: Throttle, + bot: CacheMe>, callback_data: AnnotationCallbackData, annotation_getter: fn(id: u32) -> Fut, ) -> BotHandlerInternal @@ -308,7 +308,7 @@ pub fn get_annotations_handler() -> crate::bots::BotHandler { Update::filter_message() .chain(filter_command::()) .endpoint( - |message: Message, bot: Throttle, command: AnnotationCommand| async move { + |message: Message, bot: CacheMe>, command: AnnotationCommand| async move { match command { AnnotationCommand::Book { .. } => { send_annotation_handler(message, bot, command, get_book_annotation) @@ -332,7 +332,7 @@ pub fn get_annotations_handler() -> crate::bots::BotHandler { .chain(filter_callback_query::()) .endpoint( |cq: CallbackQuery, - bot: Throttle, + bot: CacheMe>, callback_data: AnnotationCallbackData| async move { match callback_data { AnnotationCallbackData::Book { .. } => { diff --git a/src/bots/approved_bot/modules/book.rs b/src/bots/approved_bot/modules/book.rs index 2911e52..e9b3c69 100644 --- a/src/bots/approved_bot/modules/book.rs +++ b/src/bots/approved_bot/modules/book.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use regex::Regex; -use teloxide::{dispatching::UpdateFilterExt, dptree, prelude::*, adaptors::Throttle}; +use teloxide::{dispatching::UpdateFilterExt, dptree, prelude::*, adaptors::{Throttle, CacheMe}}; use crate::bots::approved_bot::{ services::{ @@ -114,7 +114,7 @@ impl GetPaginationCallbackData for BookCallbackData { async fn send_book_handler( message: Message, - bot: Throttle, + bot: CacheMe>, command: BookCommand, books_getter: fn(id: u32, page: u32, allowed_langs: Vec) -> Fut, ) -> crate::bots::BotHandlerInternal @@ -196,7 +196,7 @@ where async fn send_pagination_book_handler( cq: CallbackQuery, - bot: Throttle, + bot: CacheMe>, callback_data: BookCallbackData, books_getter: fn(id: u32, page: u32, allowed_langs: Vec) -> Fut, ) -> crate::bots::BotHandlerInternal @@ -295,7 +295,7 @@ pub fn get_book_handler() -> crate::bots::BotHandler { Update::filter_message() .chain(filter_command::()) .endpoint( - |message: Message, bot: Throttle, command: BookCommand| async move { + |message: Message, bot: CacheMe>, command: BookCommand| async move { match command { BookCommand::Author { .. } => { send_book_handler( @@ -331,7 +331,7 @@ pub fn get_book_handler() -> crate::bots::BotHandler { .branch( Update::filter_callback_query() .chain(filter_callback_query::()) - .endpoint(|cq: CallbackQuery, bot: Throttle, callback_data: BookCallbackData| async move { + .endpoint(|cq: CallbackQuery, bot: CacheMe>, callback_data: BookCallbackData| async move { match callback_data { BookCallbackData::Author { .. } => send_pagination_book_handler(cq, bot, callback_data, get_author_books).await, BookCallbackData::Translator { .. } => send_pagination_book_handler(cq, bot, callback_data, get_translator_books).await, diff --git a/src/bots/approved_bot/modules/download.rs b/src/bots/approved_bot/modules/download.rs index a428bac..acb6bb3 100644 --- a/src/bots/approved_bot/modules/download.rs +++ b/src/bots/approved_bot/modules/download.rs @@ -1,6 +1,6 @@ use futures::TryStreamExt; use regex::Regex; -use teloxide::{dispatching::UpdateFilterExt, dptree, prelude::*, types::*, adaptors::Throttle}; +use teloxide::{dispatching::UpdateFilterExt, dptree, prelude::*, types::*, adaptors::{Throttle, CacheMe}}; use tokio_util::compat::FuturesAsyncReadCompatExt; use crate::{ @@ -47,7 +47,7 @@ impl CommandParse for DownloadData { async fn _send_cached( message: &Message, - bot: &Throttle, + bot: &CacheMe>, cached_message: CachedMessage, ) -> BotHandlerInternal { match bot @@ -66,7 +66,7 @@ async fn _send_cached( async fn send_cached_message( message: Message, - bot: Throttle, + bot: CacheMe>, download_data: DownloadData, ) -> BotHandlerInternal { if let Ok(v) = get_cached_message(&download_data).await { @@ -83,7 +83,7 @@ async fn send_cached_message( async fn _send_downloaded_file( message: &Message, - bot: Throttle, + bot: CacheMe>, downloaded_data: DownloadFile, ) -> BotHandlerInternal { let DownloadFile { @@ -113,7 +113,7 @@ async fn _send_downloaded_file( async fn send_with_download_from_channel( message: Message, - bot: Throttle, + bot: CacheMe>, download_data: DownloadData, ) -> BotHandlerInternal { match download_file(&download_data).await { @@ -127,7 +127,7 @@ async fn send_with_download_from_channel( async fn download_handler( message: Message, - bot: Throttle, + bot: CacheMe>, cache: BotCache, download_data: DownloadData, ) -> BotHandlerInternal { @@ -143,7 +143,7 @@ pub fn get_download_hander() -> crate::bots::BotHandler { .chain(filter_command::()) .endpoint( |message: Message, - bot: Throttle, + bot: CacheMe>, cache: BotCache, download_data: DownloadData| async move { download_handler(message, bot, cache, download_data).await diff --git a/src/bots/approved_bot/modules/help.rs b/src/bots/approved_bot/modules/help.rs index dfbe88c..be9a858 100644 --- a/src/bots/approved_bot/modules/help.rs +++ b/src/bots/approved_bot/modules/help.rs @@ -1,6 +1,6 @@ use crate::bots::BotHandlerInternal; -use teloxide::{prelude::*, utils::command::BotCommands, types::ParseMode, adaptors::Throttle}; +use teloxide::{prelude::*, utils::command::BotCommands, types::ParseMode, adaptors::{Throttle, CacheMe}}; #[derive(BotCommands, Clone)] #[command(rename_rule = "lowercase")] @@ -10,7 +10,7 @@ enum HelpCommand { } -pub async fn help_handler(message: Message, bot: Throttle) -> BotHandlerInternal { +pub async fn help_handler(message: Message, bot: CacheMe>) -> BotHandlerInternal { let name = message .from() .map(|user| user.first_name.clone()) diff --git a/src/bots/approved_bot/modules/random.rs b/src/bots/approved_bot/modules/random.rs index a801805..5f3e15f 100644 --- a/src/bots/approved_bot/modules/random.rs +++ b/src/bots/approved_bot/modules/random.rs @@ -2,7 +2,7 @@ use strum_macros::{Display, EnumIter}; use teloxide::{ prelude::*, types::{InlineKeyboardButton, InlineKeyboardMarkup}, - utils::command::BotCommands, adaptors::Throttle, + utils::command::BotCommands, adaptors::{Throttle, CacheMe}, }; use crate::bots::{ @@ -75,7 +75,7 @@ impl std::str::FromStr for RandomCallbackData { } } -async fn random_handler(message: Message, bot: Throttle) -> crate::bots::BotHandlerInternal { +async fn random_handler(message: Message, bot: CacheMe>) -> crate::bots::BotHandlerInternal { const MESSAGE_TEXT: &str = "Что хотим получить?"; let keyboard = InlineKeyboardMarkup { @@ -122,7 +122,7 @@ async fn random_handler(message: Message, bot: Throttle) -> crate::bots::Bo async fn get_random_item_handler_internal( cq: CallbackQuery, - bot: Throttle, + bot: CacheMe>, item: Result>, ) -> BotHandlerInternal where @@ -176,7 +176,7 @@ where async fn get_random_item_handler( cq: CallbackQuery, - bot: Throttle, + bot: CacheMe>, item_getter: fn(allowed_langs: Vec) -> Fut, ) -> BotHandlerInternal where @@ -190,7 +190,7 @@ where get_random_item_handler_internal(cq, bot, item).await } -async fn get_genre_metas_handler(cq: CallbackQuery, bot: Throttle) -> BotHandlerInternal { +async fn get_genre_metas_handler(cq: CallbackQuery, bot: CacheMe>) -> BotHandlerInternal { let genre_metas = match book_library::get_genre_metas().await { Ok(v) => v, Err(err) => return Err(err), @@ -243,7 +243,7 @@ async fn get_genre_metas_handler(cq: CallbackQuery, bot: Throttle) -> BotHa async fn get_genres_by_meta_handler( cq: CallbackQuery, - bot: Throttle, + bot: CacheMe>, genre_index: u32, ) -> BotHandlerInternal { let genre_metas = match book_library::get_genre_metas().await { @@ -323,7 +323,7 @@ async fn get_genres_by_meta_handler( async fn get_random_book_by_genre( cq: CallbackQuery, - bot: Throttle, + bot: CacheMe>, genre_id: u32, ) -> BotHandlerInternal { let allowed_langs = get_user_or_default_lang_codes(cq.from.id).await; @@ -350,7 +350,7 @@ pub fn get_random_hander() -> crate::bots::BotHandler { .branch( Update::filter_callback_query() .chain(filter_callback_query::()) - .endpoint(|cq: CallbackQuery, callback_data: RandomCallbackData, bot: Throttle| async move { + .endpoint(|cq: CallbackQuery, callback_data: RandomCallbackData, bot: CacheMe>| async move { match callback_data { RandomCallbackData::RandomBook => get_random_item_handler(cq, bot, book_library::get_random_book).await, RandomCallbackData::RandomAuthor => get_random_item_handler(cq, bot, book_library::get_random_author).await, diff --git a/src/bots/approved_bot/modules/search.rs b/src/bots/approved_bot/modules/search.rs index 8654cb3..2e9ca9b 100644 --- a/src/bots/approved_bot/modules/search.rs +++ b/src/bots/approved_bot/modules/search.rs @@ -4,7 +4,7 @@ use regex::Regex; use strum_macros::EnumIter; use teloxide::{ prelude::*, - types::{InlineKeyboardButton, InlineKeyboardMarkup}, dispatching::dialogue::GetChatId, adaptors::Throttle, + types::{InlineKeyboardButton, InlineKeyboardMarkup}, dispatching::dialogue::GetChatId, adaptors::{Throttle, CacheMe}, }; use crate::bots::{ @@ -107,7 +107,7 @@ fn get_query(cq: CallbackQuery) -> Option { async fn generic_search_pagination_handler( cq: CallbackQuery, - bot: Throttle, + bot: CacheMe>, search_data: SearchCallbackData, items_getter: fn(query: String, page: u32, allowed_langs: Vec) -> Fut, ) -> BotHandlerInternal @@ -217,7 +217,7 @@ where } } -pub async fn message_handler(message: Message, bot: Throttle) -> BotHandlerInternal { +pub async fn message_handler(message: Message, bot: CacheMe>) -> BotHandlerInternal { let message_text = "Что ищем?"; let keyboard = InlineKeyboardMarkup { @@ -268,7 +268,7 @@ pub fn get_search_handler() -> crate::bots::BotHandler { ).branch( Update::filter_callback_query() .chain(filter_callback_query::()) - .endpoint(|cq: CallbackQuery, callback_data: SearchCallbackData, bot: Throttle| async move { + .endpoint(|cq: CallbackQuery, callback_data: SearchCallbackData, bot: CacheMe>| async move { match callback_data { SearchCallbackData::SearchBook { .. } => generic_search_pagination_handler(cq, bot, callback_data, search_book).await, SearchCallbackData::SearchAuthors { .. } => generic_search_pagination_handler(cq, bot, callback_data, search_author).await, diff --git a/src/bots/approved_bot/modules/settings.rs b/src/bots/approved_bot/modules/settings.rs index 0f6510b..f635e6c 100644 --- a/src/bots/approved_bot/modules/settings.rs +++ b/src/bots/approved_bot/modules/settings.rs @@ -14,7 +14,7 @@ use regex::Regex; use teloxide::{ prelude::*, types::{InlineKeyboardButton, InlineKeyboardMarkup, Me}, - utils::command::BotCommands, adaptors::Throttle, + utils::command::BotCommands, adaptors::{Throttle, CacheMe}, }; #[derive(BotCommands, Clone)] @@ -67,7 +67,7 @@ impl ToString for SettingsCallbackData { } } -async fn settings_handler(message: Message, bot: Throttle) -> BotHandlerInternal { +async fn settings_handler(message: Message, bot: CacheMe>) -> BotHandlerInternal { let keyboard = InlineKeyboardMarkup { inline_keyboard: vec![vec![InlineKeyboardButton { text: "Языки".to_string(), @@ -117,7 +117,7 @@ fn get_lang_keyboard(all_langs: Vec, allowed_langs: HashSet) -> In async fn settings_callback_handler( cq: CallbackQuery, - bot: Throttle, + bot: CacheMe>, callback_data: SettingsCallbackData, me: Me, ) -> BotHandlerInternal { @@ -219,7 +219,7 @@ pub fn get_settings_handler() -> crate::bots::BotHandler { .chain(filter_callback_query::()) .endpoint( |cq: CallbackQuery, - bot: Throttle, + bot: CacheMe>, callback_data: SettingsCallbackData, me: Me| async move { settings_callback_handler(cq, bot, callback_data, me).await diff --git a/src/bots/approved_bot/modules/support.rs b/src/bots/approved_bot/modules/support.rs index fb69d0d..d7d0a0b 100644 --- a/src/bots/approved_bot/modules/support.rs +++ b/src/bots/approved_bot/modules/support.rs @@ -3,7 +3,7 @@ use crate::bots::BotHandlerInternal; use teloxide::{ prelude::*, types::{InlineKeyboardButton, InlineKeyboardMarkup}, - utils::command::BotCommands, adaptors::Throttle, + utils::command::BotCommands, adaptors::{Throttle, CacheMe}, }; #[derive(BotCommands, Clone)] @@ -12,7 +12,7 @@ enum SupportCommand { Support, } -pub async fn support_command_handler(message: Message, bot: Throttle) -> BotHandlerInternal { +pub async fn support_command_handler(message: Message, bot: CacheMe>) -> BotHandlerInternal { const MESSAGE_TEXT: &str = " [Лицензии](https://github.com/flibusta-apps/book_bot/blob/main/LICENSE.md) diff --git a/src/bots/approved_bot/modules/update_history.rs b/src/bots/approved_bot/modules/update_history.rs index 4cd1e90..b126c49 100644 --- a/src/bots/approved_bot/modules/update_history.rs +++ b/src/bots/approved_bot/modules/update_history.rs @@ -12,7 +12,7 @@ use regex::Regex; use teloxide::{ prelude::*, types::{InlineKeyboardButton, InlineKeyboardMarkup}, - utils::command::BotCommands, adaptors::Throttle, + utils::command::BotCommands, adaptors::{Throttle, CacheMe}, }; use super::utils::{generic_get_pagination_keyboard, GetPaginationCallbackData}; @@ -77,7 +77,7 @@ impl GetPaginationCallbackData for UpdateLogCallbackData { } } -async fn update_log_command(message: Message, bot: Throttle) -> BotHandlerInternal { +async fn update_log_command(message: Message, bot: CacheMe>) -> BotHandlerInternal { let now = Utc::now().date_naive(); let d3 = now - Duration::days(3); let d7 = now - Duration::days(7); @@ -134,7 +134,7 @@ async fn update_log_command(message: Message, bot: Throttle) -> BotHandlerI async fn update_log_pagination_handler( cq: CallbackQuery, - bot: Throttle, + bot: CacheMe>, update_callback_data: UpdateLogCallbackData, ) -> BotHandlerInternal { let message = match cq.message { @@ -223,7 +223,7 @@ pub fn get_update_log_handler() -> crate::bots::BotHandler { .chain(filter_callback_query::()) .endpoint( |cq: CallbackQuery, - bot: Throttle, + bot: CacheMe>, update_log_data: UpdateLogCallbackData| async move { update_log_pagination_handler(cq, bot, update_log_data).await }, diff --git a/src/bots/bots_manager/mod.rs b/src/bots/bots_manager/mod.rs index 6f6090a..7148294 100644 --- a/src/bots/bots_manager/mod.rs +++ b/src/bots/bots_manager/mod.rs @@ -1,4 +1,4 @@ -use teloxide::{prelude::*, adaptors::Throttle}; +use teloxide::{prelude::*, adaptors::{Throttle, CacheMe}}; use std::error::Error; @@ -10,7 +10,7 @@ pub mod utils; pub async fn message_handler( message: Message, - bot: Throttle, + bot: CacheMe>, ) -> Result<(), Box> { let from_user = message.from().unwrap(); let text = message.text().unwrap_or(""); diff --git a/src/bots/mod.rs b/src/bots/mod.rs index 9ecb82f..0e7faa9 100644 --- a/src/bots/mod.rs +++ b/src/bots/mod.rs @@ -3,7 +3,7 @@ pub mod bots_manager; use std::error::Error; -use teloxide::{prelude::*, adaptors::Throttle}; +use teloxide::{prelude::*, adaptors::{Throttle, CacheMe}}; pub type BotHandlerInternal = Result<(), Box>; @@ -27,7 +27,7 @@ fn ignore_chat_member_update() -> crate::bots::BotHandler { } fn get_pending_handler() -> BotHandler { - let handler = |msg: Message, bot: Throttle| async move { + let handler = |msg: Message, bot: CacheMe>| async move { let message_text = " Бот зарегистрирован, но не подтвержден администратором! \ Подтверждение занимает примерно 12 часов. @@ -44,7 +44,7 @@ fn get_pending_handler() -> BotHandler { } fn get_blocked_handler() -> BotHandler { - let handler = |msg: Message, bot: Throttle| async move { + let handler = |msg: Message, bot: CacheMe>| async move { let message_text = "Бот заблокирован!"; bot.send_message(msg.chat.id, message_text).await?;