Add cache-me and throttle

This commit is contained in:
2023-05-06 22:34:56 +02:00
parent 97ba1f18a2
commit e9ffbf6b74
3 changed files with 12 additions and 3 deletions

7
Cargo.lock generated
View File

@@ -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"

View File

@@ -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"

View File

@@ -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!"));