This commit is contained in:
2023-05-06 23:07:09 +02:00
parent cc7165eadd
commit 3802ac0c1f
5 changed files with 12 additions and 12 deletions

View File

@@ -12,7 +12,7 @@ enum SupportCommand {
Support, Support,
} }
pub async fn support_command_handler(message: Message, bot: Bot) -> BotHandlerInternal { pub async fn support_command_handler(message: Message, bot: Throttle<Bot>) -> BotHandlerInternal {
const MESSAGE_TEXT: &str = " const MESSAGE_TEXT: &str = "
[Лицензии](https://github.com/flibusta-apps/book_bot/blob/main/LICENSE.md) [Лицензии](https://github.com/flibusta-apps/book_bot/blob/main/LICENSE.md)

View File

@@ -12,7 +12,7 @@ use regex::Regex;
use teloxide::{ use teloxide::{
prelude::*, prelude::*,
types::{InlineKeyboardButton, InlineKeyboardMarkup}, types::{InlineKeyboardButton, InlineKeyboardMarkup},
utils::command::BotCommands, utils::command::BotCommands, adaptors::Throttle,
}; };
use super::utils::{generic_get_pagination_keyboard, GetPaginationCallbackData}; 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<Bot>) -> BotHandlerInternal {
let now = Utc::now().date_naive(); let now = Utc::now().date_naive();
let d3 = now - Duration::days(3); let d3 = now - Duration::days(3);
let d7 = now - Duration::days(7); 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( async fn update_log_pagination_handler(
cq: CallbackQuery, cq: CallbackQuery,
bot: Bot, bot: Throttle<Bot>,
update_callback_data: UpdateLogCallbackData, update_callback_data: UpdateLogCallbackData,
) -> BotHandlerInternal { ) -> BotHandlerInternal {
let message = match cq.message { let message = match cq.message {
@@ -223,7 +223,7 @@ pub fn get_update_log_handler() -> crate::bots::BotHandler {
.chain(filter_callback_query::<UpdateLogCallbackData>()) .chain(filter_callback_query::<UpdateLogCallbackData>())
.endpoint( .endpoint(
|cq: CallbackQuery, |cq: CallbackQuery,
bot: Bot, bot: Throttle<Bot>,
update_log_data: UpdateLogCallbackData| async move { update_log_data: UpdateLogCallbackData| async move {
update_log_pagination_handler(cq, bot, update_log_data).await update_log_pagination_handler(cq, bot, update_log_data).await
}, },

View File

@@ -1,4 +1,4 @@
use teloxide::prelude::*; use teloxide::{prelude::*, adaptors::Throttle};
use std::error::Error; use std::error::Error;
@@ -10,7 +10,7 @@ pub mod utils;
pub async fn message_handler( pub async fn message_handler(
message: Message, message: Message,
bot: Bot, bot: Throttle<Bot>,
) -> Result<(), Box<dyn Error + Send + Sync>> { ) -> Result<(), Box<dyn Error + Send + Sync>> {
let from_user = message.from().unwrap(); let from_user = message.from().unwrap();
let text = message.text().unwrap_or(""); let text = message.text().unwrap_or("");

View File

@@ -3,7 +3,7 @@ pub mod bots_manager;
use std::error::Error; use std::error::Error;
use teloxide::prelude::*; use teloxide::{prelude::*, adaptors::Throttle};
pub type BotHandlerInternal = Result<(), Box<dyn Error + Send + Sync>>; pub type BotHandlerInternal = Result<(), Box<dyn Error + Send + Sync>>;
@@ -27,7 +27,7 @@ fn ignore_chat_member_update() -> crate::bots::BotHandler {
} }
fn get_pending_handler() -> BotHandler { fn get_pending_handler() -> BotHandler {
let handler = |msg: Message, bot: Bot| async move { let handler = |msg: Message, bot: Throttle<Bot>| async move {
let message_text = " let message_text = "
Бот зарегистрирован, но не подтвержден администратором! \ Бот зарегистрирован, но не подтвержден администратором! \
Подтверждение занимает примерно 12 часов. Подтверждение занимает примерно 12 часов.
@@ -44,7 +44,7 @@ fn get_pending_handler() -> BotHandler {
} }
fn get_blocked_handler() -> BotHandler { fn get_blocked_handler() -> BotHandler {
let handler = |msg: Message, bot: Bot| async move { let handler = |msg: Message, bot: Throttle<Bot>| async move {
let message_text = "Бот заблокирован!"; let message_text = "Бот заблокирован!";
bot.send_message(msg.chat.id, message_text).await?; bot.send_message(msg.chat.id, message_text).await?;

View File

@@ -76,9 +76,9 @@ impl BotsManager {
async fn start_bot(&mut self, bot_data: &BotData) -> bool { async fn start_bot(&mut self, bot_data: &BotData) -> bool {
let bot = Bot::new(bot_data.token.clone()) let bot = Bot::new(bot_data.token.clone())
.set_api_url(config::CONFIG.telegram_bot_api.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 let port = self.bot_port_map
.get(&bot_data.id) .get(&bot_data.id)
.unwrap_or_else(|| panic!("Can't get bot port!")); .unwrap_or_else(|| panic!("Can't get bot port!"));