(cont) botlog module

This commit is contained in:
ModulatingForce 2024-02-13 10:11:49 -05:00
commit 51d5db3f4e
5 changed files with 411 additions and 78 deletions
src/core

View file

@ -34,7 +34,9 @@ fn adminvector() -> Vec<String> {
pub async fn init(mgr:Arc<ModulesManager>)
{
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<ModulesManager>)
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<ModulesManager>)
*/
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<ModulesManager>)
// 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<ModulesManager>)
tempb.add_to_modmgr(Arc::clone(&mgr)).await;
// async fn cmd_demote(mut _chat:Arc<Mutex<BotInstance>>,_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<ModulesManager>)
// async fn getroles(bot:Arc<Mutex<BotInstance>>,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<ModulesManager>)
// 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<ModulesManager>)
};
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<ModulesManager>)
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<ChatBadge> = None;
@ -486,7 +512,9 @@ impl IdentityManager {
// ) -> Result<Permissible,Box<dyn Error>> {
) -> (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)