From df6fe8ccb757e2e6eb9129ab09a4c2c2893cabab Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Mon, 25 Mar 2024 20:11:50 -0400 Subject: [PATCH] refined promote/demote --- src/core/identity.rs | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/core/identity.rs b/src/core/identity.rs index 7ad804b..35a2c07 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -1779,13 +1779,22 @@ impl IdentityManager { } } + botlog::debug( + format!("VIP Evaluation : Channel = {:?} ; trg_role = {:?} ", + channel.clone(),trg_role + ).as_str(), + Some("identity.rs > promote()".to_string()), + None, + ); + // [x] 4b. If Authorizer is a Mod,SupMod,Broadcaster & trg_role is Some(VIP(channel)), can Promote a Target Chatter > VIP if let Some(trg_chnl) = channel.clone() { - if ( authusrroles.contains(&UserRole::Mod(trg_chnl.clone())) + if trg_role == Some(UserRole::VIP(trg_chnl.clone())) + && ( authusrroles.contains(&UserRole::Mod(trg_chnl.clone())) || authusrroles.contains(&UserRole::SupMod(trg_chnl.clone())) || authusrroles.contains(&UserRole::Broadcaster) ) - && trg_role == Some(UserRole::VIP(trg_chnl.clone())) { + { if trgusrroles.contains(&UserRole::VIP(trg_chnl.clone())) { return ChangeResult::NoChange("Already has the role".to_string()); } @@ -1796,6 +1805,9 @@ impl IdentityManager { return ChangeResult::Success("Promotion Successful".to_string()); } + } else if trg_role == Some(UserRole::VIP(trg_chnl.clone())) + { + return ChangeResult::Failed(String::from("You're not permitted to do that")); } } @@ -1977,15 +1989,15 @@ impl IdentityManager { || authusrroles.contains(&UserRole::Broadcaster) ) && trg_role == Some(UserRole::VIP(channel.clone())) { - if trgusrroles.contains(&UserRole::VIP(channel.clone())) { - return ChangeResult::NoChange("Already has the role".to_string()); + if !trgusrroles.contains(&UserRole::VIP(channel.clone())) { + return ChangeResult::NoChange("Already does not haev VIP role".to_string()); } else { - self.affirm_chatter_in_db(trgchatter.clone()).await; + // self.affirm_chatter_in_db(trgchatter.clone()).await; - self.add_role(trgchatter.clone(), UserRole::VIP(channel.clone())).await; + self.remove_role(trgchatter.clone(), UserRole::VIP(channel.clone())).await; - return ChangeResult::Success("Promotion Successful".to_string()); + return ChangeResult::Success("Demotion Successful".to_string()); } } @@ -2040,6 +2052,11 @@ impl IdentityManager { chattername: String, channel: Option, ) -> Vec { + /* + NOTE : Any NEW or CHANGES to UserRole type should have additional handling here + Specifically for Channel Elevated Roles + */ + /* Note : Ideally this be called for a given chatter name ? */ @@ -2109,6 +2126,9 @@ impl IdentityManager { if a.read().await.contains(&UserRole::SupMod(channel.clone())) { evalsproles.push(UserRole::SupMod(channel.clone())); } + if a.read().await.contains(&UserRole::VIP(channel.clone())) { + evalsproles.push(UserRole::VIP(channel.clone())); + } // else {}; } None => {