botinstance move FINAL
This commit is contained in:
parent
39791b20a7
commit
79415210e8
2 changed files with 123 additions and 51 deletions
src/core
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue