botinstance move FINAL

This commit is contained in:
ModulatingForce 2023-12-19 21:43:03 -05:00
parent 39791b20a7
commit 79415210e8
2 changed files with 123 additions and 51 deletions

View file

@ -12,10 +12,13 @@ use dotenv::dotenv;
use std::collections::HashMap;
use rand::Rng;
//mod sub::ratelimiter;
use crate::core::ratelimiter::RateLimiter;
use crate::core::ratelimiter;
// use crate::core::ratelimiter;
@ -104,4 +107,71 @@ impl BotInstance {
b
}
pub async fn run(mut self) -> () {
//let b = self;
let join_handle = tokio::spawn(async move {
// while let Some(message) = incoming_messages.recv().await {
while let Some(message) = self.incoming_messages.recv().await {
// Below can be used to debug if I want to capture all messages
// println!("Received message: {:?}", message);
match message {
ServerMessage::Notice(msg) => {
if let Some(chnl) = msg.channel_login {
println!("NOTICE : (#{}) {}", chnl, msg.message_text);
}
}
ServerMessage::Privmsg(msg) => {
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 = self.ratelimiters.get_mut(&msg.channel_login).expect("ERROR: Issue with Rate limiters");
match contextratelimiter.check_limiter() {
ratelimiter::LimiterResp::Allow => {
let maxblanks = rand::thread_rng().gen_range(1..=5);
//let mut outmsg = "GotTrolled ".to_owned();
let mut outmsg = "annytfLurk ".to_owned();
for _i in 1..maxblanks {
let blankspace: &str = "󠀀";
outmsg.push_str(blankspace);
}
// client.say_in_reply_to(&msg,outmsg).await.unwrap();
self.client.say_in_reply_to(&msg,outmsg).await.unwrap();
println!("(#{}) > {}", msg.channel_login, "rate limit counter increase");
contextratelimiter.increment_counter();
println!("{:?}",self.ratelimiters);
},
ratelimiter::LimiterResp::Skip => {
(); // do nothing otherwise
}
}
},
ServerMessage::Whisper(msg) => {
println!("(w) {}: {}", msg.sender.name, msg.message_text);
},
ServerMessage::Join(msg) => {
println!("JOINED: {}", msg.channel_login);
},
ServerMessage::Part(msg) => {
println!("PARTED: {}", msg.channel_login);
},
_ => {}
}
}
});
join_handle.await.unwrap();
}
}

View file

@ -21,7 +21,7 @@ use std::collections::HashMap;
pub mod core;
use crate::core::botinstance::BotInstance;
// use crate::core::ratelimiter::RateLimiter;
use crate::core::ratelimiter;
//use crate::core::ratelimiter;
#[tokio::main]
@ -60,7 +60,7 @@ pub async fn main() {
// client.join("modulatingforcebot".to_owned()).unwrap();
// client.say("modulatingforcebot".to_owned(), "Connected!".to_owned()).await.unwrap();
let mut bot = BotInstance::init();
let bot = BotInstance::init();
@ -83,64 +83,66 @@ pub async fn main() {
// println!("{:?}",ratelimiters);
let join_handle = tokio::spawn(async move {
// while let Some(message) = incoming_messages.recv().await {
while let Some(message) = bot.incoming_messages.recv().await {
// Below can be used to debug if I want to capture all messages
// println!("Received message: {:?}", message);
bot.run().await;
match message {
ServerMessage::Notice(msg) => {
if let Some(chnl) = msg.channel_login {
println!("NOTICE : (#{}) {}", chnl, msg.message_text);
}
}
ServerMessage::Privmsg(msg) => {
println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
// let join_handle = tokio::spawn(async move {
// // while let Some(message) = incoming_messages.recv().await {
// while let Some(message) = bot.incoming_messages.recv().await {
// // Below can be used to debug if I want to capture all messages
// // println!("Received message: {:?}", message);
// match message {
// ServerMessage::Notice(msg) => {
// if let Some(chnl) = msg.channel_login {
// println!("NOTICE : (#{}) {}", chnl, msg.message_text);
// }
// }
// ServerMessage::Privmsg(msg) => {
// 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 = bot.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 => {
let maxblanks = rand::thread_rng().gen_range(1..=5);
//let mut outmsg = "GotTrolled ".to_owned();
let mut outmsg = "annytfLurk ".to_owned();
// match contextratelimiter.check_limiter() {
// ratelimiter::LimiterResp::Allow => {
// let maxblanks = rand::thread_rng().gen_range(1..=5);
// //let mut outmsg = "GotTrolled ".to_owned();
// let mut outmsg = "annytfLurk ".to_owned();
for _i in 1..maxblanks {
let blankspace: &str = "󠀀";
outmsg.push_str(blankspace);
}
// for _i in 1..maxblanks {
// let blankspace: &str = "󠀀";
// outmsg.push_str(blankspace);
// }
// client.say_in_reply_to(&msg,outmsg).await.unwrap();
bot.client.say_in_reply_to(&msg,outmsg).await.unwrap();
println!("(#{}) > {}", msg.channel_login, "rate limit counter increase");
contextratelimiter.increment_counter();
println!("{:?}",bot.ratelimiters);
},
ratelimiter::LimiterResp::Skip => {
(); // do nothing otherwise
}
}
},
ServerMessage::Whisper(msg) => {
println!("(w) {}: {}", msg.sender.name, msg.message_text);
},
ServerMessage::Join(msg) => {
println!("JOINED: {}", msg.channel_login);
},
ServerMessage::Part(msg) => {
println!("PARTED: {}", msg.channel_login);
},
_ => {}
}
}
});
// // client.say_in_reply_to(&msg,outmsg).await.unwrap();
// bot.client.say_in_reply_to(&msg,outmsg).await.unwrap();
// println!("(#{}) > {}", msg.channel_login, "rate limit counter increase");
// contextratelimiter.increment_counter();
// println!("{:?}",bot.ratelimiters);
// },
// ratelimiter::LimiterResp::Skip => {
// (); // do nothing otherwise
// }
// }
// },
// ServerMessage::Whisper(msg) => {
// println!("(w) {}: {}", msg.sender.name, msg.message_text);
// },
// ServerMessage::Join(msg) => {
// println!("JOINED: {}", msg.channel_login);
// },
// ServerMessage::Part(msg) => {
// println!("PARTED: {}", msg.channel_login);
// },
// _ => {}
// }
// }
// });
join_handle.await.unwrap();
// join_handle.await.unwrap();
}