From 3802ac0c1f5bf6d2363bcfec7c6ca4a0df7a3e15 Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Sat, 6 May 2023 23:07:09 +0200 Subject: [PATCH] Fix --- src/bots/approved_bot/modules/support.rs | 2 +- src/bots/approved_bot/modules/update_history.rs | 8 ++++---- src/bots/bots_manager/mod.rs | 4 ++-- src/bots/mod.rs | 6 +++--- src/bots_manager.rs | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/bots/approved_bot/modules/support.rs b/src/bots/approved_bot/modules/support.rs index b5ae485..6461735 100644 --- a/src/bots/approved_bot/modules/support.rs +++ b/src/bots/approved_bot/modules/support.rs @@ -12,7 +12,7 @@ enum SupportCommand { Support, } -pub async fn support_command_handler(message: Message, bot: Bot) -> BotHandlerInternal { +pub async fn support_command_handler(message: Message, bot: Throttle) -> 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 ba7d007..4cd1e90 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, + utils::command::BotCommands, adaptors::Throttle, }; use super::utils::{generic_get_pagination_keyboard, GetPaginationCallbackData}; @@ -77,7 +77,7 @@ impl GetPaginationCallbackData for UpdateLogCallbackData { } } -async fn update_log_command(message: Message, bot: Bot) -> BotHandlerInternal { +async fn update_log_command(message: Message, bot: Throttle) -> 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: Bot) -> BotHandlerInternal { async fn update_log_pagination_handler( cq: CallbackQuery, - bot: Bot, + bot: Throttle, 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: Bot, + bot: Throttle, 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 9b8b80e..6f6090a 100644 --- a/src/bots/bots_manager/mod.rs +++ b/src/bots/bots_manager/mod.rs @@ -1,4 +1,4 @@ -use teloxide::prelude::*; +use teloxide::{prelude::*, adaptors::Throttle}; use std::error::Error; @@ -10,7 +10,7 @@ pub mod utils; pub async fn message_handler( message: Message, - bot: Bot, + bot: Throttle, ) -> 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 3f8bc80..9ecb82f 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::*; +use teloxide::{prelude::*, adaptors::Throttle}; 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: Bot| async move { + let handler = |msg: Message, bot: Throttle| 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: Bot| async move { + let handler = |msg: Message, bot: Throttle| 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 19cbc95..44e54bd 100644 --- a/src/bots_manager.rs +++ b/src/bots_manager.rs @@ -76,9 +76,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()) - // .throttle(Limits::default()); + .throttle(Limits::default()); - let token = bot.token(); + let token = bot.inner().token(); let port = self.bot_port_map .get(&bot_data.id) .unwrap_or_else(|| panic!("Can't get bot port!"));