(init) id > demote

This commit is contained in:
ModulatingForce 2024-02-14 09:21:50 -05:00
parent ce27674a5f
commit a825544590

View file

@ -411,7 +411,7 @@ pub async fn init(mgr:Arc<ModulesManager>)
botinstance::botlog::debug("Called cmd demote",
Some("identity.rs > cmd_demote()".to_string()), Some(&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
@ -440,6 +440,8 @@ pub async fn init(mgr:Arc<ModulesManager>)
*/
}
let tempcomm = BotCommand {
module : BotModule(String::from("identity")),
command : String::from("getroles"), // command call name
@ -1086,7 +1088,12 @@ impl IdentityManager {
}
// pub async fn promote(&mut self,trgchatter:String,channel:Option<ChType>,trg_role:Option<UserRole>) -> ChangeResult {
pub async fn promote(&self,trgchatter:String,channel:Option<ChType>,trg_role:Option<UserRole>) -> ChangeResult {
pub async fn promote(&self,
trgchatter:String,
channel:Option<ChType>,
trg_role:Option<UserRole>) -> ChangeResult
{
botinstance::botlog::trace(&format!("IN VARS for promote() : Target Chatter : {} ; Target Channel : {:?} ; Targer Role {:?}",
trgchatter,channel,trg_role),
@ -1291,8 +1298,14 @@ impl IdentityManager {
return ChangeResult::Success(String::from("Promotion Successful"));
},
Some(_) => (),
None => (),
Some(_) => {
botinstance::botlog::warn(&format!("Runtime reached undeveloped code"),
Some("identity.rs > promote()".to_string()), None);
},
None => {
botinstance::botlog::warn(&format!("Runtime reached undeveloped code"),
Some("identity.rs > promote()".to_string()), None);
},
}
@ -1362,9 +1375,72 @@ impl IdentityManager {
ChangeResult::Success(String::from("TEST > Promotion Successful"))
}
pub fn demote(self,trgchatter:String,channel:Option<ChType>,trgRole:Option<UserRole>) -> ChangeResult {
ChangeResult::Success(String::from("TEST > Promotion Successful"))
pub async fn demote(&self,
authorizer:String,
trgchatter:String,
channel:Option<ChType>,
trg_role:Option<UserRole>) -> ChangeResult
{
botinstance::botlog::trace(&format!("IN VARS for demote() : Authorizer : {:?} ; Target Chatter : {} ; Target Channel : {:?} ; Targer Role {:?}",
authorizer,trgchatter,channel,trg_role),
Some("identity.rs > demote()".to_string()), None);
Log::flush();
/*
Check authorizer roles (if any) for the target channel
Check Targer User roles (if any) for the target channel
Target Channel may be NONE in the case of Non-Channel related roles (FUTURE ENH)
Use the roles of the above to determine whether the authorizer can demote the target user or not
*/
if let Some(channel) = channel {
let authusrroles = self.getspecialuserroles(
authorizer.to_lowercase().clone(),
Some(channel.clone()))
.await;
// let authusrroles = authusrroles;
let trgusrroles = self.getspecialuserroles(
trgchatter.to_lowercase().clone(),
Some(channel.clone()))
.await;
if ( authusrroles.contains(&UserRole::BotAdmin) ||
authusrroles.contains(&UserRole::Broadcaster) ||
authusrroles.contains(&UserRole::SupMod(channel.clone())) ) &&
trgusrroles.contains(&UserRole::Mod(channel.clone()))
{
let mut srulock = self.special_roles_users.write().await;
let mut usrrolelock = srulock
.get_mut(&trgchatter)
.expect("Error getting roles")
.write().await;
if let Some(indx) = usrrolelock.iter().position(|value| *value == UserRole::Mod(channel.clone())){
usrrolelock.swap_remove(indx);
return ChangeResult::Success("Demoted successfully".to_string())
}
}
else if ( authusrroles.contains(&UserRole::BotAdmin) ||
authusrroles.contains(&UserRole::Broadcaster) ) &&
trgusrroles.contains(&UserRole::SupMod(channel.clone()))
{
let mut srulock = self.special_roles_users.write().await;
let mut usrrolelock = srulock
.get_mut(&trgchatter)
.expect("Error getting roles")
.write().await;
usrrolelock.push(UserRole::SupMod(channel.clone()));
if let Some(indx) = usrrolelock.iter().position(|value| *value == UserRole::SupMod(channel.clone())){
usrrolelock.swap_remove(indx);
return ChangeResult::Success("Demoted successfully".to_string())
}
}
}
ChangeResult::Failed(String::from("Did not meet criteria to demote succesfully"))
}
// pub async fn getspecialuserroles(&self,chattername:String,channel:Option<ChType>) -> Option<Arc<RwLock<Vec<UserRole>>>> {