refined promote/demote

This commit is contained in:
ModulatingForce 2024-03-25 20:11:50 -04:00
parent acfcae975e
commit df6fe8ccb7

View file

@ -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 // [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 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::SupMod(trg_chnl.clone()))
|| authusrroles.contains(&UserRole::Broadcaster) || authusrroles.contains(&UserRole::Broadcaster)
) )
&& trg_role == Some(UserRole::VIP(trg_chnl.clone())) { {
if trgusrroles.contains(&UserRole::VIP(trg_chnl.clone())) { if trgusrroles.contains(&UserRole::VIP(trg_chnl.clone())) {
return ChangeResult::NoChange("Already has the role".to_string()); return ChangeResult::NoChange("Already has the role".to_string());
} }
@ -1796,6 +1805,9 @@ impl IdentityManager {
return ChangeResult::Success("Promotion Successful".to_string()); 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) || authusrroles.contains(&UserRole::Broadcaster)
) )
&& trg_role == Some(UserRole::VIP(channel.clone())) { && trg_role == Some(UserRole::VIP(channel.clone())) {
if trgusrroles.contains(&UserRole::VIP(channel.clone())) { if !trgusrroles.contains(&UserRole::VIP(channel.clone())) {
return ChangeResult::NoChange("Already has the role".to_string()); return ChangeResult::NoChange("Already does not haev VIP role".to_string());
} }
else { 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, chattername: String,
channel: Option<Channel>, channel: Option<Channel>,
) -> Vec<UserRole> { ) -> Vec<UserRole> {
/*
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 ? 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())) { if a.read().await.contains(&UserRole::SupMod(channel.clone())) {
evalsproles.push(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 {}; // else {};
} }
None => { None => {