botlog module

This commit is contained in:
ModulatingForce 2024-03-02 10:06:26 -05:00
commit 90b9b66e6d
9 changed files with 404 additions and 238 deletions
src/core

View file

@ -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<String> {
// pub fn init(mgr:&mut ModulesManager)
pub async fn init(mgr: Arc<ModulesManager>) {
// 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<ModulesManager>) {
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<ModulesManager>) {
*/
// 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<ModulesManager>) {
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<ModulesManager>) {
}
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<ModulesManager>) {
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<ModulesManager>) {
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<ModulesManager>) {
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<ModulesManager>) {
*/
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<ModulesManager>) {
// async fn cmd_demote(mut _chat:Arc<Mutex<BotInstance>>,_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<ModulesManager>) {
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<ModulesManager>) {
}
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<ModulesManager>) {
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<ModulesManager>) {
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<ModulesManager>) {
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<ModulesManager>) {
// async fn getroles(bot:Arc<Mutex<BotInstance>>,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<ModulesManager>) {
// 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<ModulesManager>) {
// 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<ModulesManager>) {
// # 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<ModulesManager>) {
// 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<ModulesManager>) {
}
// 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<UserRole>, // ) -> Result<Permissible,Box<dyn Error>> {
) -> (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<ChType>,
trg_role: Option<UserRole>,
) -> 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,