diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 0bd38af..68c695b 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -59,12 +59,99 @@ pub use EnType::Enabled; // } +pub struct Chat { + pub ratelimiters : HashMap, // used to limit messages sent per channel + pub client : TwitchIRCClient,StaticLoginCredentials>, +} + +impl Chat { + + + pub fn init_channel(&mut self, chnl:ChType) -> () { + let n = RateLimiter::new(); + self.ratelimiters.insert(chnl,n); + } + + + + pub async fn say_in_reply_to(&mut self, msg:& PrivmsgMessage , mut outmsg:String) -> () { + // envelops a message before sending a message + // [ ] This could include additional formatting (e.g., add in random number of blank spaces) + // [ ] Incrementing or checking with RateLimiters + // [ ] For BotActions of Enabled Modules , checking whether the caller is Permissible to run the comman + + // self.client.say_in_reply_to(msg,outmsg).await.unwrap(); + + // // let contextratelimiter = ratelimiters.get_mut(&msg.channel_login).expect("ERROR: Issue with Rate limiters"); + let contextratelimiter = self.ratelimiters + .get_mut(&Channel(String::from(&msg.channel_login))) + .expect("ERROR: Issue with Rate limiters"); + // let contextratelimiter = self.ratelimiters.get(&msg.channel_login).expect("ERROR: Issue with Rate limiters"); + + match contextratelimiter.check_limiter() { + ratelimiter::LimiterResp::Allow => { + let maxblanks = rand::thread_rng().gen_range(1..=20); + //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 + } + + } + } + + async fn say(&self, _:String, _:String) -> () { + // more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say + + + // self.client.say(msg,outmsg).await.unwrap(); + + + } + + + async fn me(&self, _:String, _:String) -> () { + // more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say + + + // self.client.me(msg,outmsg).await.unwrap(); + + + } + + async fn me_in_reply_to(&self, _:String, _:String) -> () { + // more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say + + + // self.client.me(msg,outmsg).await.unwrap(); + + + } + + +} + + + pub struct BotInstance { prefix : char, bot_channel : ChType, - pub client : TwitchIRCClient,StaticLoginCredentials>, + //pub client : TwitchIRCClient,StaticLoginCredentials>, pub incoming_messages : UnboundedReceiver, - pub ratelimiters : HashMap, // used to limit messages sent per channel + // pub ratelimiters : HashMap, // used to limit messages sent per channel + chat : Chat, // botmodules : HashMap>, pub botmodules : ModulesManager, twitch_oauth : String, @@ -115,16 +202,23 @@ impl BotInstance { // ratelimiters are a hashmap of channel and a corresponding rate limiter let n = RateLimiter::new(); ratelimiters.insert(Channel(String::from(chnl)),n); + //self.chat.ratelimiters.insert(Channel(String::from(chnl)),n); } + + let b = BotInstance { prefix : prefix, bot_channel : Channel(login_name) , incoming_messages : incoming_messages, - client : client, - ratelimiters : ratelimiters, // used to limit messages sent per channel + //client : client, + chat : Chat { + ratelimiters : ratelimiters, + client : client, + } , + // ratelimiters : ratelimiters, // used to limit messages sent per channel // botmodules : HashMap::new(), botmodules : ModulesManager::init(), twitch_oauth : oauth_token, @@ -137,7 +231,7 @@ impl BotInstance { }; - println!("{:?}",b.ratelimiters); + println!("{:?}",b.chat.ratelimiters); b @@ -198,39 +292,45 @@ impl BotInstance { 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(&Channel(String::from(&msg.channel_login))) - .expect("ERROR: Issue with Rate limiters"); - // let contextratelimiter = self.ratelimiters.get(&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 = self.ratelimiters + // .get_mut(&Channel(String::from(&msg.channel_login))) + // .expect("ERROR: Issue with Rate limiters"); + // // let contextratelimiter = self.ratelimiters.get(&msg.channel_login).expect("ERROR: Issue with Rate limiters"); - match contextratelimiter.check_limiter() { - ratelimiter::LimiterResp::Allow => { - let maxblanks = rand::thread_rng().gen_range(1..=20); - //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..=20); + // //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(); - 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 - } - } + // // 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 + // } + + + self.chat.say_in_reply_to(msg,String::from("annytfLurk")).await; println!("End of Separate Listener Main prvmsg"); - + } + + } + +