From e9ffbf6b7466a5bd837db849393073bef1a4bf8b Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Sat, 6 May 2023 22:34:56 +0200 Subject: [PATCH] Add cache-me and throttle --- Cargo.lock | 7 +++++++ Cargo.toml | 2 +- src/bots_manager.rs | 6 ++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 50821ba..000b514 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1697,6 +1697,7 @@ dependencies = [ "tokio-util", "url", "uuid", + "vecrem", ] [[package]] @@ -2039,6 +2040,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "vecrem" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4808a28789238714a29163e4cb8031f0f050dd670f7a0cc74b6d80f3ce343fa" + [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index ed384cb..6cd60f9 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.12.2", features = ["macros", "webhooks-axum"] } +teloxide = { version = "0.12.2", features = ["macros", "webhooks-axum", "cache-me", "throttle"] } url = "2.2.2" ctrlc = { version = "3.2.3", features = ["termination"] } strum = "0.24" diff --git a/src/bots_manager.rs b/src/bots_manager.rs index 05cc5bf..44e54bd 100644 --- a/src/bots_manager.rs +++ b/src/bots_manager.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; +use teloxide::adaptors::throttle::Limits; use teloxide::types::BotCommand; use tokio::time::{sleep, Duration}; @@ -74,9 +75,10 @@ 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()); + .set_api_url(config::CONFIG.telegram_bot_api.clone()) + .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!"));