(cont) botlog module
This commit is contained in:
parent
fd80921ebb
commit
51d5db3f4e
5 changed files with 411 additions and 78 deletions
src/core
|
@ -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<String> - Code Module
|
||||
- Option<String> - Code_Module
|
||||
- Option<PrivmsgMessage> - 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<String>,prvmsg:Option<PrivmsgMessage>,) -> () {
|
||||
pub fn trace(in_msg:&str,in_module:Option<String>,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<PrivmsgMessage>,in_msg:&str) -> () {
|
||||
pub fn debug(in_msg:&str,in_module:Option<String>,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<PrivmsgMessage>,in_msg:&str) -> () {
|
||||
pub fn info(in_msg:&str,in_module:Option<String>,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<PrivmsgMessage>,in_msg:&str) -> () {
|
||||
pub fn notice(in_msg:&str,in_module:Option<String>,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<PrivmsgMessage>,in_msg:&str) -> () {
|
||||
pub fn warn(in_msg:&str,in_module:Option<String>,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<PrivmsgMessage>,in_msg:&str) -> () {
|
||||
pub fn error(in_msg:&str,in_module:Option<String>,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<String>,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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue