cont reorg botinstance

This commit is contained in:
ModulatingForce 2023-12-19 21:08:48 -05:00
commit 39791b20a7
4 changed files with 48 additions and 18 deletions

View file

@ -14,12 +14,14 @@ use dotenv::dotenv;
use std::collections::HashMap;
mod ratelimiter;
use ratelimiter::RateLimiter;
// mod ratelimiter;
// use ratelimiter::RateLimiter;
pub mod core;
use crate::core::botinstance::BotInstance;
// use crate::core::ratelimiter::RateLimiter;
use crate::core::ratelimiter;
#[tokio::main]
@ -71,15 +73,15 @@ pub async fn main() {
// Adding rate limit functionality to be under : https://dev.twitch.tv/docs/irc/#rate-limits
// ratelimiters are a hashmap of channel and a corresponding rate limiter
let mut ratelimiters:HashMap<String,RateLimiter> = HashMap::new();
// // ratelimiters are a hashmap of channel and a corresponding rate limiter
// let mut ratelimiters:HashMap<String,RateLimiter> = HashMap::new();
for chnl in bot.bot_channels {
let n = RateLimiter::new();
ratelimiters.insert(chnl.to_owned(),n);
}
// for chnl in bot.bot_channels {
// let n = RateLimiter::new();
// ratelimiters.insert(chnl.to_owned(),n);
// }
println!("{:?}",ratelimiters);
// println!("{:?}",ratelimiters);
let join_handle = tokio::spawn(async move {
// while let Some(message) = incoming_messages.recv().await {
@ -97,7 +99,8 @@ pub async fn main() {
println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
let contextratelimiter = ratelimiters.get_mut(&msg.channel_login).expect("ERROR: Issue with Rate limiters");
// let contextratelimiter = ratelimiters.get_mut(&msg.channel_login).expect("ERROR: Issue with Rate limiters");
let contextratelimiter = bot.ratelimiters.get_mut(&msg.channel_login).expect("ERROR: Issue with Rate limiters");
match contextratelimiter.check_limiter() {
ratelimiter::LimiterResp::Allow => {
@ -114,7 +117,7 @@ pub async fn main() {
bot.client.say_in_reply_to(&msg,outmsg).await.unwrap();
println!("(#{}) > {}", msg.channel_login, "rate limit counter increase");
contextratelimiter.increment_counter();
println!("{:?}",ratelimiters);
println!("{:?}",bot.ratelimiters);
},
ratelimiter::LimiterResp::Skip => {
(); // do nothing otherwise