(init) botlog module
This commit is contained in:
parent
b78a2cd2b9
commit
eb6c5ec58c
8 changed files with 382 additions and 68 deletions
src/core
|
@ -33,7 +33,7 @@ use crate::core::ratelimiter;
|
|||
|
||||
use crate::core::botmodules;
|
||||
use crate::core::botmodules::ModulesManager;
|
||||
use crate::core::identity::{IdentityManager,Permissible};
|
||||
use crate::core::identity::{IdentityManager,Permissible,ChangeResult};
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::cell::RefCell;
|
||||
|
@ -49,6 +49,51 @@ use core::borrow::Borrow;
|
|||
use super::botmodules::bot_actions::actions_util::BotAR;
|
||||
|
||||
|
||||
use casual_logger::{Level,Log};
|
||||
|
||||
|
||||
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<PrivmsgMessage> - this is used to parse out Chatter & Channel into the logs
|
||||
*/
|
||||
|
||||
use casual_logger::{Level,Log};
|
||||
use twitch_irc::message::PrivmsgMessage;
|
||||
|
||||
// trace, debug, info, notice, warn, error, fatal
|
||||
|
||||
fn trace(in_msg:&str,module:Option<String>,prvmsg:Option<PrivmsgMessage>,) -> () {
|
||||
|
||||
}
|
||||
|
||||
fn debug(prvmsg:Option<PrivmsgMessage>,in_msg:&str) -> () {
|
||||
|
||||
}
|
||||
|
||||
fn info(prvmsg:Option<PrivmsgMessage>,in_msg:&str) -> () {
|
||||
|
||||
}
|
||||
|
||||
fn notice(prvmsg:Option<PrivmsgMessage>,in_msg:&str) -> () {
|
||||
|
||||
}
|
||||
|
||||
fn warn(prvmsg:Option<PrivmsgMessage>,in_msg:&str) -> () {
|
||||
|
||||
}
|
||||
|
||||
fn error(prvmsg:Option<PrivmsgMessage>,in_msg:&str) -> () {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||
pub enum ChType {
|
||||
Channel(String),
|
||||
|
@ -110,15 +155,18 @@ impl Chat {
|
|||
}
|
||||
|
||||
self.client.say_in_reply_to(msg,outmsg).await.unwrap();
|
||||
println!("(#{}) > {}", msg.channel_login, "rate limit counter increase");
|
||||
// println!("(#{}) > {}", msg.channel_login, "rate limit counter increase");
|
||||
Log::trace(&format!("(#{}) > {}", msg.channel_login, "rate limit counter increase"));
|
||||
contextratelimiter.increment_counter();
|
||||
println!("{:?}",self.ratelimiters);
|
||||
// println!("{:?}",self.ratelimiters);
|
||||
Log::trace(&format!("{:?}",self.ratelimiters));
|
||||
},
|
||||
ratelimiter::LimiterResp::Skip => {
|
||||
(); // do nothing otherwise
|
||||
}
|
||||
|
||||
}
|
||||
Log::flush();
|
||||
}
|
||||
|
||||
async fn say(&self, _:String, _:String) -> () {
|
||||
|
@ -278,29 +326,42 @@ impl BotInstance
|
|||
ServerMessage::Notice(msg) => {
|
||||
|
||||
match &msg.channel_login {
|
||||
Some(chnl) => println!("NOTICE : (#{}) {}", chnl, msg.message_text),
|
||||
None => println!("NOTICE : {}", msg.message_text),
|
||||
Some(chnl) => {
|
||||
// println!("NOTICE : (#{}) {}", chnl, msg.message_text)
|
||||
Log::notice(&format!("NOTICE : (#{}) {}", chnl, msg.message_text));
|
||||
|
||||
},
|
||||
None => {
|
||||
// println!("NOTICE : {}", msg.message_text);
|
||||
Log::notice(&format!("NOTICE : {}", msg.message_text));
|
||||
},
|
||||
}
|
||||
}
|
||||
ServerMessage::Privmsg(msg) => {
|
||||
println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
||||
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
||||
Log::trace(&format!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text));
|
||||
|
||||
println!("Privmsg section");
|
||||
// println!("Privmsg section");
|
||||
Log::debug(&format!("Privmsg section"));
|
||||
|
||||
BotInstance::listener_main_prvmsg(Arc::clone(&bot), &msg).await;
|
||||
BotInstance::listener_main_prvmsg(Arc::clone(&bot), &msg).await;
|
||||
|
||||
},
|
||||
ServerMessage::Whisper(msg) => {
|
||||
println!("(w) {}: {}", msg.sender.name, msg.message_text);
|
||||
// println!("(w) {}: {}", msg.sender.name, msg.message_text);
|
||||
Log::trace(&format!("(w) {}: {}", msg.sender.name, msg.message_text));
|
||||
},
|
||||
ServerMessage::Join(msg) => {
|
||||
println!("JOINED: {}", msg.channel_login);
|
||||
// println!("JOINED: {}", msg.channel_login);
|
||||
Log::notice(&format!("JOINED: {}", msg.channel_login));
|
||||
},
|
||||
ServerMessage::Part(msg) => {
|
||||
println!("PARTED: {}", msg.channel_login);
|
||||
// println!("PARTED: {}", msg.channel_login);
|
||||
Log::notice(&format!("PARTED: {}", msg.channel_login));
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
};
|
||||
Log::flush();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -342,7 +403,8 @@ impl BotInstance
|
|||
|
||||
|
||||
pub async fn listener_main_prvmsg(bot:BotAR,msg:&PrivmsgMessage) -> () {
|
||||
println!(">> Inner listenermain_prvmsg()");
|
||||
// println!(">> Inner listenermain_prvmsg()");
|
||||
Log::trace(">> Inner listenermain_prvmsg()");
|
||||
|
||||
// let a = a;
|
||||
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
||||
|
@ -353,20 +415,24 @@ impl BotInstance
|
|||
let hacts = Arc::clone(&botlock.botmodules.botactions);
|
||||
// let hacts = hacts.read().await;
|
||||
let a = hacts.read().await;
|
||||
println!("hacts size : {}",(*a).len());
|
||||
// println!("hacts size : {}",(*a).len());
|
||||
Log::debug(&format!("hacts size : {}",(*a).len()));
|
||||
|
||||
println!(">> Inner listenermain_prvmsg() >> before for loop of bot actions");
|
||||
// println!(">> Inner listenermain_prvmsg() >> before for loop of bot actions");
|
||||
Log::trace(">> Inner listenermain_prvmsg() >> before for loop of bot actions");
|
||||
|
||||
for (_m,acts) in &*hacts.read().await {
|
||||
|
||||
println!(">> Inner listenermain_prvmsg() >> checking bot actions");
|
||||
// println!(">> Inner listenermain_prvmsg() >> checking bot actions");
|
||||
Log::trace(">> Inner listenermain_prvmsg() >> checking bot actions");
|
||||
|
||||
|
||||
// let bot = bot;
|
||||
|
||||
for a in acts {
|
||||
|
||||
println!(">> Inner listenermain_prvmsg() >> checking bot actions >> 2");
|
||||
// println!(">> Inner listenermain_prvmsg() >> checking bot actions >> 2");
|
||||
Log::trace(">> Inner listenermain_prvmsg() >> checking bot actions >> 2");
|
||||
|
||||
let _act = match a {
|
||||
|
||||
|
@ -385,7 +451,8 @@ impl BotInstance
|
|||
// println!("args : {v}");
|
||||
// }
|
||||
|
||||
println!("Reviewing internal commands");
|
||||
// println!("Reviewing internal commands");
|
||||
Log::trace("Reviewing internal commands");
|
||||
|
||||
let inpt = msg.message_text.split("\n").next().expect("ERROR during BotCommand");
|
||||
let inpt = msg.message_text.split(" ").next().expect("ERROR during BotCommand");
|
||||
|
@ -413,29 +480,60 @@ impl BotInstance
|
|||
}
|
||||
|
||||
if confirmed_bot_command {
|
||||
println!("Confirmed bot command");
|
||||
// println!("Confirmed bot command");
|
||||
Log::debug("Confirmed bot command");
|
||||
|
||||
println!("Going for botlock");
|
||||
// println!("Going for botlock");
|
||||
Log::trace("Going for botlock");
|
||||
let botlock = bot.read().await;
|
||||
println!("Going for identity");
|
||||
// println!("Going for identity");
|
||||
Log::trace("Going for identity");
|
||||
let id = botlock.get_identity();
|
||||
|
||||
let eval = {
|
||||
let mut id = id.write().await;
|
||||
println!("Unlocking identity");
|
||||
id.can_user_run_PRVMSG(&msg, c.required_roles.clone()).await
|
||||
// println!("Unlocking identity");
|
||||
Log::trace("Unlocking identity");
|
||||
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 {
|
||||
// // let b = b.to_lowercase();
|
||||
// // let b = b.contains(&"Auto Promoted Mod".to_lowercase());
|
||||
// if b.to_lowercase().contains(&"Auto Promoted Mod".to_lowercase()) {
|
||||
// let chat =
|
||||
// }
|
||||
// }
|
||||
(a,b)
|
||||
};
|
||||
println!("Checking if permissible");
|
||||
// println!("Checking if permissible");
|
||||
Log::trace("Checking if permissible");
|
||||
|
||||
let (eval , rolechange) = eval;
|
||||
|
||||
if let ChangeResult::Success(b) = rolechange {
|
||||
|
||||
if b.to_lowercase().contains(&"Auto Promoted Mod".to_lowercase()) {
|
||||
// println!("Read() lock Bot");
|
||||
Log::trace("Read() lock Bot");
|
||||
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");
|
||||
// println!("Executed as permissible");
|
||||
Log::debug("Executed as permissible");
|
||||
let a = Arc::clone(&bot);
|
||||
c.execute(a, msg.clone()).await;
|
||||
println!("exit out of execution");
|
||||
// println!("exit out of execution");
|
||||
Log::trace("exit out of execution");
|
||||
|
||||
}
|
||||
Permissible::Block => {
|
||||
println!("User Not allowed to run command")
|
||||
// println!("User Not allowed to run command");
|
||||
Log::info("User Not allowed to run command");
|
||||
},
|
||||
// _ => (),
|
||||
};
|
||||
|
@ -459,11 +557,14 @@ impl BotInstance
|
|||
|
||||
// // [ ] There should be a BotCommand Listener to check for prefixes ran
|
||||
|
||||
println!("End of Separate Listener Main prvmsg");
|
||||
// println!("End of Separate Listener Main prvmsg");
|
||||
Log::trace("End of Separate Listener Main prvmsg");
|
||||
|
||||
// self
|
||||
// bot
|
||||
|
||||
Log::flush();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue