diff --git a/Cargo.lock b/Cargo.lock index 404e5c0..cf0738a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -48,9 +48,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.70" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" +checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" [[package]] name = "aquamarine" @@ -95,9 +95,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "axum" -version = "0.5.17" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acee9fd5073ab6b045a275b3e709c163dd36c90685219cb21804a147b58dba43" +checksum = "f8175979259124331c1d7bf6586ee7e0da434155e4b2d48ec2c8386281d8df39" dependencies = [ "async-trait", "axum-core", @@ -113,22 +113,23 @@ dependencies = [ "mime", "percent-encoding", "pin-project-lite", + "rustversion", "serde", "serde_json", + "serde_path_to_error", "serde_urlencoded", "sync_wrapper", "tokio", "tower", - "tower-http", "tower-layer", "tower-service", ] [[package]] name = "axum-core" -version = "0.2.9" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e5939e02c56fecd5c017c37df4238c0a839fa76b7f97acdd7efb804fd181cc" +checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" dependencies = [ "async-trait", "bytes", @@ -136,6 +137,7 @@ dependencies = [ "http", "http-body", "mime", + "rustversion", "tower-layer", "tower-service", ] @@ -912,9 +914,9 @@ checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" [[package]] name = "matchit" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" +checksum = "b87248edafb776e59e6ee64a79086f65890d3510f2c656c000bf2a7e8a0aea40" [[package]] name = "memchr" @@ -1123,9 +1125,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "ppv-lite86" @@ -1313,9 +1315,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.17" +version = "0.37.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc809f704c03a812ac71f22456c857be34185cac691a4316f27ab0f633bb9009" +checksum = "8bbfc1d1c7c40c01715f47d71444744a81669ca84e8b63e25a55e169b1f86433" dependencies = [ "bitflags", "errno", @@ -1498,6 +1500,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7f05c1d5476066defcdfacce1f52fc3cae3af1d3089727100c02ae92e5abbe0" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -1629,9 +1640,9 @@ checksum = "20f34339676cdcab560c9a82300c4c2581f68b9369aedf0fae86f2ff9565ff3e" [[package]] name = "teloxide" -version = "0.10.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91471f2d0f91b079b1b71dc689daac4748ded26a32c1cf0c6fc4130490c8f64e" +checksum = "c63345cf32a8850ebddcdd769dc2d5193d5e231262d5dada264b79da01a664da" dependencies = [ "aquamarine", "axum", @@ -1659,9 +1670,9 @@ dependencies = [ [[package]] name = "teloxide-core" -version = "0.7.1" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20608e89a267b68f3ac6e05228c89ebf455d6085388dd57250e3a00f1806e4e9" +checksum = "303db260110c238e3af77bb9dff18bf7a5b5196f783059b0852aab75f91d5a16" dependencies = [ "bitflags", "bytes", @@ -1690,9 +1701,9 @@ dependencies = [ [[package]] name = "teloxide-macros" -version = "0.6.3" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60d1f9fc42b44919d45dfcf8992d12e3df2a0d109431d2a15110d76fd3701a19" +checksum = "0f1d653b093dba5e44cada57a516f572167df37b8a619443e59c8c517bb6d804" dependencies = [ "heck", "proc-macro2", @@ -1901,7 +1912,6 @@ dependencies = [ "http-body", "http-range-header", "pin-project-lite", - "tower", "tower-layer", "tower-service", "tracing", diff --git a/Cargo.toml b/Cargo.toml index 052a265..ed384cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ serde = { version = "1.0.144", features = ["derive"] } serde_json = "1.0.85" log = "0.4" pretty_env_logger = "0.4" -teloxide = { version = "0.10.1", features = ["macros", "auto-send", "webhooks-axum"] } +teloxide = { version = "0.12.2", features = ["macros", "webhooks-axum"] } url = "2.2.2" ctrlc = { version = "3.2.3", features = ["termination"] } strum = "0.24" diff --git a/src/bots/approved_bot/modules/annotations.rs b/src/bots/approved_bot/modules/annotations.rs index 8bca59e..57976a4 100644 --- a/src/bots/approved_bot/modules/annotations.rs +++ b/src/bots/approved_bot/modules/annotations.rs @@ -162,7 +162,7 @@ async fn download_image( pub async fn send_annotation_handler( message: Message, - bot: AutoSend, + bot: Bot, command: AnnotationCommand, annotation_getter: fn(id: u32) -> Fut, ) -> BotHandlerInternal @@ -248,7 +248,7 @@ where pub async fn annotation_pagination_handler( cq: CallbackQuery, - bot: AutoSend, + bot: Bot, 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: AutoSend, command: AnnotationCommand| async move { + |message: Message, bot: Bot, 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: AutoSend, + bot: Bot, 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 423c432..7639bb3 100644 --- a/src/bots/approved_bot/modules/book.rs +++ b/src/bots/approved_bot/modules/book.rs @@ -114,7 +114,7 @@ impl GetPaginationCallbackData for BookCallbackData { async fn send_book_handler( message: Message, - bot: AutoSend, + bot: Bot, 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: AutoSend, + bot: Bot, 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: AutoSend, command: BookCommand| async move { + |message: Message, bot: Bot, 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: AutoSend, callback_data: BookCallbackData| async move { + .endpoint(|cq: CallbackQuery, bot: Bot, 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 1f01d03..1d2c402 100644 --- a/src/bots/approved_bot/modules/download.rs +++ b/src/bots/approved_bot/modules/download.rs @@ -47,14 +47,14 @@ impl CommandParse for DownloadData { async fn _send_cached( message: &Message, - bot: &AutoSend, + bot: &Bot, cached_message: CachedMessage, ) -> BotHandlerInternal { match bot .copy_message( message.chat.id, Recipient::Id(ChatId(cached_message.data.chat_id)), - cached_message.data.message_id, + MessageId(cached_message.data.message_id), ) .send() .await @@ -66,7 +66,7 @@ async fn _send_cached( async fn send_cached_message( message: Message, - bot: AutoSend, + bot: Bot, 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: &AutoSend, + bot: Bot, downloaded_data: DownloadFile, ) -> BotHandlerInternal { let DownloadFile { @@ -113,11 +113,11 @@ async fn _send_downloaded_file( async fn send_with_download_from_channel( message: Message, - bot: AutoSend, + bot: Bot, download_data: DownloadData, ) -> BotHandlerInternal { match download_file(&download_data).await { - Ok(v) => match _send_downloaded_file(&message, &bot, v).await { + Ok(v) => match _send_downloaded_file(&message, bot, v).await { Ok(v_2) => Ok(v_2), Err(err) => Err(err), }, @@ -127,7 +127,7 @@ async fn send_with_download_from_channel( async fn download_handler( message: Message, - bot: AutoSend, + bot: Bot, 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: AutoSend, + bot: Bot, 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 e347dd4..80044c6 100644 --- a/src/bots/approved_bot/modules/help.rs +++ b/src/bots/approved_bot/modules/help.rs @@ -3,13 +3,14 @@ use crate::bots::BotHandlerInternal; use teloxide::{prelude::*, utils::command::BotCommands, types::ParseMode}; #[derive(BotCommands, Clone)] -#[command(rename = "lowercase")] +#[command(rename_rule = "lowercase")] enum HelpCommand { Start, Help, } -pub async fn help_handler(message: Message, bot: AutoSend) -> BotHandlerInternal { + +pub async fn help_handler(message: Message, bot: Bot) -> 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 9bb2702..6b5769a 100644 --- a/src/bots/approved_bot/modules/random.rs +++ b/src/bots/approved_bot/modules/random.rs @@ -17,7 +17,7 @@ use crate::bots::{ }; #[derive(BotCommands, Clone)] -#[command(rename = "lowercase")] +#[command(rename_rule = "lowercase")] enum RandomCommand { Random, } @@ -75,7 +75,7 @@ impl std::str::FromStr for RandomCallbackData { } } -async fn random_handler(message: Message, bot: AutoSend) -> crate::bots::BotHandlerInternal { +async fn random_handler(message: Message, bot: Bot) -> crate::bots::BotHandlerInternal { const MESSAGE_TEXT: &str = "Что хотим получить?"; let keyboard = InlineKeyboardMarkup { @@ -122,7 +122,7 @@ async fn random_handler(message: Message, bot: AutoSend) -> crate::bots::Bo async fn get_random_item_handler_internal( cq: CallbackQuery, - bot: AutoSend, + bot: Bot, item: Result>, ) -> BotHandlerInternal where @@ -176,7 +176,7 @@ where async fn get_random_item_handler( cq: CallbackQuery, - bot: AutoSend, + bot: Bot, 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: AutoSend) -> BotHandlerInternal { +async fn get_genre_metas_handler(cq: CallbackQuery, bot: Bot) -> 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: AutoSend) -> BotHa async fn get_genres_by_meta_handler( cq: CallbackQuery, - bot: AutoSend, + bot: Bot, 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: AutoSend, + bot: Bot, 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: AutoSend| async move { + .endpoint(|cq: CallbackQuery, callback_data: RandomCallbackData, bot: Bot| 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 4f2b679..93fcf08 100644 --- a/src/bots/approved_bot/modules/search.rs +++ b/src/bots/approved_bot/modules/search.rs @@ -107,7 +107,7 @@ fn get_query(cq: CallbackQuery) -> Option { async fn generic_search_pagination_handler( cq: CallbackQuery, - bot: AutoSend, + bot: Bot, 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: AutoSend) -> BotHandlerInternal { +pub async fn message_handler(message: Message, bot: Bot) -> 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: AutoSend| async move { + .endpoint(|cq: CallbackQuery, callback_data: SearchCallbackData, bot: Bot| 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 3387d0c..fcdad73 100644 --- a/src/bots/approved_bot/modules/settings.rs +++ b/src/bots/approved_bot/modules/settings.rs @@ -18,7 +18,7 @@ use teloxide::{ }; #[derive(BotCommands, Clone)] -#[command(rename = "lowercase")] +#[command(rename_rule = "lowercase")] enum SettingsCommand { Settings, } @@ -67,7 +67,7 @@ impl ToString for SettingsCallbackData { } } -async fn settings_handler(message: Message, bot: AutoSend) -> BotHandlerInternal { +async fn settings_handler(message: Message, bot: Bot) -> 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: AutoSend, + bot: Bot, 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: AutoSend, + bot: Bot, 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 cbf56f4..b5ae485 100644 --- a/src/bots/approved_bot/modules/support.rs +++ b/src/bots/approved_bot/modules/support.rs @@ -7,12 +7,12 @@ use teloxide::{ }; #[derive(BotCommands, Clone)] -#[command(rename = "lowercase")] +#[command(rename_rule = "lowercase")] enum SupportCommand { Support, } -pub async fn support_command_handler(message: Message, bot: AutoSend) -> BotHandlerInternal { +pub async fn support_command_handler(message: Message, bot: Bot) -> 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 3278035..ba7d007 100644 --- a/src/bots/approved_bot/modules/update_history.rs +++ b/src/bots/approved_bot/modules/update_history.rs @@ -18,7 +18,7 @@ use teloxide::{ use super::utils::{generic_get_pagination_keyboard, GetPaginationCallbackData}; #[derive(BotCommands, Clone)] -#[command(rename = "snake_case")] +#[command(rename_rule = "snake_case")] enum UpdateLogCommand { UpdateLog, } @@ -77,7 +77,7 @@ impl GetPaginationCallbackData for UpdateLogCallbackData { } } -async fn update_log_command(message: Message, bot: AutoSend) -> BotHandlerInternal { +async fn update_log_command(message: Message, bot: Bot) -> 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: AutoSend) -> BotHandlerI async fn update_log_pagination_handler( cq: CallbackQuery, - bot: AutoSend, + bot: Bot, 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: AutoSend, + bot: Bot, 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 fa92f36..9b8b80e 100644 --- a/src/bots/bots_manager/mod.rs +++ b/src/bots/bots_manager/mod.rs @@ -10,7 +10,7 @@ pub mod utils; pub async fn message_handler( message: Message, - bot: AutoSend, + bot: Bot, ) -> 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 ec6eb8a..3f8bc80 100644 --- a/src/bots/mod.rs +++ b/src/bots/mod.rs @@ -27,7 +27,7 @@ fn ignore_chat_member_update() -> crate::bots::BotHandler { } fn get_pending_handler() -> BotHandler { - let handler = |msg: Message, bot: AutoSend| async move { + let handler = |msg: Message, bot: Bot| 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: AutoSend| async move { + let handler = |msg: Message, bot: Bot| async move { let message_text = "Бот заблокирован!"; bot.send_message(msg.chat.id, message_text).await?; diff --git a/src/bots_manager.rs b/src/bots_manager.rs index 8970e88..05cc5bf 100644 --- a/src/bots_manager.rs +++ b/src/bots_manager.rs @@ -74,10 +74,9 @@ impl BotsManager { async fn start_bot(&mut self, bot_data: &BotData) -> bool { let bot = Bot::new(bot_data.token.clone()) - .set_api_url(config::CONFIG.telegram_bot_api.clone()) - .auto_send(); + .set_api_url(config::CONFIG.telegram_bot_api.clone()); - let token = bot.inner().token(); + let token = bot.token(); let port = self.bot_port_map .get(&bot_data.id) .unwrap_or_else(|| panic!("Can't get bot port!")); @@ -219,7 +218,7 @@ impl BotsManager { manager.check().await; for _ in 1..30 { - sleep(Duration::from_secs(1)).await; + sleep(Duration::from_millis(50)).await; if !running.load(Ordering::SeqCst) { manager.stop_all().await;