diff --git a/src/core.rs b/src/core.rs index ef71070..51e40d0 100644 --- a/src/core.rs +++ b/src/core.rs @@ -1,4 +1,5 @@ pub mod botinstance; +pub mod botlog; pub mod botmodules; pub mod identity; pub mod ratelimiter; diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index a00f6e1..9225e48 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -1,15 +1,14 @@ - -use std::sync::Arc; -use std::env; use std::collections::HashMap; +use std::env; +use std::sync::Arc; use tokio::sync::mpsc::UnboundedReceiver; -use tokio::sync::{RwLock,Mutex}; +use tokio::sync::{Mutex, RwLock}; use twitch_irc::login::StaticLoginCredentials; -use twitch_irc::message::{PrivmsgMessage,ServerMessage}; -use twitch_irc::transport::tcp::{TCPTransport,TLS}; -use twitch_irc::{ClientConfig,SecureTCPTransport,TwitchIRCClient}; +use twitch_irc::message::{PrivmsgMessage, ServerMessage}; +use twitch_irc::transport::tcp::{TCPTransport, TLS}; +use twitch_irc::{ClientConfig, SecureTCPTransport, TwitchIRCClient}; use dotenv::dotenv; @@ -20,189 +19,188 @@ use rand::Rng; use crate::core::ratelimiter; use crate::core::ratelimiter::RateLimiter; -use crate::core::botmodules::ModulesManager; use crate::core::botmodules::bot_actions::actions_util::BotAR; +use crate::core::botmodules::ModulesManager; use crate::core::identity::{ChangeResult, IdentityManager, Permissible}; +use crate::core::botlog; -pub mod botlog { +// 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 - this is used to parse out Chatter & Channel into the logs - */ +// /* +// Module intends to add some layers to logging with the module user only requiring to pass : +// - String Log message +// - Option - Code_Module +// - Option - this is used to parse out Chatter & Channel into the logs +// */ +// // use casual_logger::{Level, Log}; +// use casual_logger::Log; +// use twitch_irc::message::PrivmsgMessage; - // use casual_logger::{Level, Log}; - use casual_logger::Log; - use twitch_irc::message::PrivmsgMessage; +// // trace, debug, info, notice, warn, error, fatal - // trace, debug, info, notice, warn, error, fatal +// /* - /* +// in main : Log::debug("Checking bot actions", Some("main()".to_string()), None); - in main : Log::debug("Checking bot actions", Some("main()".to_string()), None); +// in log : +// [blalba@timestmp] +// debug = "Checking bot actions", - in log : - [blalba@timestmp] - debug = "Checking bot actions", +// */ +// 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)), +// ); +// } - 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), - }; +// 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::trace_t( - in_msg, - casual_logger::Table::default() // - .str("Channel", &format!("{:?}", chnl)) - .str("Chatter", &format!("{:?}", chatter)) - .str("Code_Module", &format!("{:?}", in_module)), - ); - } +// Log::debug_t( +// in_msg, +// casual_logger::Table::default() // +// .str("Channel", &format!("{:?}", chnl)) +// .str("Chatter", &format!("{:?}", chatter)) +// .str("Code_Module", &format!("{:?}", in_module)), +// ); +// } - 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), - }; +// 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::debug_t( - in_msg, - casual_logger::Table::default() // - .str("Channel", &format!("{:?}", chnl)) - .str("Chatter", &format!("{:?}", chatter)) - .str("Code_Module", &format!("{:?}", in_module)), - ); - } +// Log::info_t( +// in_msg, +// casual_logger::Table::default() // +// .str("Channel", &format!("{:?}", chnl)) +// .str("Chatter", &format!("{:?}", chatter)) +// .str("Code_Module", &format!("{:?}", in_module)), +// ); +// } - 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), - }; +// 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::info_t( - in_msg, - casual_logger::Table::default() // - .str("Channel", &format!("{:?}", chnl)) - .str("Chatter", &format!("{:?}", chatter)) - .str("Code_Module", &format!("{:?}", in_module)), - ); - } +// Log::notice_t( +// in_msg, +// casual_logger::Table::default() // +// .str("Channel", &format!("{:?}", chnl)) +// .str("Chatter", &format!("{:?}", chatter)) +// .str("Code_Module", &format!("{:?}", in_module)), +// ); +// } - 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), - }; +// 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::notice_t( - in_msg, - casual_logger::Table::default() // - .str("Channel", &format!("{:?}", chnl)) - .str("Chatter", &format!("{:?}", chatter)) - .str("Code_Module", &format!("{:?}", in_module)), - ); - } +// Log::warn_t( +// in_msg, +// casual_logger::Table::default() // +// .str("Channel", &format!("{:?}", chnl)) +// .str("Chatter", &format!("{:?}", chatter)) +// .str("Code_Module", &format!("{:?}", in_module)), +// ); +// } - 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), - }; +// 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::warn_t( - in_msg, - casual_logger::Table::default() // - .str("Channel", &format!("{:?}", chnl)) - .str("Chatter", &format!("{:?}", chatter)) - .str("Code_Module", &format!("{:?}", in_module)), - ); - } +// 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 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), - }; +// 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::error_t( - in_msg, - casual_logger::Table::default() // - .str("Channel", &format!("{:?}", chnl)) - .str("Chatter", &format!("{:?}", chatter)) - .str("Code_Module", &format!("{:?}", in_module)), - ); - } +// Log::fatal_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 - } -} +// in_msg +// } +// } #[derive(Debug, PartialEq, Eq, Hash, Clone)] pub enum ChType { diff --git a/src/core/botlog.rs b/src/core/botlog.rs new file mode 100644 index 0000000..27272d2 --- /dev/null +++ b/src/core/botlog.rs @@ -0,0 +1,175 @@ +/* + Module intends to add some layers to logging with the module user only requiring to pass : + - String Log message + - Option - Code_Module + - Option - this is used to parse out Chatter & Channel into the logs +*/ + +// use casual_logger::{Level, Log}; +use casual_logger::Log; +use twitch_irc::message::PrivmsgMessage; + +// trace, debug, info, notice, warn, error, fatal + +/* + +in main : Log::debug("Checking bot actions", Some("main()".to_string()), None); + +in log : +[blalba@timestmp] +debug = "Checking bot actions", + +*/ + +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)), + ); +} + +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)), + ); +} + +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)), + ); +} + +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)), + ); +} + +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)), + ); +} + +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 +} diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 269985a..e30b567 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -15,7 +15,9 @@ use tokio::sync::RwLock; // Important to use tokios Mutex here since std Mutex doesn't work with async functions // use tokio::sync::Mutex; -use crate::core::botinstance::{self, botlog, BotInstance}; +use crate::core::botinstance::{self, BotInstance}; +use crate::core::botlog; + // use std::rc::Rc; // use tokio::sync::RwLock; @@ -185,7 +187,7 @@ impl BotActionTrait for Listener { async fn add_to_bot(self, bot: BotInstance) { // println!("Adding action to bot"); // Log::trace("Adding action to bot"); - botinstance::botlog::trace( + botlog::trace( "Adding action to bot", Some("BotModules > BotActionTrait > add_to_bot()".to_string()), None, @@ -197,7 +199,7 @@ impl BotActionTrait for Listener { // let modmgr = *modmgr.lock().await; // println!("Adding action to module manager"); // Log::trace("Adding action to module manager"); - botinstance::botlog::trace( + botlog::trace( "Adding action to module manager", Some("BotModules > BotActionTrait > add_to_bot()".to_string()), None, diff --git a/src/core/identity.rs b/src/core/identity.rs index 1271630..d967e53 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -7,7 +7,8 @@ use crate::core::botmodules::bot_actions::actions_util; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager}; // use crate::core::botinstance::{self, botlog, BotInstance, ChType}; -use crate::core::botinstance::{self, ChType}; +use crate::core::botinstance::ChType; +use crate::core::botlog; // use futures::lock::Mutex; // use twitch_irc::message::{Badge, PrivmsgMessage}; use twitch_irc::message::PrivmsgMessage; @@ -34,7 +35,7 @@ fn adminvector() -> Vec { // pub fn init(mgr:&mut ModulesManager) pub async fn init(mgr: Arc) { // println!("Went into Identiy Module init"); - botinstance::botlog::trace( + botlog::trace( "Went into Identiy Module init", Some("identity.rs > init()".to_string()), None, @@ -61,7 +62,7 @@ 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"); - botinstance::botlog::trace( + botlog::trace( "Called cmd promote", Some("identity.rs > cmd_prommote()".to_string()), Some(&msg), @@ -94,7 +95,7 @@ pub async fn init(mgr: Arc) { */ // println!("{}",msg.message_text); - botinstance::botlog::trace( + botlog::trace( &format!("Twich Message > {}", msg.message_text), Some("identity.rs > cmd_promote()".to_string()), None, @@ -144,7 +145,7 @@ pub async fn init(mgr: Arc) { let rslt = match targetusr { Some(targetusr) => { - botinstance::botlog::debug( + botlog::debug( // &format!("running promote()"), "running promote()", Some("identity.rs > cmd_promote()".to_string()), @@ -170,7 +171,7 @@ pub async fn init(mgr: Arc) { } None => { - botinstance::botlog::debug( + botlog::debug( // &format!("No Targer User argument"), "No Targer User argument", Some("identity.rs > cmd_demote()".to_string()), @@ -188,7 +189,7 @@ pub async fn init(mgr: Arc) { ChangeResult::Success(a) => { // println!("Succesfully promoted : {a} ;"); let outmsg = &format!("o7 Successfully promoted : {a}"); - botinstance::botlog::debug( + botlog::debug( outmsg, Some("identity.rs > cmd_prommote()".to_string()), Some(&msg), @@ -203,7 +204,7 @@ pub async fn init(mgr: Arc) { ChangeResult::Failed(a) => { // println!("Failed to promote : {a} ; "); let outmsg = &format!("PoroSad failed to promote : {a}"); - botinstance::botlog::debug( + botlog::debug( outmsg, Some("identity.rs > cmd_prommote()".to_string()), Some(&msg), @@ -218,7 +219,7 @@ pub async fn init(mgr: Arc) { ChangeResult::NoChange(a) => { // println!("No Changes Made : {a} ; "); let outmsg = &format!("uuh No Promotion Change : {a}"); - botinstance::botlog::debug( + botlog::debug( outmsg, Some("identity.rs > cmd_prommote()".to_string()), Some(&msg), @@ -486,7 +487,7 @@ pub async fn init(mgr: Arc) { */ - botinstance::botlog::trace( + botlog::trace( // &format!("End of cmd_promote()"), "End of cmd_promote()", Some("identity.rs > cmd_prommote()".to_string()), @@ -527,7 +528,7 @@ pub async fn init(mgr: Arc) { // async fn cmd_demote(mut _chat:Arc>,_msg:PrivmsgMessage) { async fn cmd_demote(bot: BotAR, msg: PrivmsgMessage) { // println!("Called cmd demote"); - botinstance::botlog::debug( + botlog::debug( "Called cmd demote", Some("identity.rs > cmd_demote()".to_string()), Some(&msg), @@ -669,7 +670,7 @@ pub async fn init(mgr: Arc) { let rslt = match targetusr { Some(targetusr) => { - botinstance::botlog::debug( + botlog::debug( // &format!("running demote()"), "running demote()", Some("identity.rs > cmd_demote()".to_string()), @@ -688,7 +689,7 @@ pub async fn init(mgr: Arc) { } None => { - botinstance::botlog::debug( + botlog::debug( // &format!("No Targer User argument"), "No Targer User argument", Some("identity.rs > cmd_demote()".to_string()), @@ -746,7 +747,7 @@ pub async fn init(mgr: Arc) { ChangeResult::Success(a) => { // println!("Succesfully promoted : {a} ;"); let outmsg = &format!("o7 Successfully demoted : {a}"); - botinstance::botlog::debug( + botlog::debug( outmsg, Some("identity.rs > cmd_demote()".to_string()), Some(&msg), @@ -761,7 +762,7 @@ pub async fn init(mgr: Arc) { ChangeResult::Failed(a) => { // println!("Failed to promote : {a} ; "); let outmsg = &format!("PoroSad failed to demote : {a}"); - botinstance::botlog::debug( + botlog::debug( outmsg, Some("identity.rs > cmd_demote()".to_string()), Some(&msg), @@ -776,7 +777,7 @@ pub async fn init(mgr: Arc) { ChangeResult::NoChange(a) => { // println!("No Changes Made : {a} ; "); let outmsg = &format!("uuh No Demotion Change : {a}"); - botinstance::botlog::debug( + botlog::debug( outmsg, Some("identity.rs > cmd_demote()".to_string()), Some(&msg), @@ -813,7 +814,7 @@ pub async fn init(mgr: Arc) { // async fn getroles(bot:Arc>,msg:PrivmsgMessage) { async fn getroles(bot: BotAR, msg: PrivmsgMessage) { // println!("Called cmd getroles"); - botinstance::botlog::debug( + botlog::debug( "Called cmd getroles", Some("identity.rs > cmd_getroles()".to_string()), Some(&msg), @@ -888,21 +889,21 @@ pub async fn init(mgr: Arc) { // let a = bot.get_identity(); let botlock = bot.read().await; // println!("botlock read"); - botinstance::botlog::trace( + botlog::trace( "botlock read", Some("identity.rs > init > getroles()".to_string()), Some(&msg), ); let idlock = botlock.get_identity(); // println!("got identity"); - botinstance::botlog::trace( + 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"); - botinstance::botlog::trace( + botlog::trace( "id lock", Some("identity.rs > init > getroles()".to_string()), Some(&msg), @@ -1003,7 +1004,7 @@ pub async fn init(mgr: Arc) { // let sproles = idlock.getspecialuserroles(String::from(targetuser),).await; // println!("Retrieved User Roles >> {:?}",sproles); - botinstance::botlog::debug( + botlog::debug( &format!("User roles of Target Chatter >> {:?}", sproles), Some("identity.rs > init > getroles()".to_string()), Some(&msg), @@ -1011,7 +1012,7 @@ pub async fn init(mgr: Arc) { // # I believe at this stage I still have botlock active - botinstance::botlog::debug( + botlog::debug( // &format!("Evaluating special roles"), "Evaluating special roles", Some("identity.rs > init > getroles()".to_string()), @@ -1091,7 +1092,7 @@ pub async fn init(mgr: Arc) { // let a = bot.identity.getuserroles(String::from("ModulatingForce"), Some(ChType::Channel(String::from("ModulatingForcebot")))); // println!("{:?}",a); - botinstance::botlog::debug( + botlog::debug( &format!("Chat Say Reply message : {:?}", outmsg), Some("identity.rs > init > getroles()".to_string()), Some(&msg), @@ -1102,7 +1103,7 @@ pub async fn init(mgr: Arc) { } // println!("End of Init MOdule add"); - botinstance::botlog::trace( + botlog::trace( "End of Init MOdule add", Some("identity.rs > init ".to_string()), None, @@ -1215,7 +1216,7 @@ impl IdentityManager { srulock .entry(trgchatter.clone()) .or_insert(Arc::new(RwLock::new(vec![]))); - botinstance::botlog::trace( + botlog::trace( &format!( "Ensuring User in Roles {:?}", srulock.entry(trgchatter.clone()) @@ -1240,7 +1241,7 @@ impl IdentityManager { // [ ] Check what Badges in PrivmsgMessage // println!{"Checking within PRVMSG"}; - botinstance::botlog::debug( + botlog::debug( "Checking within PRVMSG", Some("identity.rs > can_user_run_PRVMSG()".to_string()), // Some(&msg), @@ -1327,7 +1328,7 @@ impl IdentityManager { cmdreqroles: Vec, // ) -> Result> { ) -> (Permissible, ChangeResult) { // println!{"Checking within can_user_run()"}; - botinstance::botlog::debug( + botlog::debug( &format!( "Checking within can_user_run() : usr : {} ; channel : {:?} ; badge : {:?} ; cmdreqroles : {:?}", @@ -1410,7 +1411,7 @@ impl IdentityManager { // [x] If not, assign them UserRole::Mod(channelname::ChType) Some(ChatBadge::Mod) => { // println!("Mod Chatbadge detected"); - botinstance::botlog::info( + botlog::info( "Mod Chatbadge detected", Some("identity.rs > can_user_run()".to_string()), None, @@ -1423,7 +1424,7 @@ impl IdentityManager { // match self.special_roles_users.get_mut(&usr.to_lowercase()) { // match self.special_roles_users.get(&usr.to_lowercase()) { // println!("Creating clone"); - botinstance::botlog::trace( + botlog::trace( "Creating arc clone", Some("identity.rs > can_user_run()".to_string()), None, @@ -1433,7 +1434,7 @@ impl IdentityManager { let roleslock = Arc::clone(&self.special_roles_users); // println!("Read lock on : Special_Roles_User"); // <-- after this is slightly different between working and problem - botinstance::botlog::trace( + botlog::trace( "Read lock on : Special_Roles_User", Some("identity.rs > can_user_run()".to_string()), None, @@ -1468,7 +1469,7 @@ impl IdentityManager { // 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"); - botinstance::botlog::trace( + botlog::trace( "Already a mod in roles", Some("identity.rs > can_user_run()".to_string()), None, @@ -1477,13 +1478,13 @@ impl IdentityManager { _ => { // 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"); - botinstance::botlog::trace( + 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", + // botlog::notice("Assigning ModRole to Chatter", // Some("identity.rs > can_user_run()".to_string()), None); let mut roleslock = roleslock; @@ -1510,7 +1511,7 @@ 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); - botinstance::botlog::trace( + botlog::trace( &format!("cmd required roles : {:?}", cmdreqroles), Some("identity.rs > can_user_run()".to_string()), None, @@ -1524,7 +1525,7 @@ impl IdentityManager { // } // println!("Command requires Mod Role"); - botinstance::botlog::trace( + botlog::trace( "Command requires Mod Role", Some("identity.rs > can_user_run()".to_string()), None, @@ -1542,7 +1543,7 @@ impl IdentityManager { .get(&usr.to_lowercase()) { // println!("Special roles found for user"); - botinstance::botlog::trace( + botlog::trace( "Special roles found for user", Some("identity.rs > can_user_run()".to_string()), None, @@ -1555,7 +1556,7 @@ impl IdentityManager { { // return Ok(Permissible::Allow); // println!("Special roles found for user : A mod idenfified "); - botinstance::botlog::trace( + botlog::trace( "> Special Role Identified : Mod ", Some("identity.rs > can_user_run()".to_string()), None, @@ -1592,7 +1593,7 @@ 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)); - botinstance::botlog::trace( + botlog::trace( &format!( "Eval cmdreqroles with botadmin : {}", cmdreqroles.contains(&UserRole::BotAdmin) @@ -1603,7 +1604,7 @@ impl IdentityManager { if cmdreqroles.contains(&UserRole::BotAdmin) { // println!("special roles get : {:?}",(&*self).special_roles_users.read().await.get(&usr.to_lowercase())); - botinstance::botlog::trace( + botlog::trace( &format!( "special roles get : {:?}", // (&*self) @@ -1631,7 +1632,7 @@ impl IdentityManager { "special roles contains BotAdmin: {}", a.read().await.contains(&UserRole::BotAdmin) ); - botinstance::botlog::trace( + botlog::trace( &format!( "special roles contains BotAdmin: {}", a.read().await.contains(&UserRole::BotAdmin) @@ -1662,7 +1663,7 @@ impl IdentityManager { channel: Option, trg_role: Option, ) -> ChangeResult { - botinstance::botlog::trace( + botlog::trace( &format!( "IN VARS for promote() : auth : {} ; authbadge : {:?} ; trg : {} ; Channel {:?} ; {:?}", authorizer,authorizer_badge,trgchatter,channel,trg_role), @@ -1929,7 +1930,7 @@ impl IdentityManager { // Some("identity.rs > promote()".to_string()), // None, // ); - botinstance::botlog::warn( + botlog::warn( "Code Warning : add handing for other trgusrroles", Some("identity.rs > promote()".to_string()), None, @@ -2265,7 +2266,7 @@ impl IdentityManager { // Some("identity.rs > promote()".to_string()), // None, // ); - botinstance::botlog::warn( + botlog::warn( "Runtime reached undeveloped code", Some("identity.rs > promote()".to_string()), None, @@ -2283,7 +2284,7 @@ impl IdentityManager { ) -> ChangeResult { // botinstance::botlog::trace(&format!("IN VARS for demote() : Authorizer : {:?} ; Target Chatter : {} ; Target Channel : {:?} ; Targer Role {:?}", // authorizer,trgchatter,channel,trg_role), - botinstance::botlog::trace(&format!("IN VARS for demote() : Authorizer : {:?} ; Target Chatter : {} ; Target Channel : {:?}", + botlog::trace(&format!("IN VARS for demote() : Authorizer : {:?} ; Target Chatter : {} ; Target Channel : {:?}", authorizer,trgchatter,channel), Some("identity.rs > demote()".to_string()), None); Log::flush(); @@ -2403,7 +2404,7 @@ impl IdentityManager { // botinstance::botlog::warn(&format!("Potential Unhandled Demotion Condition : Consider explicitely adding in for better handling"), // Some("identity.rs > demote()".to_string()), None); - botinstance::botlog::warn("Potential Unhandled Demotion Condition : Consider explicitely adding in for better handling", + botlog::warn("Potential Unhandled Demotion Condition : Consider explicitely adding in for better handling", Some("identity.rs > demote()".to_string()), None); Log::flush(); ChangeResult::Failed(String::from("Did not meet criteria to demote succesfully")) @@ -2420,7 +2421,7 @@ impl IdentityManager { */ // [ ] !!! TODO: I don't think below is evaluating by given channel - botinstance::botlog::debug( + botlog::debug( &format!( "IN VARS > chattername {} ; channel {:?}", chattername, channel @@ -2467,14 +2468,14 @@ impl IdentityManager { Some(channel) => { // let eval = a.read().await.contains(&UserRole::Mod(channel)); // let eval = a.read().await.contains(&UserRole::SupMod(channel)); - botinstance::botlog::debug( + botlog::debug( &format!("INTERNAL > All Roles found {:?}", &a), Some("IdentityManager > getspecialuserroles()".to_string()), None, ); // a.read().await.contains(&UserRole::BotAdmin) - botinstance::botlog::trace( + botlog::trace( &format!( "INTERNAL > eval special roles contains botadmin : {:?}", a.read().await.contains(&UserRole::BotAdmin) @@ -2514,7 +2515,7 @@ impl IdentityManager { } } - botinstance::botlog::debug( + botlog::debug( &format!("OUT > evalsproles {:?}", &evalsproles), Some("IdentityManager > getspecialuserroles()".to_string()), None, diff --git a/src/core/ratelimiter.rs b/src/core/ratelimiter.rs index 5e99a5a..b43abba 100644 --- a/src/core/ratelimiter.rs +++ b/src/core/ratelimiter.rs @@ -12,7 +12,7 @@ pub struct RateLimiter { pub enum LimiterResp { Allow, // when it's evaluated to be within limits Skip, // as outside of rate limits - // Enqueue, // [FUTURE] + // Enqueue, // [FUTURE] } impl Default for RateLimiter { diff --git a/src/main.rs b/src/main.rs index 1e53b43..d632453 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,8 @@ use tokio::sync::RwLock; use casual_logger::{Extension, Level, Log}; -use bot_lib::core::botinstance::{BotInstance,botlog}; +use bot_lib::core::botinstance::BotInstance; +use bot_lib::core::botlog; use bot_lib::core::botmodules; pub type BotAR = Arc>; @@ -48,7 +49,6 @@ pub async fn main() { bot.runner().await; - let pstr = - botlog::fatal("ERROR : EXIT Game loop", Some("main()".to_string()), None); + let pstr = botlog::fatal("ERROR : EXIT Game loop", Some("main()".to_string()), None); panic!("{}", pstr); } diff --git a/src/modules.rs b/src/modules.rs index c9eeaa9..fc802e6 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -20,5 +20,4 @@ pub async fn init(mgr: Arc) { // this is achieved by calling submodules that also have fn init() defined experiments::init(mgr).await - } diff --git a/src/modules/experiments.rs b/src/modules/experiments.rs index 80b5a7d..b310e92 100644 --- a/src/modules/experiments.rs +++ b/src/modules/experiments.rs @@ -1,22 +1,21 @@ /* Custom Modules - - Usage : + Usage : [ ] within the file's init(), define BotActions & Load them into the ModulesManager - [ ] Define Execution Bodies for these BotActions + [ ] Define Execution Bodies for these BotActions [ ] Afterwards, add the following to parent modules.rs file - mod ; - within init(), ::init(mgr).await - + */ - -use std::sync::Arc; use rand::Rng; +use std::sync::Arc; use twitch_irc::message::PrivmsgMessage; -use crate::core::botinstance::botlog; +use crate::core::botlog; use crate::core::botmodules::bot_actions::actions_util::{self, BotAR}; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager}; @@ -24,8 +23,6 @@ use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, M use crate::core::identity; pub async fn init(mgr: Arc) { - - // 1. Define the BotAction let botc1 = BotCommand { module: BotModule(String::from("experiments001")), @@ -39,7 +36,6 @@ pub async fn init(mgr: Arc) { // 2. Add the BotAction to ModulesManager botc1.add_to_modmgr(Arc::clone(&mgr)).await; - // 1. Define the BotAction let list1 = Listener { module: BotModule(String::from("experiments001")), @@ -50,11 +46,9 @@ pub async fn init(mgr: Arc) { // 2. Add the BotAction to ModulesManager list1.add_to_modmgr(Arc::clone(&mgr)).await; - } async fn good_girl(bot: BotAR, msg: PrivmsgMessage) { - // [ ] Uses gen_ratio() to output bool based on a ratio probability . // - For example gen_ratio(2,3) is 2 out of 3 or 0.67% (numerator,denomitator) // - More Info : https://rust-random.github.io/rand/rand/trait.Rng.html#method.gen_ratio @@ -62,18 +56,15 @@ async fn good_girl(bot: BotAR, msg: PrivmsgMessage) { if msg.sender.name.to_lowercase() == "ModulatingForce".to_lowercase() || msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase() { - botlog::debug( "Good Girl Detected > Pausechamp", Some("experiments > goodgirl()".to_string()), Some(&msg), ); - let rollwin = rand::thread_rng().gen_ratio(1, 8); if rollwin { - botlog::debug( "Oh that's a good girl!", Some("experiments > goodgirl()".to_string()), @@ -90,7 +81,6 @@ async fn good_girl(bot: BotAR, msg: PrivmsgMessage) { .chat .say_in_reply_to(&msg, String::from("GoodGirl xdd ")) .await; - } } }