diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index e7dd889..07b481d 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -37,15 +37,6 @@ pub enum ChangeResult { pub struct Channel(pub String); -// impl PartialEq for Channel { -// fn eq(&self, other: &Self) -> bool { -// let Channel(name1) = self.clone(); -// let Channel(name2) = other.clone(); -// name1.to_lowercase() == name2.to_lowercase() -// } -// } -// impl Eq for Channel {} - use super::bot_actions::ExecBodyParams; use super::botmodules::StatusType; @@ -480,13 +471,6 @@ impl BotInstance { params.clone(), ).await; - - // botlock.botmgrs.chat.say_in_reply_to( - // msg, - // outstr, - // // c.module.clone(), - // params - // ).await; } if innerstr @@ -516,13 +500,7 @@ impl BotInstance { ), params.clone(), ).await; - - // botlock.botmgrs.chat.say_in_reply_to( - // msg, - // outstr, - // // c.module.clone(), - // params - // ).await; + } } diff --git a/src/core/identity.rs b/src/core/identity.rs index fa74e92..dc2da72 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -74,200 +74,7 @@ pub async fn init(mgr: Arc) { }; tempb.add_core_to_modmgr(Arc::clone(&mgr)).await; -/* - async fn cmd_promote(params : ExecBodyParams) { - botlog::trace( - "Called cmd promote", - Some("identity.rs > cmd_prommote()".to_string()), - Some(¶ms.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 - - /* - - `promote` / `demote` - - [ ] `SupMod` & `Broadcaster` & `BotAdmin` can run - - [ ] `UserRole`s that can run, can - - [ ] run `promote` on a regular `Chatter` to make them a `Mod` - - [ ] run `demote` on a `Mod` to make them a `Chatter` - - [ ] Only `BotAdmin` can : - - [ ] target themselves to `promote` / `demote` , in the case that they want to make themselves either a `Mod` or `SupMod` for the channel temporarily - - [ ] `promote admin ` to assign them `BotAdmin` role - - `[ ] Broadcaster` & `BotAdmin` can `demote` a `SupMod` to make them a `Mod` or `promote` the other way - */ - - /* - Usage : - - promote - promote -m - promote -mod - - demote - - promote -v - promote -vip - - promote -admin - - */ - - // println!("{}",params.msg.message_text); - botlog::trace( - format!("Twich Message > {}", params.msg.message_text).as_str(), - Some("identity.rs > cmd_promote()".to_string()), - None, - ); - - let sendername = params.msg.clone().sender.name; - - let mut argv = params.msg.message_text.split(' '); - - argv.next(); // Skip the command name - - let arg1 = argv.next(); - - let arg2 = argv.next(); - - let mut sender_badge: Option = None; - - for b in ¶ms.msg.badges { - if b.name == "moderator" { - sender_badge = Some(ChatBadge::Mod); - } else if b.name == "broadcaster" { - sender_badge = Some(ChatBadge::Broadcaster); - } else if b.name == "vip" { - sender_badge = Some(ChatBadge::VIP); - } - }; - - let targetchnl = params.msg.channel_login.to_lowercase(); - - /* - - [x] 1. Get trgusr (regardless of -admin flag) - [x] 2. promote trguser - [x] 3. Output resulting change - - */ - - // [x] 1. Get trgusr (regardless of -admin flag) - - // let targetusr = if arg1 == Some("-admin") { arg2 } else { arg1 }; - let targetusr = if - arg1 == Some("-admin") - || arg1 == Some("-v") - || arg1 == Some("-vip") - || arg1 == Some("-m") - || arg1 == Some("-mod") - { arg2 } - else { arg1 }; - - // [x] 2. promote trguser - - // [x] Get a required lock first - - let botlock = params.bot.read().await; - let id = botlock.get_identity(); - let idlock = id.read().await; - - let rslt = match targetusr { - Some(targetusr) => { - botlog::debug( - "running promote()", - Some("identity.rs > cmd_promote()".to_string()), - None, - ); - - Log::flush(); - - - // // Believe this is just using this as a Constaint depending on input - // let target_bot_admin_role = - // if arg1 == Some("-admin") { - // Some(UserRole::BotAdmin) - // } else { - // None - // }; - - let target_role = - if arg1 == Some("-admin") { - Some(UserRole::BotAdmin) - } else if arg1 == Some("-vip") || arg1 == Some("-v") { - Some(UserRole::VIP(Channel(targetchnl.clone()))) - } else { - None // [x] Internal promote() logic automatically considers trg_role targetting -mod or -m - }; - - // let target_bot_admin_role = - // if arg1 == Some("-admin") { - // Some(UserRole::BotAdmin) - // } else if arg1 == Some("-v") { - // Some(UserRole::VIP) - // } else { - // None - // }; - - idlock - .promote( - sendername.clone(), - &sender_badge, - targetusr.to_string(), - Some(Channel(targetchnl.clone())), - target_role, - ) - .await - } - - None => { - botlog::debug( - "No Targer User argument", - Some("identity.rs > cmd_demote()".to_string()), - None, - ); - Log::flush(); - - ChangeResult::NoChange("No Targer User".to_string()) - } - }; - - // [x] 3. Output resulting change - - let outmsg = match rslt { - ChangeResult::Success(a) => { - format!("o7 Successfully promoted : {a}") - } - ChangeResult::Failed(a) => { - format!("PoroSad failed to promote : {a}") - } - ChangeResult::NoChange(a) => { - format!("uuh No Promotion Change : {a}") - } - }; - - botlog::debug( - outmsg.as_str(), - Some("identity.rs > cmd_prommote()".to_string()), - Some(¶ms.msg), - ); - - // We should call a notification around here - - botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif( - outmsg.to_string() - ), - params.clone(), - ).await; - - - botlog::trace( - "End of cmd_promote()", - Some("identity.rs > cmd_prommote()".to_string()), - None, - ); - } -*/ + let tempb = BotCommand { module: BotModule(String::from("identity")), command: String::from("demote"), // command call name @@ -283,211 +90,7 @@ pub async fn init(mgr: Arc) { }; tempb.add_core_to_modmgr(Arc::clone(&mgr)).await; -/* - async fn cmd_demote(params : ExecBodyParams) { - botlog::debug( - "Called cmd demote", - Some("identity.rs > cmd_demote()".to_string()), - Some(¶ms.msg), - ); - Log::flush(); - - // -- If the BotCommand.command was called (e.g., demote) & required roles were validated OUTSIDE of this call - // , this is the current function body to execute - - /* - - `promote` / `demote` - - [ ] `SupMod` & `Broadcaster` & `BotAdmin` can run - - [ ] `UserRole`s that can run, can - - [ ] run `promote` on a regular `Chatter` to make them a `Mod` - - [ ] run `demote` on a `Mod` to make them a `Chatter` - - [ ] Only `BotAdmin` can : - - [ ] target themselves to `promote` / `demote` , in the case that they want to make themselves either a `Mod` or `SupMod` for the channel temporarily - - [ ] `promote admin ` to assign them `BotAdmin` role - - `[ ] Broadcaster` & `BotAdmin` can `demote` a `SupMod` to make them a `Mod` or `promote` the other way - */ - - /* - Usage : - - promote - - demote - - demote -m - demote -mod - - demote -v - demote -vip - - // promote -admin - - - - */ - - // [x] Unwraps arguments from message - - let (arg1, arg2) = { - let mut argv = params.msg.message_text.split(' '); - - argv.next(); // Skip the command name - - let arg1 = argv.next(); - - let arg2 = argv.next(); - - (arg1, arg2) - }; - - // --- - - /* - - [x] 1. Parse out the following - - Sender (e.g., Name & Badge) - - Target User (arg1) - - Target Channel (current channel) - - Msg or Msg.Message_Text (for later) - - - [x] 2. Run Demote() - - within demote(), getspecialuserroles() is called on both the sender and the target - - getspecialuserroles() only sends current db , while canuserrun() may change db depending on the most current state of the sender - - getspecialuserroles also borrows the sender's badge to evaluate - - - [x] 3. Take ChangeResult and output response - - */ - - /* - - - [x] 1. Parse out the following - - Sender (e.g., Name & Badge) - - Target User (arg1) - - Target Channel (current channel) - - (no need) Msg or Msg.Message_Text (for later) - - */ - - let sendername = params.msg.clone().sender.name; - - let mut sender_badge_mut: Option = None; - - for b in ¶ms.msg.badges { - if b.name == "moderator" { - sender_badge_mut = Some(ChatBadge::Mod); - } else if b.name == "broadcaster" { - sender_badge_mut = Some(ChatBadge::Broadcaster); - } else if b.name == "vip" { - sender_badge_mut = Some(ChatBadge::VIP); - } - }; - - let sender_badge = sender_badge_mut; - - - let targetchnl = params.msg.channel_login.to_lowercase(); - - - // let targetusr = arg1; - let targetusr = if - arg1 == Some("-v") - || arg1 == Some("-vip") - || arg1 == Some("-m") - || arg1 == Some("-mod") - { arg2 } - else { arg1 }; - - // Note : At the moment, no handling of -admin - let target_role = - if arg1 == Some("-vip") || arg1 == Some("-v") { - Some(UserRole::VIP(Channel(targetchnl.clone()))) - } else { - None // [x] Internal promote() logic automatically considers trg_role targetting -mod or -m - }; - - - - /* - - - [x] 2. Run Demote() - - within demote(), getspecialuserroles() is called on both the sender and the target - - getspecialuserroles() only sends current db , while canuserrun() may change db depending on the most current state of the sender - - getspecialuserroles also borrows the sender's badge to evaluate - - - */ - - // [x] Get a required lock first - - let botlock = params.bot.read().await; - let id = botlock.get_identity(); - let idlock = id.read().await; - - let rslt = match targetusr { - Some(targetusr) => { - botlog::debug( - "running demote()", - Some("identity.rs > cmd_demote()".to_string()), - None, - ); - Log::flush(); - - idlock - .demote( - sendername.clone(), - &sender_badge, - targetusr.to_string(), - Some(Channel(targetchnl.clone())), - target_role, - ) - .await - } - - None => { - botlog::debug( - "No Targer User argument", - Some("identity.rs > cmd_demote()".to_string()), - None, - ); - Log::flush(); - - ChangeResult::NoChange("No Targer User".to_string()) - } - }; - - /* - - - [x] 3. Take ChangeResult and output response - - */ - - let outmsg = match rslt { - ChangeResult::Success(a) => { - format!("o7 Successfully demoted : {a}") - } - ChangeResult::Failed(a) => { - format!("PoroSad failed to demote : {a}") - } - ChangeResult::NoChange(a) => { - format!("uuh No Demotion Change : {a}") - } - }; - - botlog::debug( - outmsg.as_str(), - Some("identity.rs > cmd_demote()".to_string()), - Some(¶ms.msg), - ); - - botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif( - outmsg.to_string() - ), - params.clone(), - ).await; - - - } -*/ + let tempcomm = BotCommand { module: BotModule(String::from("identity")), command: String::from("getroles"), // command call name @@ -503,147 +106,7 @@ pub async fn init(mgr: Arc) { }; tempcomm.add_core_to_modmgr(Arc::clone(&mgr)).await; -/* - async fn getroles(params : ExecBodyParams) { - botlog::debug( - "Called cmd getroles", - Some("identity.rs > cmd_getroles()".to_string()), - Some(¶ms.msg), - ); - - /* - Usage - - getroles - - If channel is provided, provide roles for that channel specifically - - */ - - - let mut argv = params.msg.message_text.split(' '); - - argv.next(); // Skip the command name - - let arg1 = argv.next(); - - let targetuser = match arg1 { - None => return, // exit if no arguments - Some(arg) => arg, - }; - - let arg2 = argv.next(); - - let targetchnl = arg2; - - let botlock = params.bot.read().await; - - let id = botlock.get_identity(); - - let idlock = id.read().await; - - let sproles = match targetchnl { - None => { - // [ ] If targetchnl is not provided, default to pulling the current channel - idlock - .getspecialuserroles( - String::from(targetuser), - Some(Channel(params.msg.channel_login.to_lowercase())), - ) - .await - } - Some(targetchnl) => { - // [x] gets special roles for caller - let callersproles = idlock - .getspecialuserroles( - params.msg.sender.name.to_lowercase(), - Some(Channel(targetchnl.to_lowercase().to_string())), - ) - .await; - - // Below appears to be validating if getroles() should run based on caller's specific roles - // - No Need to add VIP here - if callersproles.contains(&UserRole::Mod(Channel( - targetchnl.to_lowercase().to_string(), - ))) || callersproles.contains(&UserRole::SupMod(Channel( - targetchnl.to_lowercase().to_string(), - ))) || callersproles.contains(&UserRole::Broadcaster) - { - idlock - .getspecialuserroles( - String::from(targetuser), - Some(Channel(targetchnl.to_lowercase())), - ) - .await - } else { - // Otherwise, don't get the target channel, return the current channel instead - idlock - .getspecialuserroles( - String::from(targetuser), - Some(Channel(params.msg.channel_login.to_lowercase())), - ) - .await - } - } - }; - - botlog::debug( - &format!("User roles of Target Chatter >> {:?}", sproles), - Some("identity.rs > init > getroles()".to_string()), - Some(¶ms.msg), - ); - - botlog::trace( - "Evaluating special roles", - Some("identity.rs > init > getroles()".to_string()), - Some(¶ms.msg), - ); - - let outmsg = if ((targetuser.to_lowercase() == params.msg.channel_login.to_lowercase()) - && arg2.is_none()) - || (arg2.is_some() && arg2.unwrap() == targetuser.to_lowercase()) - { - // First evaluates if they're broadcaster - - let mut outmsg = "FeelsWowMan they're the broadcaster. ".to_string(); - - // Below appears to be validating if getroles() should run based on caller's specific roles - // - No Need to add VIP here - if sproles.contains(&UserRole::Mod(Channel( - params.msg.channel_login.to_lowercase(), - ))) || sproles.contains(&UserRole::SupMod(Channel( - params.msg.channel_login.to_lowercase(), - ))) || sproles.contains(&UserRole::BotAdmin) - { - outmsg += format!("Target chatter's user roles are : {:?}", sproles).as_str(); - } - outmsg - } else if sproles.contains(&UserRole::Mod(Channel( - params.msg.channel_login.to_lowercase(), - ))) || sproles.contains(&UserRole::SupMod(Channel( - params.msg.channel_login.to_lowercase(), - ))) || sproles.contains(&UserRole::BotAdmin) - { - format!("Target chatter's user roles are : {:?}", sproles) - } else { - "Target chatter has no special roles LULE ".to_string() - }; - - botlog::debug( - format!("Chat Say Reply message : {}", outmsg).as_str(), - Some("identity.rs > init > getroles()".to_string()), - Some(¶ms.msg), - ); - - botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif( - outmsg.to_string() - ), - params.clone(), - ).await; - - - // [ ] NOTE : After the above, I should receive only the roles in the context of the current channel I received this ideally and maybe BotAdmin ; not outside - } -*/ + botlog::trace( "End of Init MOdule add", Some("identity.rs > init ".to_string()), @@ -750,7 +213,7 @@ async fn cmd_promote(params : ExecBodyParams) { || arg1 == Some("-mod") { arg2 } else if let Some(a) = arg1 { - if a.starts_with("-") { + if a.starts_with('-') { botlock.botmgrs.chat.send_botmsg( super::chat::BotMsgType::Notif( "Invalid Argument Flag".to_string() @@ -777,13 +240,6 @@ async fn cmd_promote(params : ExecBodyParams) { // // Believe this is just using this as a Constaint depending on input - // let target_bot_admin_role = - // if arg1 == Some("-admin") { - // Some(UserRole::BotAdmin) - // } else { - // None - // }; - let target_role = if arg1 == Some("-admin") { Some(UserRole::BotAdmin) @@ -793,15 +249,6 @@ async fn cmd_promote(params : ExecBodyParams) { None // [x] Internal promote() logic automatically considers trg_role targetting -mod or -m }; - // let target_bot_admin_role = - // if arg1 == Some("-admin") { - // Some(UserRole::BotAdmin) - // } else if arg1 == Some("-v") { - // Some(UserRole::VIP) - // } else { - // None - // }; - idlock .promote( sendername.clone(), @@ -984,7 +431,7 @@ async fn cmd_demote(params : ExecBodyParams) { || arg1 == Some("-mod") { arg2 } else if let Some(a) = arg1 { - if a.starts_with("-") { + if a.starts_with('-') { botlock.botmgrs.chat.send_botmsg( super::chat::BotMsgType::Notif( "Invalid Argument Flag".to_string() @@ -2194,7 +1641,7 @@ impl IdentityManager { #[cfg(test)] mod core_identity { - use casual_logger::{Extension, Level}; + use casual_logger::Extension; use super::*; @@ -2798,7 +2245,8 @@ mod core_identity { - let channel = Some(Channel("somechannel".to_string())); + // let channel = Some(Channel("somechannel".to_string())); + let channel = Channel("somechannel".to_string()); let authorizer_badge = Some(ChatBadge::VIP); let authorizer = "chatMod".to_string(); @@ -2808,7 +2256,7 @@ mod core_identity { // [x] 1. assert getspecialuserroles for Target Chatter let rslt = test_id_mgr - .getspecialuserroles(authorizer.clone(), channel.clone()) + .getspecialuserroles(authorizer.clone(), Some(channel.clone())) .await; assert_eq!(rslt,vec![]); @@ -2818,7 +2266,7 @@ mod core_identity { let rslt = test_id_mgr .can_user_run( authorizer.clone(), - channel.clone().unwrap(), + channel.clone(), authorizer_badge, vec![ UserRole::VIP(OF_CMD_CHANNEL), @@ -2831,10 +2279,10 @@ mod core_identity { // [x] 3. assert getspecialuserroles for Target Chatter let rslt = test_id_mgr - .getspecialuserroles(authorizer.clone(), channel.clone()) + .getspecialuserroles(authorizer.clone(), Some(channel.clone())) .await; - assert_eq!(rslt,vec![UserRole::VIP(channel.unwrap())]); + assert_eq!(rslt,vec![UserRole::VIP(channel)]);