From 2957f9462bf4b33e2e20bf3a016848e3f3e60782 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:14:51 -0400 Subject: [PATCH 01/13] reorg common say logic --- src/core/chat.rs | 71 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 12 deletions(-) diff --git a/src/core/chat.rs b/src/core/chat.rs index fe49896..cc62376 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -27,6 +27,14 @@ pub struct Chat { pub client: TwitchIRCClient, StaticLoginCredentials>, } + +#[derive(Clone)] +enum BotMsgType<'a> { + SayInReplyTo(&'a PrivmsgMessage,String), + _Say(String,String) +} + + impl Chat { pub fn init( ratelimiters: HashMap, @@ -43,8 +51,11 @@ impl Chat { self.ratelimiters.lock().await.insert(chnl, n); } - pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, mut outmsg: String) { - /* + + + + async fn send_botmsg(&self, msginput: BotMsgType<'_>) { + /* formats message before sending to TwitchIRC - [x] Custom String Formatting (e.g., adding random black spaces) @@ -53,12 +64,21 @@ impl Chat { */ + let (channel_login,mut outmsg) = match msginput.clone() { + BotMsgType::SayInReplyTo(msg, outmsg) => { + (msg.channel_login.clone(),outmsg) + }, + _ => { + panic!("ISSUE : NOT IMPLEMENTED") + }, + }; + let rl = Arc::clone(&self.ratelimiters); let mut rllock = rl.lock().await; let contextratelimiter = rllock // .get_mut() - .get_mut(&Channel(String::from(&msg.channel_login))) + .get_mut(&Channel(String::from(channel_login.clone()))) .expect("ERROR: Issue with Rate limiters"); // Continue to check the limiter and sleep if required if the minimum is not reached @@ -75,20 +95,38 @@ impl Chat { outmsg.push_str(blankspace); } - self.client.say_in_reply_to(msg, outmsg).await.unwrap(); - + match msginput.clone() { + BotMsgType::SayInReplyTo(msg, _) => { + self.client.say_in_reply_to(msg, outmsg).await.unwrap(); + }, + _ => { + panic!("ISSUE : NOT IMPLEMENTED") + }, + } + contextratelimiter.increment_counter(); let logstr = format!( "(#{}) > {} ; contextratelimiter : {:?}", - msg.channel_login, "rate limit counter increase", contextratelimiter + channel_login.clone(), "rate limit counter increase", contextratelimiter ); - botlog::trace( - logstr.as_str(), - Some("Chat > say_in_reply_to".to_string()), - Some(msg), - ); + if let BotMsgType::SayInReplyTo(msg,_ ) = msginput { + botlog::trace( + logstr.as_str(), + Some("Chat > say_in_reply_to".to_string()), + Some(&msg), + ); + } else { + botlog::trace( + logstr.as_str(), + Some("Chat > say_in_reply_to".to_string()), + None, + ); + } + + + } ratelimiter::LimiterResp::Skip => { // (); // do nothing otherwise @@ -98,7 +136,16 @@ impl Chat { } } - Log::flush(); + + Log::flush(); + } + + + + pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String) { + + self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg)).await; + } async fn _say(&self, _: String, _: String) { From b8bf2e33f6ac2e33be12fca56f8423a99ddd04bd Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:21:08 -0400 Subject: [PATCH 02/13] added say to Chat --- src/core/chat.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/core/chat.rs b/src/core/chat.rs index cc62376..5ca8a61 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -31,7 +31,7 @@ pub struct Chat { #[derive(Clone)] enum BotMsgType<'a> { SayInReplyTo(&'a PrivmsgMessage,String), - _Say(String,String) + Say(String,String), } @@ -68,9 +68,12 @@ impl Chat { BotMsgType::SayInReplyTo(msg, outmsg) => { (msg.channel_login.clone(),outmsg) }, - _ => { - panic!("ISSUE : NOT IMPLEMENTED") + BotMsgType::Say(a,b ) => { + (a.clone(),b.clone()) }, + // _ => { + // panic!("ISSUE : NOT IMPLEMENTED") + // }, }; let rl = Arc::clone(&self.ratelimiters); @@ -99,9 +102,12 @@ impl Chat { BotMsgType::SayInReplyTo(msg, _) => { self.client.say_in_reply_to(msg, outmsg).await.unwrap(); }, - _ => { - panic!("ISSUE : NOT IMPLEMENTED") - }, + BotMsgType::Say(a, _) => { + self.client.say(a, outmsg).await.unwrap(); + } + // _ => { + // panic!("ISSUE : NOT IMPLEMENTED") + // }, } contextratelimiter.increment_counter(); @@ -114,13 +120,13 @@ impl Chat { if let BotMsgType::SayInReplyTo(msg,_ ) = msginput { botlog::trace( logstr.as_str(), - Some("Chat > say_in_reply_to".to_string()), + Some("Chat > send_botmsg".to_string()), Some(&msg), ); } else { botlog::trace( logstr.as_str(), - Some("Chat > say_in_reply_to".to_string()), + Some("Chat > send_botmsg".to_string()), None, ); } @@ -148,10 +154,11 @@ impl Chat { } - async fn _say(&self, _: String, _: String) { + async fn _say(&self, channel_login: String, message: String) { // more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say // self.client.say(msg,outmsg).await.unwrap(); + self.send_botmsg(BotMsgType::Say(channel_login, message)).await; } async fn _me(&self, _: String, _: String) { From 5802e9b755d071be13837e669b6063706bd95d82 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 23 Mar 2024 13:32:22 -0400 Subject: [PATCH 03/13] experimental say functionality --- src/core/chat.rs | 11 +- src/custom.rs | 8 +- src/custom/experimental.rs | 24 ++++ .../experiment001.rs} | 0 src/custom/experimental/experiment002.rs | 135 ++++++++++++++++++ 5 files changed, 172 insertions(+), 6 deletions(-) create mode 100644 src/custom/experimental.rs rename src/custom/{experiments.rs => experimental/experiment001.rs} (100%) create mode 100644 src/custom/experimental/experiment002.rs diff --git a/src/core/chat.rs b/src/core/chat.rs index 5ca8a61..7f00a7e 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -79,9 +79,15 @@ impl Chat { let rl = Arc::clone(&self.ratelimiters); let mut rllock = rl.lock().await; + botlog::debug( + &format!("Ratelimiter being checked for channel : {}",channel_login.clone()), + Some("Chat > send_botmsg".to_string()), + None, + ); + let contextratelimiter = rllock // .get_mut() - .get_mut(&Channel(String::from(channel_login.clone()))) + .get_mut(&Channel(String::from(channel_login.to_lowercase().clone()))) .expect("ERROR: Issue with Rate limiters"); // Continue to check the limiter and sleep if required if the minimum is not reached @@ -154,10 +160,9 @@ impl Chat { } - async fn _say(&self, channel_login: String, message: String) { + pub async fn say(&self, channel_login: String, message: String) { // more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say - // self.client.say(msg,outmsg).await.unwrap(); self.send_botmsg(BotMsgType::Say(channel_login, message)).await; } diff --git a/src/custom.rs b/src/custom.rs index fc802e6..6107797 100644 --- a/src/custom.rs +++ b/src/custom.rs @@ -1,5 +1,5 @@ /* - `modules` will : + `custom` will : - be a starting refrence point for the bot instance to pull module definitions for */ @@ -11,7 +11,8 @@ pub use crate::core::botmodules::ModulesManager; // [ ] Load submodules -mod experiments; +// mod experiments; +mod experimental; // [ ] init() function that accepts bot instance - this is passed to init() on submodules @@ -19,5 +20,6 @@ pub async fn init(mgr: Arc) { // Modules initializer loads modules into the bot // this is achieved by calling submodules that also have fn init() defined - experiments::init(mgr).await + // experiments::init(mgr).await + experimental::init(mgr).await; } diff --git a/src/custom/experimental.rs b/src/custom/experimental.rs new file mode 100644 index 0000000..e2aa67e --- /dev/null +++ b/src/custom/experimental.rs @@ -0,0 +1,24 @@ +/* + `experimental` will : + - be for mostly experimental +*/ + +use std::sync::Arc; + +pub use crate::core::botinstance::BotInstance; +pub use crate::core::botmodules::ModulesManager; + +// [ ] Load submodules + +mod experiment001; +mod experiment002; + +// [ ] init() function that accepts bot instance - this is passed to init() on submodules + +pub async fn init(mgr: Arc) { + // Modules initializer loads modules into the bot + // this is achieved by calling submodules that also have fn init() defined + + experiment001::init(Arc::clone(&mgr)).await; + experiment002::init(Arc::clone(&mgr)).await; +} diff --git a/src/custom/experiments.rs b/src/custom/experimental/experiment001.rs similarity index 100% rename from src/custom/experiments.rs rename to src/custom/experimental/experiment001.rs diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs new file mode 100644 index 0000000..d3b70e5 --- /dev/null +++ b/src/custom/experimental/experiment002.rs @@ -0,0 +1,135 @@ +/* + Custom Modules - + + Usage : + [ ] within the file's init(), define BotActions & Load them into the ModulesManager + [ ] Define Execution Bodies for these BotActions + [ ] Afterwards, add the following to parent modules.rs file + - mod ; + - within init(), ::init(mgr).await + +*/ + +// use rand::Rng; +use std::sync::Arc; + +use twitch_irc::message::PrivmsgMessage; + +// use crate::core::botinstance::ChType::Channel; +use crate::core::botinstance::ChType; +use ChType::Channel; +use crate::core::botlog; + +use casual_logger::Log; + +use crate::core::bot_actions::actions_util::{self, BotAR}; +use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager}; + +use crate::core::identity::UserRole::*; + +// use tokio::time::{sleep, Duration}; + +pub async fn init(mgr: Arc) { + + const OF_CMD_CHANNEL:ChType = Channel(String::new()); + + + // 1. Define the BotAction + let botc1 = BotCommand { + module: BotModule(String::from("experiments002")), + command: String::from("say"), // command call name + alias: vec![ + "s".to_string(), + ], // String of alternative names + exec_body: actions_util::asyncbox(sayout), + help: String::from("Test Command tester"), + required_roles: vec![ + BotAdmin, + Mod(OF_CMD_CHANNEL), + ], + }; + + // 2. Add the BotAction to ModulesManager + botc1.add_to_modmgr(Arc::clone(&mgr)).await; + + mgr.set_instance_enabled(BotModule(String::from("experiments002"))).await; + + +} + + +async fn sayout(bot: BotAR, msg: PrivmsgMessage) { + + /* + usage : + + */ + + // [x] Unwraps arguments from message + + let argrslt = + if let Some((_,str1)) = msg.message_text.split_once(" ") { + if let Some((channelstr,msgstr)) = str1.split_once(" ") { + // println!("{}",cmdstr); + // println!("{}",channelstr); + // println!("{}",msgstr); + Some((channelstr,msgstr)) + } + else { None } + } + else { None }; + + + + + match argrslt { + Some((trgchnl,outmsg)) => { + + let newoutmsg = format!("{} (from #{}) says : {}", + msg.sender.name,msg.channel_login, outmsg); + + + let bot = Arc::clone(&bot); + + let botlock = bot.read().await; + + // uses chat.say_in_reply_to() for the bot controls for messages + botlock + .botmgrs + .chat + .say(trgchnl.to_string(), newoutmsg.to_string()) + .await; + + // botlog::debug( + // "Sayout had issues trying to parse arguments", + // Some("experiment002 > sayout".to_string()), + // Some(&msg), + // ); + + + }, + None => { + botlog::debug( + "sayout had issues trying to parse arguments", + Some("experiment002 > sayout".to_string()), + Some(&msg), + ); + + let bot = Arc::clone(&bot); + + let botlock = bot.read().await; + + // uses chat.say_in_reply_to() for the bot controls for messages + botlock + .botmgrs + .chat + .say_in_reply_to(&msg, String::from("Invalid arguments")) + .await; + + }, + + } + + + Log::flush(); +} \ No newline at end of file From 4613d69e3f8095ecdb8cdcc26a2dfed3b4e1969f Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 23 Mar 2024 16:58:46 -0400 Subject: [PATCH 04/13] smol --- src/custom/experimental/experiment002.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index d3b70e5..5f4226b 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -16,8 +16,8 @@ use std::sync::Arc; use twitch_irc::message::PrivmsgMessage; // use crate::core::botinstance::ChType::Channel; -use crate::core::botinstance::ChType; -use ChType::Channel; +use crate::core::botinstance::Channel; +// use ChType::Channel; use crate::core::botlog; use casual_logger::Log; @@ -31,7 +31,7 @@ use crate::core::identity::UserRole::*; pub async fn init(mgr: Arc) { - const OF_CMD_CHANNEL:ChType = Channel(String::new()); + const OF_CMD_CHANNEL:Channel = Channel(String::new()); // 1. Define the BotAction From ff6046bb1f7f0ae11c072fe389ff5b5a3d5dc37b Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 23 Mar 2024 18:04:57 -0400 Subject: [PATCH 05/13] botcommands recognized in replies --- src/core/botinstance.rs | 95 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 5 deletions(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index a668dac..8d76956 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -171,6 +171,7 @@ impl BotInstance { ); } ServerMessage::Privmsg(msg) => { + botlog::debug( format!( "[Twitch Chat > {}] > {}: {}", @@ -181,6 +182,17 @@ impl BotInstance { Some(&msg), ); + + botlog::trace( + format!( + "[TRACE][Twitch Chat > {}] > {}: {:?}", + msg.channel_login, msg.sender.name, msg + ) + .as_str(), + Some("BotInstance > runner()".to_string()), + Some(&msg), + ); + BotInstance::listener_main_prvmsg(Arc::clone(&bot), &msg).await; } ServerMessage::Whisper(msg) => { @@ -243,6 +255,59 @@ impl BotInstance { Some(msg), ); + + // /* + // [ ] Here, msg is taken, and message_text is split so we can pull the first argument + // */ + + // let inpt = msg + // .message_text + // .split(' ') + // .next() + // .expect("ERROR during BotCommand"); + + /* + [ ] What we should do instead is : + 1. Check if the message is related to a Reply (so we know how many arguments we should skip) + 2. If a reply, skip the first argument + */ + + let mut msgiter= msg + .message_text + .split(' '); + + let arg1 = msgiter.next(); + let arg2 = msgiter.next(); + + let reply = if let Some(replyidout) = msg.source.tags.0.get("reply-thread-parent-msg-id") { + if let Some(replyid) = replyidout { + // println!("Detected Reply : {}",replyid); + Some(replyid) + } else { None } + } else { None } + ; + + // let inpt = match reply { + // None => arg1, // Regular message, use the first arg as the command + // Some(_) => arg2, // A reply message, use the 2nd arg as the command + // }; + + + let inpt = match reply { + None => { // Regular message, use the first arg as the command + match arg1 { + None => return, // return if no argument found + Some(a) => a, + } + }, + Some(_) => { + match arg2 { // A reply message, use the 2nd arg as the command + None => return, // return if no argument found + Some(a) => a, + } + }, + }; + for acts in (*actsdblock).values() { for a in acts { match a { @@ -263,11 +328,31 @@ impl BotInstance { Some(msg), ); - let inpt = msg - .message_text - .split(' ') - .next() - .expect("ERROR during BotCommand"); + + // /* + // [ ] Here, msg is taken, and message_text is split so we can pull the first argument + // */ + + // let inpt = msg + // .message_text + // .split(' ') + // .next() + // .expect("ERROR during BotCommand"); + + // /* + // [ ] What we should do instead is : + // 1. Check if the message is related to a Reply (so we know how many arguments we should skip) + // 2. If a reply, skip the first argument + // */ + + // if let Some(rslt) = msg.source.tags.0.get("reply-thread-parent-msg-id") { + // if let Some(rslt) = rslt { + // println!("Detected Reply : {}",rslt); + // } + // } + + + // [x] Check if a bot command based on ... // [x] prefix + command From 7e59b8b251b85c563bdff6e5fff205addcc2ca43 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 23 Mar 2024 18:33:33 -0400 Subject: [PATCH 06/13] say chnl must be valid --- src/core/chat.rs | 11 +++++++++++ src/custom/experimental/experiment002.rs | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/core/chat.rs b/src/core/chat.rs index e6b520d..6bd61e5 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -76,6 +76,17 @@ impl Chat { // }, }; + if self.client.get_channel_status(channel_login.clone()).await == (false,false) { + // in the case where the provided channel isn't something we're known to be connected to + + botlog::warn( + &format!("A message attempted to send for a Non-Joined Channel : {}",channel_login.clone()), + Some("Chat > send_botmsg".to_string()), + None, + ); + return ; + } + let rl = Arc::clone(&self.ratelimiters); let mut rllock = rl.lock().await; diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index 5f4226b..5b4f11b 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -81,6 +81,7 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { + match argrslt { Some((trgchnl,outmsg)) => { @@ -93,6 +94,27 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { let botlock = bot.read().await; + // [x] Validate first if trgchnl exists + + if botlock.botmgrs.chat.client.get_channel_status(trgchnl.to_string().clone()).await == (false,false) { + // in the case where the provided channel isn't something we're known to be connected to + // botlog::warn( + // &format!("A message attempted to send for a Non-Joined Channel : {}",channel_login.clone()), + // Some("Chat > send_botmsg".to_string()), + // None, + // ); + // return ; + + botlock + .botmgrs + .chat + .say_in_reply_to(&msg, format!("Cannot join channel : {}",trgchnl.to_string())) + .await; + + + } + + // uses chat.say_in_reply_to() for the bot controls for messages botlock .botmgrs From 0e12cd1bff68b06783bfd4bddbd5d65e1bece67c Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 23 Mar 2024 19:20:43 -0400 Subject: [PATCH 07/13] experiments module --- src/custom/experimental/experiment002.rs | 98 +++++++++++++++++++----- 1 file changed, 80 insertions(+), 18 deletions(-) diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index 5b4f11b..91043c8 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -65,31 +65,50 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { */ + + let reply_parent = if let Some(replyout) = msg.source.tags.0.get("reply-parent-msg-body") { + if let Some(replymsg) = replyout { + // println!("Detected Reply : {}",replyid); + Some(replymsg) + } else { None } + } else { None } + ; + + let reply_parent_usr = if let Some(replyout) = msg.source.tags.0.get("reply-thread-parent-user-login") { + if let Some(replymsgusr) = replyout { + // println!("Detected Reply : {}",replyid); + Some(replymsgusr) + } else { None } + } else { None } + ; + // [x] Unwraps arguments from message let argrslt = if let Some((_,str1)) = msg.message_text.split_once(" ") { - if let Some((channelstr,msgstr)) = str1.split_once(" ") { - // println!("{}",cmdstr); - // println!("{}",channelstr); - // println!("{}",msgstr); - Some((channelstr,msgstr)) - } - else { None } + if reply_parent.is_none() { + if let Some((channelstr,msgstr)) = str1.split_once(" ") { + Some((channelstr,msgstr)) + } + else { None } + } else { + if let Some((_,str2)) = str1.split_once(" ") { + if let Some((channelstr,msgstr)) = str2.split_once(" ") { + Some((channelstr,msgstr)) + } + else { None } + } + else { None } + } } else { None }; - match argrslt { Some((trgchnl,outmsg)) => { - let newoutmsg = format!("{} (from #{}) says : {}", - msg.sender.name,msg.channel_login, outmsg); - - let bot = Arc::clone(&bot); let botlock = bot.read().await; @@ -98,23 +117,66 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { if botlock.botmgrs.chat.client.get_channel_status(trgchnl.to_string().clone()).await == (false,false) { // in the case where the provided channel isn't something we're known to be connected to - // botlog::warn( - // &format!("A message attempted to send for a Non-Joined Channel : {}",channel_login.clone()), - // Some("Chat > send_botmsg".to_string()), - // None, - // ); + botlog::warn( + &format!("A message attempted to send for a Non-Joined Channel : {}",trgchnl.to_string().clone()), + Some("Chat > send_botmsg".to_string()), + None, + ); // return ; botlock .botmgrs .chat - .say_in_reply_to(&msg, format!("Cannot join channel : {}",trgchnl.to_string())) + .say_in_reply_to(&msg, format!("Not a Joined Channel : {}",trgchnl.to_string())) .await; } + + // if let Some((arg1,arg1other)) = msg.message_text.split_once(' ') { + + // } + + + /* + 1. If a Reply , + [ ] Get Parent Content message - reply_parent + [ ] Get Parent Chatter - reply_parent_usr + [ ] Get Parent Channel - msg.channel_login + -> Share this first then + [ ] Get Reply Message (that triggered bot command) - msgstr + [ ] Get Reply Sender - msg.sender.name + [ ] Get Target Channel - trgchnl + + 2. If not a reply + [ ] Get Reply Message (that triggered bot command) - msgstr + [ ] Get Reply Sender - msg.sender.name + [ ] Get Target Channel - trgchnl + */ + + + + if let Some(srcmsg) = reply_parent { + + let newoutmsg = format!("{} from #{} Shared >> {} : {}", + msg.sender.name,msg.channel_login, reply_parent_usr.unwrap(),srcmsg); + + // uses chat.say_in_reply_to() for the bot controls for messages + botlock + .botmgrs + .chat + .say(trgchnl.to_string(), newoutmsg.to_string()) + .await; + } + + + let newoutmsg = format!("{} from #{} says : {}", + msg.sender.name,msg.channel_login, outmsg); + + + // uses chat.say_in_reply_to() for the bot controls for messages botlock .botmgrs From 22b2ec746af6e0e4fee64a023a77d140d491a9d8 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 23 Mar 2024 19:37:43 -0400 Subject: [PATCH 08/13] smol adj --- src/core/botinstance.rs | 12 ++++++ src/custom/experimental/experiment002.rs | 54 ++++++++++++++++-------- 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 8d76956..c3d1d37 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -161,6 +161,18 @@ impl BotInstance { while let Some(message) = msglock.recv().await { + + botlog::trace( + format!( + "[TRACE][ServerMessage] > {:?}", + message + ) + .as_str(), + Some("BotInstance > runner()".to_string()), + None, + ); + + match message { ServerMessage::Notice(msg) => { botlog::notice( diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index 91043c8..67a9fa8 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -157,26 +157,16 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { */ + let newoutmsg = if let Some(srcmsg) = reply_parent { - if let Some(srcmsg) = reply_parent { - - let newoutmsg = format!("{} from #{} Shared >> {} : {}", - msg.sender.name,msg.channel_login, reply_parent_usr.unwrap(),srcmsg); - - // uses chat.say_in_reply_to() for the bot controls for messages - botlock - .botmgrs - .chat - .say(trgchnl.to_string(), newoutmsg.to_string()) - .await; - } + format!("{} from #{} says {} . Replying to: {} : {}", + msg.sender.name,msg.channel_login,outmsg, reply_parent_usr.unwrap(),srcmsg) + } else { + format!("{} from #{} says : {}", + msg.sender.name,msg.channel_login, outmsg) + }; - let newoutmsg = format!("{} from #{} says : {}", - msg.sender.name,msg.channel_login, outmsg); - - - // uses chat.say_in_reply_to() for the bot controls for messages botlock .botmgrs @@ -184,6 +174,36 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { .say(trgchnl.to_string(), newoutmsg.to_string()) .await; + + + // if let Some(srcmsg) = reply_parent { + + // let newoutmsg = format!("{} from #{} Shared >> {} : {}", + // msg.sender.name,msg.channel_login, reply_parent_usr.unwrap(),srcmsg); + + // // uses chat.say_in_reply_to() for the bot controls for messages + // botlock + // .botmgrs + // .chat + // .say(trgchnl.to_string(), newoutmsg.to_string()) + // .await; + // } + + + // let newoutmsg = format!("{} from #{} says : {}", + // msg.sender.name,msg.channel_login, outmsg); + + + + // // uses chat.say_in_reply_to() for the bot controls for messages + // botlock + // .botmgrs + // .chat + // .say(trgchnl.to_string(), newoutmsg.to_string()) + // .await; + + + // botlog::debug( // "Sayout had issues trying to parse arguments", // Some("experiment002 > sayout".to_string()), From 30a3e2af008e8cda4a0ab49d457e845fb8ff76eb Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 23 Mar 2024 19:39:36 -0400 Subject: [PATCH 09/13] comments cleanup --- src/custom/experimental/experiment002.rs | 43 ------------------------ 1 file changed, 43 deletions(-) diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index 67a9fa8..fde184e 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -133,13 +133,6 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { } - - - // if let Some((arg1,arg1other)) = msg.message_text.split_once(' ') { - - // } - - /* 1. If a Reply , [ ] Get Parent Content message - reply_parent @@ -166,7 +159,6 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { msg.sender.name,msg.channel_login, outmsg) }; - // uses chat.say_in_reply_to() for the bot controls for messages botlock .botmgrs @@ -176,41 +168,6 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { - // if let Some(srcmsg) = reply_parent { - - // let newoutmsg = format!("{} from #{} Shared >> {} : {}", - // msg.sender.name,msg.channel_login, reply_parent_usr.unwrap(),srcmsg); - - // // uses chat.say_in_reply_to() for the bot controls for messages - // botlock - // .botmgrs - // .chat - // .say(trgchnl.to_string(), newoutmsg.to_string()) - // .await; - // } - - - // let newoutmsg = format!("{} from #{} says : {}", - // msg.sender.name,msg.channel_login, outmsg); - - - - // // uses chat.say_in_reply_to() for the bot controls for messages - // botlock - // .botmgrs - // .chat - // .say(trgchnl.to_string(), newoutmsg.to_string()) - // .await; - - - - // botlog::debug( - // "Sayout had issues trying to parse arguments", - // Some("experiment002 > sayout".to_string()), - // Some(&msg), - // ); - - }, None => { botlog::debug( From 098f16ce870c824895ca06e881d03fd896995f42 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 23 Mar 2024 20:06:45 -0400 Subject: [PATCH 10/13] say channel case insensitive --- src/core/botinstance.rs | 29 ++++-------------------- src/core/chat.rs | 2 +- src/custom/experimental/experiment002.rs | 11 ++++++++- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index c3d1d37..e8b8793 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -181,6 +181,7 @@ impl BotInstance { Some("BotInstance > runner()".to_string()), None, ); + Log::flush(); } ServerMessage::Privmsg(msg) => { @@ -204,6 +205,7 @@ impl BotInstance { Some("BotInstance > runner()".to_string()), Some(&msg), ); + Log::flush(); BotInstance::listener_main_prvmsg(Arc::clone(&bot), &msg).await; } @@ -213,6 +215,7 @@ impl BotInstance { Some("BotInstance > runner()".to_string()), None, ); + Log::flush(); } ServerMessage::Join(msg) => { botlog::notice( @@ -220,6 +223,7 @@ impl BotInstance { Some("BotInstance > runner()".to_string()), None, ); + Log::flush(); } ServerMessage::Part(msg) => { botlog::notice( @@ -227,6 +231,7 @@ impl BotInstance { Some("BotInstance > runner()".to_string()), None, ); + Log::flush(); } _ => {} }; @@ -341,30 +346,6 @@ impl BotInstance { ); - // /* - // [ ] Here, msg is taken, and message_text is split so we can pull the first argument - // */ - - // let inpt = msg - // .message_text - // .split(' ') - // .next() - // .expect("ERROR during BotCommand"); - - // /* - // [ ] What we should do instead is : - // 1. Check if the message is related to a Reply (so we know how many arguments we should skip) - // 2. If a reply, skip the first argument - // */ - - // if let Some(rslt) = msg.source.tags.0.get("reply-thread-parent-msg-id") { - // if let Some(rslt) = rslt { - // println!("Detected Reply : {}",rslt); - // } - // } - - - // [x] Check if a bot command based on ... // [x] prefix + command diff --git a/src/core/chat.rs b/src/core/chat.rs index 6bd61e5..8761516 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -174,7 +174,7 @@ impl Chat { pub async fn say(&self, channel_login: String, message: String) { // more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say - self.send_botmsg(BotMsgType::Say(channel_login, message)).await; + self.send_botmsg(BotMsgType::Say(channel_login.to_lowercase(), message)).await; } async fn _me(&self, _: String, _: String) { diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index fde184e..a00e76b 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -115,7 +115,16 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { // [x] Validate first if trgchnl exists - if botlock.botmgrs.chat.client.get_channel_status(trgchnl.to_string().clone()).await == (false,false) { + botlog::trace( + &format!("[TRACE] Evaluated status of {} : {:?}", + trgchnl.to_string().clone(),botlock.botmgrs.chat.client.get_channel_status(trgchnl.to_string().clone()).await), + Some("Chat > send_botmsg".to_string()), + None, + ); + + // if botlock.botmgrs.chat.client.get_channel_status(trgchnl.to_string().clone()).await == (false,false) { + if !botlock.bot_channels.contains(&Channel(trgchnl.to_lowercase().to_string().clone())) { + // in the case where the provided channel isn't something we're known to be connected to botlog::warn( &format!("A message attempted to send for a Non-Joined Channel : {}",trgchnl.to_string().clone()), From d372d0dc791629f6bebaa7eb3862f48878f42b15 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 23 Mar 2024 20:14:42 -0400 Subject: [PATCH 11/13] comments cleanup --- src/core/botinstance.rs | 5 ----- src/core/chat.rs | 6 ------ 2 files changed, 11 deletions(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index e8b8793..7c6f33b 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -304,11 +304,6 @@ impl BotInstance { } else { None } ; - // let inpt = match reply { - // None => arg1, // Regular message, use the first arg as the command - // Some(_) => arg2, // A reply message, use the 2nd arg as the command - // }; - let inpt = match reply { None => { // Regular message, use the first arg as the command diff --git a/src/core/chat.rs b/src/core/chat.rs index 8761516..370fcf5 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -71,9 +71,6 @@ impl Chat { BotMsgType::Say(a,b ) => { (a.clone(),b.clone()) }, - // _ => { - // panic!("ISSUE : NOT IMPLEMENTED") - // }, }; if self.client.get_channel_status(channel_login.clone()).await == (false,false) { @@ -122,9 +119,6 @@ impl Chat { BotMsgType::Say(a, _) => { self.client.say(a, outmsg).await.unwrap(); } - // _ => { - // panic!("ISSUE : NOT IMPLEMENTED") - // }, } contextratelimiter.increment_counter(); From e4a44894d7a63de4ce099d81cf5de240158ece9e Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 23 Mar 2024 20:29:18 -0400 Subject: [PATCH 12/13] clippy cleanup clippy cleanup --- src/core/botinstance.rs | 23 ++++------------ src/core/chat.rs | 4 +-- src/custom/experimental.rs | 2 +- src/custom/experimental/experiment002.rs | 34 +++++++++--------------- 4 files changed, 21 insertions(+), 42 deletions(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 7c6f33b..c5b6dca 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -272,17 +272,7 @@ impl BotInstance { Some(msg), ); - - // /* - // [ ] Here, msg is taken, and message_text is split so we can pull the first argument - // */ - - // let inpt = msg - // .message_text - // .split(' ') - // .next() - // .expect("ERROR during BotCommand"); - + /* [ ] What we should do instead is : 1. Check if the message is related to a Reply (so we know how many arguments we should skip) @@ -295,14 +285,11 @@ impl BotInstance { let arg1 = msgiter.next(); let arg2 = msgiter.next(); - - let reply = if let Some(replyidout) = msg.source.tags.0.get("reply-thread-parent-msg-id") { - if let Some(replyid) = replyidout { - // println!("Detected Reply : {}",replyid); - Some(replyid) - } else { None } + + let reply = if let Some(Some(replyid)) = msg.source.tags.0.get("reply-thread-parent-msg-id") { + Some(replyid) } else { None } - ; + ; let inpt = match reply { diff --git a/src/core/chat.rs b/src/core/chat.rs index 370fcf5..1ba85e7 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -95,7 +95,7 @@ impl Chat { let contextratelimiter = rllock // .get_mut() - .get_mut(&Channel(String::from(channel_login.to_lowercase().clone()))) + .get_mut(&Channel(channel_login.to_lowercase().clone())) .expect("ERROR: Issue with Rate limiters"); // Continue to check the limiter and sleep if required if the minimum is not reached @@ -132,7 +132,7 @@ impl Chat { botlog::trace( logstr.as_str(), Some("Chat > send_botmsg".to_string()), - Some(&msg), + Some(msg), ); } else { botlog::trace( diff --git a/src/custom/experimental.rs b/src/custom/experimental.rs index e2aa67e..409abd1 100644 --- a/src/custom/experimental.rs +++ b/src/custom/experimental.rs @@ -5,7 +5,7 @@ use std::sync::Arc; -pub use crate::core::botinstance::BotInstance; +// pub use crate::core::botinstance::BotInstance; pub use crate::core::botmodules::ModulesManager; // [ ] Load submodules diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index a00e76b..ff18642 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -65,41 +65,33 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { */ - - let reply_parent = if let Some(replyout) = msg.source.tags.0.get("reply-parent-msg-body") { - if let Some(replymsg) = replyout { - // println!("Detected Reply : {}",replyid); - Some(replymsg) + let reply_parent = if let Some(Some(reply)) = msg.source.tags.0.get("reply-parent-msg-body") { + Some(reply) } else { None } - } else { None } ; - let reply_parent_usr = if let Some(replyout) = msg.source.tags.0.get("reply-thread-parent-user-login") { - if let Some(replymsgusr) = replyout { - // println!("Detected Reply : {}",replyid); - Some(replymsgusr) + + let reply_parent_usr = if let Some(Some(reply)) = msg.source.tags.0.get("reply-thread-parent-user-login") { + Some(reply) } else { None } - } else { None } ; // [x] Unwraps arguments from message + let argrslt = - if let Some((_,str1)) = msg.message_text.split_once(" ") { + if let Some((_,str1)) = msg.message_text.split_once(' ') { if reply_parent.is_none() { - if let Some((channelstr,msgstr)) = str1.split_once(" ") { + if let Some((channelstr,msgstr)) = str1.split_once(' ') { Some((channelstr,msgstr)) } else { None } - } else { - if let Some((_,str2)) = str1.split_once(" ") { - if let Some((channelstr,msgstr)) = str2.split_once(" ") { - Some((channelstr,msgstr)) - } - else { None } + } else if let Some((_,str2)) = str1.split_once(' ') { + if let Some((channelstr,msgstr)) = str2.split_once(' ') { + Some((channelstr,msgstr)) } else { None } - } + } else { None } } else { None }; @@ -136,7 +128,7 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { botlock .botmgrs .chat - .say_in_reply_to(&msg, format!("Not a Joined Channel : {}",trgchnl.to_string())) + .say_in_reply_to(&msg, format!("Not a Joined Channel : {}",trgchnl)) .await; From 97d76ea088a00e8f9231be78db0dc5f1a9c05a13 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 23 Mar 2024 22:40:06 -0400 Subject: [PATCH 13/13] added ts to experiment --- Cargo.lock | 5 +-- Cargo.toml | 1 + src/custom/experimental/experiment002.rs | 43 ++++++++++++++++++++---- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 18195c8..018b9dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -122,9 +122,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.34" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" +checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" dependencies = [ "android-tzdata", "iana-time-zone", @@ -196,6 +196,7 @@ version = "0.1.0" dependencies = [ "async-trait", "casual_logger", + "chrono", "dotenv", "futures", "rand", diff --git a/Cargo.toml b/Cargo.toml index 87f8cfa..f4c7751 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ rand = { version = "0.8.5", features = [] } futures = "0.3" async-trait = "0.1.77" casual_logger = "0.6.5" +chrono = "0.4.35" [lib] name = "bot_lib" diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index ff18642..2a97b30 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -13,6 +13,8 @@ // use rand::Rng; use std::sync::Arc; +use chrono::{TimeZone,Local}; + use twitch_irc::message::PrivmsgMessage; // use crate::core::botinstance::ChType::Channel; @@ -71,8 +73,18 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { ; - let reply_parent_usr = if let Some(Some(reply)) = msg.source.tags.0.get("reply-thread-parent-user-login") { - Some(reply) + // let reply_parent_usr = if let Some(Some(reply)) = msg.source.tags.0.get("reply-thread-parent-user-login") { + // Some(reply) + // } else { None } + // ; + + let reply_parent_ts = if let Some(Some(replyts)) = msg.source.tags.0.get("tmi-sent-ts") { + + let a: i64 = replyts.parse().unwrap(); + let b = Local.timestamp_millis_opt(a).unwrap(); + // println!("Output : {}",b.to_string()); + // println!("Formatted : {}",b.format("%m-%d %H:%M") ); + Some(b.format("%m-%d %H:%M")) } else { None } ; @@ -150,14 +162,33 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { [ ] Get Target Channel - trgchnl */ + // reply_parent_ts let newoutmsg = if let Some(srcmsg) = reply_parent { - format!("{} from #{} says {} . Replying to: {} : {}", - msg.sender.name,msg.channel_login,outmsg, reply_parent_usr.unwrap(),srcmsg) + // format!("{} from #{} says {} . Replying to: {} : {}", + // msg.sender.name,msg.channel_login,outmsg, reply_parent_usr.unwrap(),srcmsg) + // format!("{} from #{} says {} @ {} {} : {}", + // msg.sender.name, + // msg.channel_login, + // outmsg, + // reply_parent_ts.unwrap(), + // reply_parent_usr.unwrap(), + // srcmsg) + format!("{} {} @ {} : {}", + reply_parent_ts.unwrap(), + msg.sender.name, + msg.channel_login, + srcmsg) } else { - format!("{} from #{} says : {}", - msg.sender.name,msg.channel_login, outmsg) + // format!("{} from #{} says : {}", + // msg.sender.name, + // msg.channel_login, + // outmsg) + format!("in {} - {} : {}", + msg.channel_login, + msg.sender.name, + outmsg) }; // uses chat.say_in_reply_to() for the bot controls for messages