diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index b0ef047..7823673 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -57,7 +57,7 @@ pub mod botlog { /* Module intends to add some layers to logging with the module user only requiring to pass : - String Log message - - Option - Code Module + - Option - Code_Module - Option - this is used to parse out Chatter & Channel into the logs */ @@ -66,28 +66,160 @@ pub mod botlog { // trace, debug, info, notice, warn, error, fatal - fn trace(in_msg:&str,module:Option,prvmsg:Option,) -> () { + pub fn trace(in_msg:&str,in_module:Option,in_prvmsg:Option<&PrivmsgMessage>) -> () + { + + let (chnl,chatter) = match in_prvmsg { + Some(prvmsg) => { + //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text)); + (Some(prvmsg.channel_login.clone()),Some(prvmsg.sender.name.clone())) // <-- Clone fine atm while we're just working with Strings + } + None => { + (None,None) + } + }; + + Log::trace_t( + in_msg, + casual_logger::Table::default() // + .str("Channel",&format!("{:?}",chnl)) + .str("Chatter",&format!("{:?}",chatter)) + .str("Code_Module",&format!("{:?}",in_module)) + ); } - fn debug(prvmsg:Option,in_msg:&str) -> () { + pub fn debug(in_msg:&str,in_module:Option,in_prvmsg:Option<&PrivmsgMessage>) -> () { + + let (chnl,chatter) = match in_prvmsg { + Some(prvmsg) => { + //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text)); + (Some(prvmsg.channel_login.clone()),Some(prvmsg.sender.name.clone())) // <-- Clone fine atm while we're just working with Strings + } + None => { + (None,None) + } + }; + + Log::debug_t( + in_msg, + casual_logger::Table::default() // + .str("Channel",&format!("{:?}",chnl)) + .str("Chatter",&format!("{:?}",chatter)) + .str("Code_Module",&format!("{:?}",in_module)) + ); } - fn info(prvmsg:Option,in_msg:&str) -> () { + pub fn info(in_msg:&str,in_module:Option,in_prvmsg:Option<&PrivmsgMessage>) -> () { + + let (chnl,chatter) = match in_prvmsg { + Some(prvmsg) => { + //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text)); + (Some(prvmsg.channel_login.clone()),Some(prvmsg.sender.name.clone())) // <-- Clone fine atm while we're just working with Strings + } + None => { + (None,None) + } + }; + + Log::info_t( + in_msg, + casual_logger::Table::default() // + .str("Channel",&format!("{:?}",chnl)) + .str("Chatter",&format!("{:?}",chatter)) + .str("Code_Module",&format!("{:?}",in_module)) + ); } - fn notice(prvmsg:Option,in_msg:&str) -> () { + pub fn notice(in_msg:&str,in_module:Option,in_prvmsg:Option<&PrivmsgMessage>) -> () { + + let (chnl,chatter) = match in_prvmsg { + Some(prvmsg) => { + //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text)); + (Some(prvmsg.channel_login.clone()),Some(prvmsg.sender.name.clone())) // <-- Clone fine atm while we're just working with Strings + } + None => { + (None,None) + } + }; + + Log::notice_t( + in_msg, + casual_logger::Table::default() // + .str("Channel",&format!("{:?}",chnl)) + .str("Chatter",&format!("{:?}",chatter)) + .str("Code_Module",&format!("{:?}",in_module)) + ); } - fn warn(prvmsg:Option,in_msg:&str) -> () { + pub fn warn(in_msg:&str,in_module:Option,in_prvmsg:Option<&PrivmsgMessage>) -> () { + + let (chnl,chatter) = match in_prvmsg { + Some(prvmsg) => { + //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text)); + (Some(prvmsg.channel_login.clone()),Some(prvmsg.sender.name.clone())) // <-- Clone fine atm while we're just working with Strings + } + None => { + (None,None) + } + }; + + Log::warn_t( + in_msg, + casual_logger::Table::default() // + .str("Channel",&format!("{:?}",chnl)) + .str("Chatter",&format!("{:?}",chatter)) + .str("Code_Module",&format!("{:?}",in_module)) + ); } - fn error(prvmsg:Option,in_msg:&str) -> () { + pub fn error(in_msg:&str,in_module:Option,in_prvmsg:Option<&PrivmsgMessage>) -> () { + let (chnl,chatter) = match in_prvmsg { + Some(prvmsg) => { + //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text)); + (Some(prvmsg.channel_login.clone()),Some(prvmsg.sender.name.clone())) // <-- Clone fine atm while we're just working with Strings + } + None => { + (None,None) + } + }; + + Log::error_t( + in_msg, + casual_logger::Table::default() // + .str("Channel",&format!("{:?}",chnl)) + .str("Chatter",&format!("{:?}",chatter)) + .str("Code_Module",&format!("{:?}",in_module)) + ); + + } + + pub fn fatal<'a>(in_msg:&'a str,in_module:Option,in_prvmsg:Option<&PrivmsgMessage>) -> &'a str { + + let (chnl,chatter) = match in_prvmsg { + Some(prvmsg) => { + //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text)); + (Some(prvmsg.channel_login.clone()),Some(prvmsg.sender.name.clone())) // <-- Clone fine atm while we're just working with Strings + } + None => { + (None,None) + } + }; + + Log::fatal_t( + in_msg, + casual_logger::Table::default() // + .str("Channel",&format!("{:?}",chnl)) + .str("Chatter",&format!("{:?}",chatter)) + .str("Code_Module",&format!("{:?}",in_module)) + ); + + in_msg } } @@ -156,10 +288,16 @@ impl Chat { self.client.say_in_reply_to(msg,outmsg).await.unwrap(); // println!("(#{}) > {}", msg.channel_login, "rate limit counter increase"); - Log::trace(&format!("(#{}) > {}", msg.channel_login, "rate limit counter increase")); + // Log::trace(&format!("(#{}) > {}", msg.channel_login, "rate limit counter increase")); + botlog::trace(&format!("(#{}) > {}", msg.channel_login, "rate limit counter increase"), + Some("Chat > say_in_reply_to".to_string()) , + Some(&msg)); contextratelimiter.increment_counter(); // println!("{:?}",self.ratelimiters); - Log::trace(&format!("{:?}",self.ratelimiters)); + // Log::trace(&format!("{:?}",self.ratelimiters)); + botlog::trace(&format!("{:?}",self.ratelimiters), + Some("Chat > say_in_reply_to".to_string()) , + Some(&msg)); }, ratelimiter::LimiterResp::Skip => { (); // do nothing otherwise @@ -328,36 +466,57 @@ impl BotInstance match &msg.channel_login { Some(chnl) => { // println!("NOTICE : (#{}) {}", chnl, msg.message_text) - Log::notice(&format!("NOTICE : (#{}) {}", chnl, msg.message_text)); + // Log::notice(&format!("NOTICE : (#{}) {}", chnl, msg.message_text)); + botlog::notice(&format!("NOTICE : (#{}) {}", chnl, msg.message_text), + Some("BotInstance > runner()".to_string()) , + None); }, None => { // println!("NOTICE : {}", msg.message_text); - Log::notice(&format!("NOTICE : {}", msg.message_text)); + // Log::notice(&format!("NOTICE : {}", msg.message_text)); + botlog::notice(&format!("NOTICE : {}", msg.message_text), + Some("BotInstance > runner()".to_string()) , + None); }, } } ServerMessage::Privmsg(msg) => { // println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); - Log::trace(&format!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text)); + // Log::trace(&format!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text)); + botlog::debug(&format!("Twitch Chat > {} @ #{}: {}", msg.channel_login, msg.sender.name, msg.message_text), + Some("BotInstance > runner()".to_string()) , + Some(&msg)); // println!("Privmsg section"); - Log::debug(&format!("Privmsg section")); + // Log::debug(&format!("Privmsg section")); + botlog::trace(&format!("Privmsg section"), + Some("BotInstance > runner()".to_string()) , + Some(&msg)); BotInstance::listener_main_prvmsg(Arc::clone(&bot), &msg).await; }, ServerMessage::Whisper(msg) => { // println!("(w) {}: {}", msg.sender.name, msg.message_text); - Log::trace(&format!("(w) {}: {}", msg.sender.name, msg.message_text)); + // Log::trace(&format!("(w) {}: {}", msg.sender.name, msg.message_text)); + botlog::trace(&format!("(w) {}: {}", msg.sender.name, msg.message_text), + Some("BotInstance > runner()".to_string()) , + None); }, ServerMessage::Join(msg) => { // println!("JOINED: {}", msg.channel_login); - Log::notice(&format!("JOINED: {}", msg.channel_login)); + // Log::notice(&format!("JOINED: {}", msg.channel_login)); + botlog::notice(&format!("JOINED: {}", msg.channel_login), + Some("BotInstance > runner()".to_string()) , + None); }, ServerMessage::Part(msg) => { // println!("PARTED: {}", msg.channel_login); - Log::notice(&format!("PARTED: {}", msg.channel_login)); + // Log::notice(&format!("PARTED: {}", msg.channel_login)); + botlog::notice(&format!("PARTED: {}", msg.channel_login), + Some("BotInstance > runner()".to_string()) , + None); }, _ => {} }; @@ -404,7 +563,10 @@ impl BotInstance pub async fn listener_main_prvmsg(bot:BotAR,msg:&PrivmsgMessage) -> () { // println!(">> Inner listenermain_prvmsg()"); - Log::trace(">> Inner listenermain_prvmsg()"); + // Log::trace(">> Inner listenermain_prvmsg()"); + botlog::trace(">> Inner listenermain_prvmsg()", + Some("BotInstance > listener_main_prvmsg()".to_string()) , + Some(&msg)); // let a = a; // println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); @@ -416,23 +578,35 @@ impl BotInstance // let hacts = hacts.read().await; let a = hacts.read().await; // println!("hacts size : {}",(*a).len()); - Log::debug(&format!("hacts size : {}",(*a).len())); + // Log::debug(&format!("hacts size : {}",(*a).len())); + botlog::trace(&format!("hacts size : {}",(*a).len()), + Some("BotInstance > listener_main_prvmsg()".to_string()) , + Some(&msg)); // println!(">> Inner listenermain_prvmsg() >> before for loop of bot actions"); - Log::trace(">> Inner listenermain_prvmsg() >> before for loop of bot actions"); + // Log::trace(">> Inner listenermain_prvmsg() >> before for loop of bot actions"); + botlog::trace(">> Inner listenermain_prvmsg() >> before for loop of bot actions", + Some("BotInstance > listener_main_prvmsg()".to_string()) , + Some(&msg)); for (_m,acts) in &*hacts.read().await { // println!(">> Inner listenermain_prvmsg() >> checking bot actions"); - Log::trace(">> Inner listenermain_prvmsg() >> checking bot actions"); - + // Log::trace(">> Inner listenermain_prvmsg() >> checking bot actions"); + botlog::trace(">> Inner listenermain_prvmsg() >> checking bot actions", + Some("BotInstance > listener_main_prvmsg()".to_string()) , + Some(&msg)); + // let bot = bot; for a in acts { // println!(">> Inner listenermain_prvmsg() >> checking bot actions >> 2"); - Log::trace(">> Inner listenermain_prvmsg() >> checking bot actions >> 2"); + // Log::trace(">> Inner listenermain_prvmsg() >> checking bot actions >> 2"); + botlog::trace(">> Inner listenermain_prvmsg() >> checking bot actions >> 2", + Some("BotInstance > listener_main_prvmsg()".to_string()) , + Some(&msg)); let _act = match a { @@ -452,9 +626,12 @@ impl BotInstance // } // println!("Reviewing internal commands"); - Log::trace("Reviewing internal commands"); + // Log::trace("Reviewing internal commands"); + botlog::trace("Reviewing internal commands", + Some("BotInstance > listener_main_prvmsg()".to_string()) , + Some(&msg)); - let inpt = msg.message_text.split("\n").next().expect("ERROR during BotCommand"); + // let inpt = msg.message_text.split("\n").next().expect("ERROR during BotCommand"); let inpt = msg.message_text.split(" ").next().expect("ERROR during BotCommand"); @@ -481,19 +658,35 @@ impl BotInstance if confirmed_bot_command { // println!("Confirmed bot command"); - Log::debug("Confirmed bot command"); + // Log::debug("Confirmed bot command"); + botlog::debug("Confirmed bot command", + Some("BotInstance > listener_main_prvmsg()".to_string()) , + Some(&msg)); // println!("Going for botlock"); - Log::trace("Going for botlock"); + // Log::trace("Going for botlock"); + botlog::trace("Going for botlock", + Some("BotInstance > listener_main_prvmsg()".to_string()) , + Some(&msg)); + let botlock = bot.read().await; // println!("Going for identity"); - Log::trace("Going for identity"); + // Log::trace("Going for identity"); + botlog::trace("Going for identity", + Some("BotInstance > listener_main_prvmsg()".to_string()) , + Some(&msg)); + let id = botlock.get_identity(); let eval = { let mut id = id.write().await; // println!("Unlocking identity"); - Log::trace("Unlocking identity"); + // Log::trace("Unlocking identity"); + botlog::trace("Unpacking identity", + Some("BotInstance > listener_main_prvmsg()".to_string()) , + Some(&msg)); + + let (a,b) = id.can_user_run_PRVMSG(&msg, c.required_roles.clone()).await; // // [-] #todo : need ot add functionality around here to do an o7 when a mod has been promoted => Preferring to do this outside the mutex // if let ChangeResult::Success(b) = b { @@ -507,33 +700,54 @@ impl BotInstance }; // println!("Checking if permissible"); Log::trace("Checking if permissible"); + botlog::trace("Checking if permissible", + Some("BotInstance > listener_main_prvmsg()".to_string()) , + Some(&msg)); let (eval , rolechange) = eval; if let ChangeResult::Success(b) = rolechange { if b.to_lowercase().contains(&"Auto Promoted Mod".to_lowercase()) { + botlog::notice("Assigning Mod UserRole to Mod", + Some("botinstance > listener_main_prvmsg()".to_string()), Some(&msg)); + + // println!("Read() lock Bot"); - Log::trace("Read() lock Bot"); + // Log::trace("Read() lock Bot"); + botlog::trace("Read() lock Bot", + Some("BotInstance > listener_main_prvmsg()".to_string()) , + Some(&msg)); + let botlock = bot.read().await; let outstr = "o7 a Mod. I kneel to serve! pepeKneel ".to_string(); (*botlock).botmgrs.chat.say_in_reply_to(msg, outstr).await; + } } match eval { Permissible::Allow => { // println!("Executed as permissible"); - Log::debug("Executed as permissible"); + // Log::debug("Executed as permissible"); + botlog::debug("Executed as permissible", + Some("BotInstance > listener_main_prvmsg()".to_string()) , + Some(&msg)); let a = Arc::clone(&bot); c.execute(a, msg.clone()).await; // println!("exit out of execution"); - Log::trace("exit out of execution"); + // Log::trace("exit out of execution"); + botlog::trace("exit out of execution", + Some("BotInstance > listener_main_prvmsg()".to_string()) , + Some(&msg)); } Permissible::Block => { // println!("User Not allowed to run command"); - Log::info("User Not allowed to run command"); + // Log::info("User Not allowed to run command"); + botlog::info("User Not allowed to run command", + Some("BotInstance > listener_main_prvmsg()".to_string()) , + Some(&msg)); }, // _ => (), }; @@ -558,7 +772,10 @@ impl BotInstance // // [ ] There should be a BotCommand Listener to check for prefixes ran // println!("End of Separate Listener Main prvmsg"); - Log::trace("End of Separate Listener Main prvmsg"); + // Log::trace("End of Separate Listener Main prvmsg"); + botlog::trace("End of Separate Listener Main prvmsg", + Some("BotInstance > listener_main_prvmsg()".to_string()) , + Some(&msg)); // self // bot diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 7075484..43af6d7 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -17,7 +17,7 @@ use tokio::sync::Mutex; -use crate::core::botinstance::{self, BotInstance}; +use crate::core::botinstance::{self, botlog, BotInstance}; use std::rc::Rc; // use tokio::sync::RwLock; @@ -201,14 +201,20 @@ impl BotActionTrait for Listener async fn add_to_bot(self, bot:BotInstance) { // println!("Adding action to bot"); - Log::trace("Adding action to bot"); + // Log::trace("Adding action to bot"); + botinstance::botlog::trace("Adding action to bot", + Some("BotModules > BotActionTrait > add_to_bot()".to_string()) , + None); self.add_to_modmgr(bot.botmodules).await; } async fn add_to_modmgr(self, modmgr:Arc) { // let modmgr = *modmgr.lock().await; // println!("Adding action to module manager"); - Log::trace("Adding action to module manager"); + // Log::trace("Adding action to module manager"); + botinstance::botlog::trace("Adding action to module manager", + Some("BotModules > BotActionTrait > add_to_bot()".to_string()) , + None); modmgr.add_botaction(self.module.clone(), BotAction::L(self)).await; } @@ -245,7 +251,11 @@ impl ModulesManager // :: [x] initialize core modules - println!("ModulesManager > init() > Adding modules"); + // println!("ModulesManager > init() > Adding modules"); + botlog::debug("ModulesManager > init() > Adding modules", + Some("ModulesManager > init()".to_string()), + None + ); let mgra = Arc::new(mgr); crate::core::identity::init(Arc::clone(&mgra)).await; @@ -254,7 +264,11 @@ impl ModulesManager - println!(">> Modules Manager : End of Init"); + // println!(">> Modules Manager : End of Init"); + botlog::trace(">> Modules Manager : End of Init", + Some("ModulesManager > init()".to_string()), + None + ); mgra } @@ -285,7 +299,14 @@ impl ModulesManager pub async fn add_botaction(&self, in_module:ModType, in_action:BotAction ) { - println!("Add botaction called"); + // println!("Add botaction called"); + + botlog::trace("Add botaction called", + Some("ModulesManager > init()".to_string()), + None + ); + + /* adds a BotAction to the Modules Manager - This will require a BotModule passed as well This will including the logic of a valid add @@ -426,8 +447,16 @@ impl ModulesManager // modactions.push(BotAction::L(newlistener)); modactions.push(in_action); - println!(">> Modules Manager : Called Add bot Action"); - println!("add_botaction - botactions size : {}",modactions.len()); + // println!(">> Modules Manager : Called Add bot Action"); + botlog::trace(">> Modules Manager : Called Add bot Action", + Some("ModulesManager > init()".to_string()), + None + ); + // println!("add_botaction - botactions size : {}",modactions.len()); + botlog::trace(&format!("add_botaction - botactions size : {}",modactions.len()), + Some("ModulesManager > init()".to_string()), + None + ); } diff --git a/src/core/identity.rs b/src/core/identity.rs index c02e269..a628aa6 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -34,7 +34,9 @@ fn adminvector() -> Vec { pub async fn init(mgr:Arc) { - println!("Went into Identiy Module init"); + // println!("Went into Identiy Module init"); + botinstance::botlog::trace("Went into Identiy Module init", + Some("identity.rs > init()".to_string()), None); // let a = actions_util::asyncbox(cmd_promote) ; @@ -57,7 +59,9 @@ pub async fn init(mgr:Arc) async fn cmd_promote(bot:BotAR,msg:PrivmsgMessage) -> () { //println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); - println!("Called cmd promote"); + // println!("Called cmd promote"); + botinstance::botlog::trace("Called cmd promote", + Some("identity.rs > cmd_prommote()".to_string()), Some(&msg)); // -- If the BotCommand.command was called (e.g., promote) & required roles were validated OUTSIDE of this call // , this is the current function body to execute @@ -87,7 +91,10 @@ pub async fn init(mgr:Arc) */ - println!("{}",msg.message_text); + // println!("{}",msg.message_text); + botinstance::botlog::trace(&format!("{}",msg.message_text), + Some("identity.rs > cmd_prommote()".to_string()), None); + let mut argv = msg.message_text.split(" "); argv.next(); // Skip the command name @@ -122,7 +129,10 @@ pub async fn init(mgr:Arc) // if let Some(a) = *ta { if a.contains(&UserRole::BotAdmin) { - println!("BotAdmin allowed to promote admin"); + // println!("BotAdmin allowed to promote admin"); + botinstance::botlog::debug("BotAdmin allowed to promote admin", + Some("identity.rs > cmd_prommote()".to_string()), Some(&msg)); + { let botlock = Arc::clone(&bot.read().await.get_identity()); @@ -184,8 +194,10 @@ pub async fn init(mgr:Arc) tempb.add_to_modmgr(Arc::clone(&mgr)).await; // async fn cmd_demote(mut _chat:Arc>,_msg:PrivmsgMessage) { - async fn cmd_demote(mut _chat:BotAR,_msg:PrivmsgMessage) { - println!("Called cmd demote"); + async fn cmd_demote(mut _chat:BotAR,msg:PrivmsgMessage) { + // println!("Called cmd demote"); + botinstance::botlog::debug("Called cmd demote", + Some("identity.rs > cmd_demote()".to_string()), Some(&msg)); } @@ -224,7 +236,9 @@ pub async fn init(mgr:Arc) // async fn getroles(bot:Arc>,msg:PrivmsgMessage) { async fn getroles(bot:BotAR,msg:PrivmsgMessage) { - println!("Called cmd getroles"); + // println!("Called cmd getroles"); + botinstance::botlog::debug("Called cmd getroles", + Some("identity.rs > cmd_getroles()".to_string()), Some(&msg)); /* Usage @@ -297,11 +311,17 @@ pub async fn init(mgr:Arc) // let a = a.lock().await; // let a = bot.get_identity(); let botlock = bot.read().await; - println!("botlock read"); + // println!("botlock read"); + botinstance::botlog::trace("botlock read", + Some("identity.rs > init > getroles()".to_string()), Some(&msg)); let idlock = botlock.get_identity(); - println!("got identity"); + // println!("got identity"); + botinstance::botlog::trace("got identity", + Some("identity.rs > init > getroles()".to_string()), Some(&msg)); let idlock = idlock.read().await; // <-- 02.12 - Latest where it gest stuck - before or at this point - println!("id lock"); + // println!("id lock"); + botinstance::botlog::trace("id lock", + Some("identity.rs > init > getroles()".to_string()), Some(&msg)); let sproles = match targetchnl { None => { // let bot = Rc::clone(&bot); @@ -334,7 +354,9 @@ pub async fn init(mgr:Arc) }; - println!("Retrieved User Roles >> {:?}",sproles); + // println!("Retrieved User Roles >> {:?}",sproles); + botinstance::botlog::debug(&format!("Retrieved User Roles >> {:?}",sproles), + Some("identity.rs > init > getroles()".to_string()), Some(&msg)); // let a = bot.identity.getuserroles(String::from("ModulatingForce"), Some(ChType::Channel(String::from("ModulatingForcebot")))); // println!("{:?}",a); @@ -343,7 +365,9 @@ pub async fn init(mgr:Arc) - println!("End of Init MOdule add"); + // println!("End of Init MOdule add"); + botinstance::botlog::trace("End of Init MOdule add", + Some("identity.rs > init ".to_string()), None); } @@ -416,7 +440,9 @@ impl IdentityManager { // println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); // [ ] Check what Badges in PrivmsgMessage - println!{"Checking within PRVMSG"}; + // println!{"Checking within PRVMSG"}; + botinstance::botlog::debug("Checking within PRVMSG", + Some("identity.rs > can_user_run_PRVMSG()".to_string()), Some(&msg)); let mut sender_badge:Option = None; @@ -486,7 +512,9 @@ impl IdentityManager { // ) -> Result> { ) -> (Permissible,ChangeResult) { - println!{"Checking within can_user_run()"}; + // println!{"Checking within can_user_run()"}; + botinstance::botlog::debug("Checking within can_user_run()", + Some("identity.rs > can_user_run()".to_string()), None); /* canUserRun - @@ -557,7 +585,9 @@ impl IdentityManager { ChatBadge::Mod => { - println!("Mod Chatbadge detected"); + // println!("Mod Chatbadge detected"); + botinstance::botlog::info("Mod Chatbadge detected", + Some("identity.rs > can_user_run()".to_string()), None); // println!("debug special roles : {:?}",self.special_roles_users); // println!("debug usr : {}",&usr.to_lowercase()); @@ -565,9 +595,16 @@ impl IdentityManager { // let Some((k,v)) = self.special_roles_users.get_key_value(usr); // match self.special_roles_users.get_mut(&usr.to_lowercase()) { // match self.special_roles_users.get(&usr.to_lowercase()) { - println!("Creating clone"); + // println!("Creating clone"); + botinstance::botlog::trace("Creating clone", + Some("identity.rs > can_user_run()".to_string()), None); + let roleslock = Arc::clone(&(*self).special_roles_users); - println!("Read lock on : Special_Roles_User"); // <-- after this is slightly different between working and problem + + // println!("Read lock on : Special_Roles_User"); // <-- after this is slightly different between working and problem + botinstance::botlog::trace("Read lock on : Special_Roles_User", + Some("identity.rs > can_user_run()".to_string()), None); + let mut roleslock = roleslock.write().await; match (*roleslock).get(&usr.to_lowercase()) { Some(usrroles) if @@ -577,12 +614,20 @@ impl IdentityManager { // println!("contains supmod : {}", usrroles.read().await.contains(&UserRole::SupMod(channelname.clone()))); // Do nothing when theh have a mod badge and have either a supmod or mod badge for the channel - println!("Already a mod in roles"); + // println!("Already a mod in roles"); + botinstance::botlog::trace("Already a mod in roles", + Some("identity.rs > can_user_run()".to_string()), None); } _ => { // In the event they have a mod badge , are running a bot command, but don't have a channel mod role yet... - println!("lock created > adding with a mod role o7"); + // println!("lock created > adding with a mod role o7"); + botinstance::botlog::trace("lock created > adding with a mod role o7", + Some("identity.rs > can_user_run()".to_string()), None); + + // botinstance::botlog::notice("Assigning ModRole to Chatter", + // Some("identity.rs > can_user_run()".to_string()), None); + let mut roleslock = roleslock; let mut a = roleslock.get_mut(&usr.to_lowercase()).unwrap(); let mut alock = a.write().await; @@ -607,7 +652,9 @@ impl IdentityManager { // [x] If cmdreqroles includes UserRole::Mod("") , checks if chatter has UserRole::Mod(channelname::ChType) or UserRole::SupMod(channelname::ChType) to determine if Ok(Permissible::Allow) - println!("cmd required roles : {:?}",cmdreqroles); + // println!("cmd required roles : {:?}",cmdreqroles); + botinstance::botlog::trace(&format!("cmd required roles : {:?}",cmdreqroles), + Some("identity.rs > can_user_run()".to_string()), None); if cmdreqroles.contains(&UserRole::Mod(ChType::Channel(String::new()))) { // match self.special_roles_users.get(&channelname) { @@ -616,13 +663,20 @@ impl IdentityManager { // } - println!("Mod Role required"); + // println!("Command requires Mod Role"); + botinstance::botlog::trace("Command requires Mod Role", + Some("identity.rs > can_user_run()".to_string()), None); if let Some(a) = (&*self).special_roles_users.read().await.get(&usr.to_lowercase()) { - println!("Special roles found for user"); + // println!("Special roles found for user"); + botinstance::botlog::trace("Special roles found for user", + Some("identity.rs > can_user_run()".to_string()), None); + if a.read().await.contains(&UserRole::Mod(channelname.clone())) || a.read().await.contains(&UserRole::SupMod(channelname.clone())){ // return Ok(Permissible::Allow); - println!("Special roles found for user : A mod idenfified "); + // println!("Special roles found for user : A mod idenfified "); + botinstance::botlog::trace("> Special Role Identified : Mod ", + Some("identity.rs > can_user_run()".to_string()), None); return (Permissible::Allow , modrolechange) } } @@ -644,12 +698,22 @@ impl IdentityManager { // [x] If cmdreqroles includes UserRole::BotAdmin and chatter has UserRole::BotAdmin , Ok(Permissible::Allow) - println!("Eval cmdreqroles with botadmin : {}",cmdreqroles.contains(&UserRole::BotAdmin)); + // println!("Eval cmdreqroles with botadmin : {}",cmdreqroles.contains(&UserRole::BotAdmin)); + botinstance::botlog::trace(&format!("Eval cmdreqroles with botadmin : {}",cmdreqroles.contains(&UserRole::BotAdmin)), + Some("identity.rs > can_user_run()".to_string()), None); if cmdreqroles.contains(&UserRole::BotAdmin) { - println!("special roles get : {:?}",(&*self).special_roles_users.read().await.get(&usr.to_lowercase())); + // println!("special roles get : {:?}",(&*self).special_roles_users.read().await.get(&usr.to_lowercase())); + botinstance::botlog::trace(&format!("special roles get : {:?}",(&*self).special_roles_users.read().await.get(&usr.to_lowercase())), + Some("identity.rs > can_user_run()".to_string()), None); + + + if let Some(a) = (&*self).special_roles_users.read().await.get(&usr.to_lowercase()) { println!("special roles contains BotAdmin: {}",a.read().await.contains(&UserRole::BotAdmin)); + botinstance::botlog::trace(&format!("special roles contains BotAdmin: {}",a.read().await.contains(&UserRole::BotAdmin)), + Some("identity.rs > can_user_run()".to_string()), None); + if a.read().await.contains(&UserRole::BotAdmin) { // return Ok(Permissible::Allow); return (Permissible::Allow,modrolechange) diff --git a/src/main.rs b/src/main.rs index 07e4a13..316483e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use std::process::Output; use crate::core::botinstance::ArcBox; -use crate::core::botinstance::BotInstance; +use crate::core::botinstance::{self,BotInstance}; use casual_logger::Extension; use tokio::sync::RwLock; use std::sync::Arc; @@ -23,7 +23,8 @@ pub async fn main() { let bot = BotInstance::init().await; - Log::debug("Checking bot actions"); + // Log::debug("Checking bot actions"); + botinstance::botlog::debug("Checking bot actions", Some("main()".to_string()), None); let a = Arc::clone(&bot.botmodules.botactions); let a = a.read().await; // let a = *a; @@ -33,15 +34,18 @@ pub async fn main() { match act { crate::core::botmodules::BotAction::C(b) => { // println!("bot actiions: {}",b.command) - Log::info(&format!("bot actions: {}",b.command)); + // Log::info(&format!("bot actions: {}",b.command)); + botinstance::botlog::info(&format!("bot actions: {}",b.command), Some("main()".to_string()), None); }, crate::core::botmodules::BotAction::L(l) => { // println!("bot actiions: {}",l.name) - Log::info(&format!("bot actions: {}",l.name)); + // Log::info(&format!("bot actions: {}",l.name)); + botinstance::botlog::info(&format!("bot actions: {}",l.name), Some("main()".to_string()), None); }, _ => { // println!("Not a valid match??") - Log::info("Not a valid match??"); + // Log::info("Not a valid match??"); + botinstance::botlog::info("Not a valid match??", Some("main()".to_string()), None); }, } @@ -49,7 +53,9 @@ pub async fn main() { }; // println!("Starting runner.."); - Log::notice("Starting Bot Runner"); + // Log::notice("Starting Bot Runner"); + botinstance::botlog::notice("Starting Bot Runner", Some("main()".to_string()), None); + println!("Starting Bot Runner"); Log::flush(); @@ -57,6 +63,8 @@ pub async fn main() { // println!("ERROR : EXIT Game loop"); // let msg = Log::fatal("ERROR : EXIT Game loop"); - panic!("{}",Log::fatal("ERROR : EXIT Game loop")); + // panic!("{}",Log::fatal("ERROR : EXIT Game loop")); + let a = botinstance::botlog::fatal("ERROR : EXIT Game loop", Some("main()".to_string()), None); + panic!("{}",a); } \ No newline at end of file diff --git a/src/modules/experiments.rs b/src/modules/experiments.rs index f63192c..2c4a4e2 100644 --- a/src/modules/experiments.rs +++ b/src/modules/experiments.rs @@ -79,7 +79,13 @@ pub async fn init(mgr:Arc) async fn good_girl(mut bot:BotAR,msg:PrivmsgMessage) { - println!("In GoodGirl() Listener"); + // println!("In GoodGirl() Listener"); + // Change below from debug to trace if required later + botinstance::botlog::debug("In GoodGirl() Listener", + Some("experiments > goodgirl()".to_string()) , + Some(&msg)); + + //println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); // [ ] Uses gen_ratio() to output bool based on a ratio probability . @@ -91,10 +97,16 @@ async fn good_girl(mut bot:BotAR,msg:PrivmsgMessage) { // chat.say_in_reply_to(&msg,String::from("GoodGirl")).await; //if rng.gen_ratio(1,5) { - println!("In GoodGirl() > Pausechamp"); + // println!("In GoodGirl() > Pausechamp"); + botinstance::botlog::debug("In GoodGirl() > Pausechamp", + Some("experiments > goodgirl()".to_string()) , + Some(&msg)); let rollwin = rand::thread_rng().gen_ratio(1,8); if rollwin { - println!("In GoodGirl() > Win"); + // println!("In GoodGirl() > Win"); + botinstance::botlog::debug("In GoodGirl() > Win", + Some("experiments > goodgirl()".to_string()) , + Some(&msg)); let a = Arc::clone(&bot); let botlock = a.read().await; botlock.botmgrs.chat.say_in_reply_to(&msg, String::from("GoodGirl xdd ")).await; @@ -106,8 +118,11 @@ async fn good_girl(mut bot:BotAR,msg:PrivmsgMessage) } -async fn testy(mut _chat:BotAR,_msg:PrivmsgMessage) +async fn testy(mut _chat:BotAR,msg:PrivmsgMessage) { - println!("testy triggered!") + println!("testy triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call + botinstance::botlog::debug("testy triggered!", + Some("experiments > testy()".to_string()) , + Some(&msg)); } \ No newline at end of file