diff --git a/src/bots/approved_bot/modules/book.rs b/src/bots/approved_bot/modules/book.rs index 7639bb3..2911e52 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::*}; +use teloxide::{dispatching::UpdateFilterExt, dptree, prelude::*, adaptors::Throttle}; use crate::bots::approved_bot::{ services::{ @@ -114,7 +114,7 @@ impl GetPaginationCallbackData for BookCallbackData { async fn send_book_handler( message: Message, - bot: Bot, + bot: Throttle, 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: Bot, + bot: Throttle, 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: Bot, command: BookCommand| async move { + |message: Message, bot: Throttle, 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: Bot, callback_data: BookCallbackData| async move { + .endpoint(|cq: CallbackQuery, bot: Throttle, 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 1d2c402..a428bac 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::*}; +use teloxide::{dispatching::UpdateFilterExt, dptree, prelude::*, types::*, adaptors::Throttle}; use tokio_util::compat::FuturesAsyncReadCompatExt; use crate::{ @@ -47,7 +47,7 @@ impl CommandParse for DownloadData { async fn _send_cached( message: &Message, - bot: &Bot, + bot: &Throttle, cached_message: CachedMessage, ) -> BotHandlerInternal { match bot @@ -66,7 +66,7 @@ async fn _send_cached( async fn send_cached_message( message: Message, - bot: Bot, + bot: Throttle, 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: Bot, + bot: Throttle, 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: Bot, + bot: Throttle, 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: Bot, + bot: Throttle, 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: Bot, + bot: Throttle, 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 80044c6..dfbe88c 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}; +use teloxide::{prelude::*, utils::command::BotCommands, types::ParseMode, adaptors::Throttle}; #[derive(BotCommands, Clone)] #[command(rename_rule = "lowercase")] @@ -10,7 +10,7 @@ enum HelpCommand { } -pub async fn help_handler(message: Message, bot: Bot) -> BotHandlerInternal { +pub async fn help_handler(message: Message, bot: Throttle) -> 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 6b5769a..a801805 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, + utils::command::BotCommands, adaptors::Throttle, }; use crate::bots::{ @@ -75,7 +75,7 @@ impl std::str::FromStr for RandomCallbackData { } } -async fn random_handler(message: Message, bot: Bot) -> crate::bots::BotHandlerInternal { +async fn random_handler(message: Message, bot: Throttle) -> crate::bots::BotHandlerInternal { const MESSAGE_TEXT: &str = "Что хотим получить?"; let keyboard = InlineKeyboardMarkup { @@ -122,7 +122,7 @@ async fn random_handler(message: Message, bot: Bot) -> crate::bots::BotHandlerIn async fn get_random_item_handler_internal( cq: CallbackQuery, - bot: Bot, + bot: Throttle, item: Result>, ) -> BotHandlerInternal where @@ -176,7 +176,7 @@ where async fn get_random_item_handler( cq: CallbackQuery, - bot: Bot, + bot: Throttle, 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: Bot) -> BotHandlerInternal { +async fn get_genre_metas_handler(cq: CallbackQuery, bot: Throttle) -> 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: Bot) -> BotHandlerInter async fn get_genres_by_meta_handler( cq: CallbackQuery, - bot: Bot, + bot: Throttle, 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: Bot, + bot: Throttle, 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: Bot| async move { + .endpoint(|cq: CallbackQuery, callback_data: RandomCallbackData, bot: Throttle| 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 93fcf08..8654cb3 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, + types::{InlineKeyboardButton, InlineKeyboardMarkup}, dispatching::dialogue::GetChatId, adaptors::Throttle, }; use crate::bots::{ @@ -107,7 +107,7 @@ fn get_query(cq: CallbackQuery) -> Option { async fn generic_search_pagination_handler( cq: CallbackQuery, - bot: Bot, + bot: Throttle, 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: Bot) -> BotHandlerInternal { +pub async fn message_handler(message: Message, bot: Throttle) -> 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: Bot| async move { + .endpoint(|cq: CallbackQuery, callback_data: SearchCallbackData, bot: Throttle| 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 fcdad73..0f6510b 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, + utils::command::BotCommands, adaptors::Throttle, }; #[derive(BotCommands, Clone)] @@ -67,7 +67,7 @@ impl ToString for SettingsCallbackData { } } -async fn settings_handler(message: Message, bot: Bot) -> BotHandlerInternal { +async fn settings_handler(message: Message, bot: Throttle) -> 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: Bot, + bot: Throttle, 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: Bot, + bot: Throttle, 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 6461735..fb69d0d 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, + utils::command::BotCommands, adaptors::Throttle, }; #[derive(BotCommands, Clone)]