From d8c187d53a25659ac13d9d639843c6927056090f Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Wed, 20 Dec 2023 17:55:46 -0500 Subject: [PATCH] smol --- src/core/botinstance.rs | 164 ++++++++++++++++++++++++++++++++++------ 1 file changed, 141 insertions(+), 23 deletions(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 60d39c3..5de3650 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -4,6 +4,7 @@ use twitch_irc::login::StaticLoginCredentials; use twitch_irc::ClientConfig; use twitch_irc::SecureTCPTransport; use twitch_irc::TwitchIRCClient; +use twitch_irc::message::PrivmsgMessage; use twitch_irc::message::ServerMessage; use twitch_irc::transport::tcp::TCPTransport; use twitch_irc::transport::tcp::TLS; @@ -43,9 +44,9 @@ pub struct BotInstance { // identity : identitymodule, } - impl BotInstance { + pub fn init() -> BotInstance { dotenv().ok(); @@ -130,30 +131,40 @@ 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(&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(&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 + // } + // } + + // BotInstance::listener_main_prvmsg(msg); + //let botref = *self; + // BotInstance::listener_main_prvmsg(botref,msg).await(); + //self.listener_main_prvmsg(&msg); + + println!("Something"); + + self.listener_main_prvmsg(); + }, ServerMessage::Whisper(msg) => { println!("(w) {}: {}", msg.sender.name, msg.message_text); @@ -176,4 +187,111 @@ impl BotInstance { join_handle.await.unwrap(); } -} \ No newline at end of file + +// ----------------- +// PRIVATE FUNCTIONS + + // async fn listener_main_prvmsg(bot:BotInstance,msg:PrivmsgMessage) -> () { + + // 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"); + + // 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(); + // 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 + // } + // } + + // } + + // async fn listener_main_prvmsg(mut self,msg:& PrivmsgMessage) -> () { + + // 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..=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 listener_main_prvmsg(self) -> () { + + // 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..=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 + // } + // } + + println!("Something"); + + } + + +} + + +