diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 1452860..1aa0e49 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -246,7 +246,7 @@ impl BotInstance { /* BotCommand handling - - [x] Checks if the input message is a prefix with command name or alias - - [ ] Validate User can run based on identityModule(From_Bot)::can_user_run( + - [x] Validate User can run based on identityModule(From_Bot)::can_user_run( _usr:String, _channelname:ChType, _chat_badge:ChatBadge, @@ -431,40 +431,11 @@ impl BotInstance { Some(msg), ); - - // const OF_CMD_CHANNEL:ChType = Channel(String::new()); - - // let elevated_access = { - // let mut idlock = id.write().await; - // let (permissability, _) = idlock - // .can_user_run_prvmsg(msg, - // vec![ - // identity::UserRole::BotAdmin, - // identity::UserRole::Mod(OF_CMD_CHANNEL), - // identity::UserRole::SupMod(OF_CMD_CHANNEL), - // identity::UserRole::Broadcaster, - // ]) - // .await; - - // permissability - // }; - - // if let Permissible::Allow = elevated_access { - // let botlock = bot.read().await; - // let outstr = - // format!("sadg Module is disabled : {:?}",a); - // botlock.botmgrs.chat.say_in_reply_to(msg, outstr).await; - // } - - //return; } else { let a = Arc::clone(&bot); l.execute(a, msg.clone()).await; } - - // let a = Arc::clone(&bot); - // l.execute(a, msg.clone()).await; } _ => (), diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index d716ec5..cef3b2f 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -22,10 +22,8 @@ Example use core::panic; use std::collections::HashMap; -// use std::error::Error; use std::sync::Arc; -// use futures::stream::iter; use twitch_irc::message::PrivmsgMessage; use casual_logger::Log; @@ -48,8 +46,6 @@ use std::hash::{Hash, Hasher}; use super::identity::ChatBadge; -// use super::identity::ChangeResult; - pub async fn init(mgr: Arc) { @@ -91,7 +87,6 @@ pub async fn init(mgr: Arc) { /* 1. Parse out Message Arguments - exec_enable() @@ -415,12 +410,6 @@ pub async fn init(mgr: Arc) { - - - - -// #[derive(Debug, PartialEq, Eq, Hash, Clone)] -// #[derive(Debug, Hash, Clone)] #[derive(Debug, Clone)] pub enum ModType { BotModule(String), @@ -578,9 +567,6 @@ pub struct Routine {} type StatusdbEntry = (ModGroup, Vec); pub struct ModulesManager { - // statusdb: Arc>>>, - // statusdb: Arc>>>, - // statusdb: Arc)>>>, statusdb: Arc>>, pub botactions: Arc>>>, } @@ -668,19 +654,6 @@ impl ModulesManager { StatusType::Enabled(StatusLvl::Instance) // This forces core to be validated as Enabled, even if undesired scenario of missing StatusLvl::Instance or empty vectors }, ModGroup::Custom => { - // // remove all instance level pattern for the module - // while let Some(index) = statusvector - // .iter() - // .position(|x| (*x == StatusType::Enabled(StatusLvl::Instance)) || (*x == StatusType::Disabled(StatusLvl::Instance))) { - - // statusvector.remove(index); - // } - // statusvector.push(StatusType::Disabled(StatusLvl::Instance)); - - // ( - // StatusType::Disabled(StatusLvl::Instance), - // ChangeResult::Success("Set Disabled at Instance".to_string()) - // ) /* @@ -737,29 +710,12 @@ impl ModulesManager { //StatusType::Enabled(StatusLvl::Instance) } - // pub fn togglestatus(&self, _: ModType, _: ChType) -> StatusType { - // // enables or disables based on current status - // StatusType::Enabled(StatusLvl::Instance) - // } - - // pub fn setstatus(&self, _: ModType, _: StatusType) -> Result<&str, Box> { - // // sets the status based given ModSatusType - // // e.g., b.setstatus(BodModule("GambaCore"), Enabled(Channel("modulatingforce"))).expect("ERROR") - // Ok("") - // } - - /* - exec_enable(self,requestor,requestor_badge,trg_module,Channel) -> ChangeResult - */ - pub async fn exec_enable( &self, requestor: String, requestor_badge: Option, trg_module: ModType, - // channel: Option, trg_level: StatusLvl, - // bot: BotAR, id: Arc>, ) -> ChangeResult { @@ -784,7 +740,7 @@ impl ModulesManager { /* - [ ] 1. If CmdSender is BotAdmin but not (Mod,SupMod,Broadcaster) + [x] 1. If CmdSender is BotAdmin but not (Mod,SupMod,Broadcaster) 1. can_user_run for cmdreqRoles including BotAdmin & not can_user_run for cmdreqRoles (Mod,SupMod,Broadcaster) 1a. , and is -i (to instance) , return a Success 1b. , and is not -i (to instance) , return a Failure recommending BotAdmin promote themselves first @@ -795,19 +751,14 @@ impl ModulesManager { // [x] Validate in trg_module first - // let botlock = bot.read().await; - // let modmgr = Arc::clone(&botlock.botmodules); let modlist = self.moduleslist().await; let rslt = modlist.get(&trg_module); - // if let None = rslt { if rslt.is_none() { return ChangeResult::Failed("Module doesn't exist".to_string()); } - // let botlock = bot.read().await; - // let id = botlock.get_identity(); let mut idlock = id.write().await; // if trg_level = StatusLvl::Instance , the temp_chnl = the broadcaster's or the chatter's @@ -833,16 +784,6 @@ impl ModulesManager { ]).await; - // botlog::debug( - // &format!("FAILURE BEFORE Let statements involves : - // admin_level_access : {:?} ; chnl_elevated_access : {:?}", - // admin_level_access , chnl_elevated_access), - // Some("botmodules.rs > exec_enable()".to_string()), - // None, - // ); - - - if let Permissible::Allow = admin_level_access { if let Permissible::Block = chnl_elevated_access { @@ -868,7 +809,7 @@ impl ModulesManager { /* - [ ] 2. If CmdSender not a BotAdmin but is (Mod,SupMod,Broadcaster) + [x] 2. If CmdSender not a BotAdmin but is (Mod,SupMod,Broadcaster) 2. not can_user_run for cmdreqRoles including BotAdmin & can_user_run for cmdreqRoles (Mod,SupMod,Broadcaster) 2a. , and is -i (to instance) , return a Failure they are not allowed 2b. , and is not -i (to instance) , return a Success @@ -892,7 +833,7 @@ impl ModulesManager { /* - [ ] 3. If CmdSender is (Mod,SupMod,Broadcaster) and a BotAdmin + [x] 3. If CmdSender is (Mod,SupMod,Broadcaster) and a BotAdmin 3. can_user_run for cmdreqRoles (Mod,SupMod,Broadcaster) & can_user_run for cmdreqRoles including BotAdmin 3a. , and is not -i (to instance) , return a Success 3b. , and is -i (to instance) , return a Success @@ -937,64 +878,11 @@ impl ModulesManager { - - // ======================= - // ======================= - // ======================= - // /* - - // 2. Get Special Roles of CmdSender - // 3. If CmdSender is BotAdmin but not (Mod,SupMod,Broadcaster) - // 3a. , and is not -i (to instance) , return a Failure recommending BotAdmin promote themselves first - // 3b. , and is -i (to instance) , return a Success - // 4. If CmdSender not a BotAdmin but is (Mod,SupMod,Broadcaster) - // 4a. , and is not -i (to instance) , return a Success - // 4b. , and is -i (to instance) , return a Failure they are not allowed - // 5. If CmdSender is (Mod,SupMod,Broadcaster) and a BotAdmin - // 5a. , and is not -i (to instance) , return a Success - // 5b. , and is -i (to instance) , return a Success - - - // */ - - // // [ ] 2. Get Special Roles of CmdSender - - // let botlock = bot.read().await; - // let id = botlock.get_identity(); - // let idlock = id.read().await; - - - // let trgchnl = { - // match trg_level { - // StatusLvl::Instance => None, - // StatusLvl::Ch(a) => Some(a), - // } - // }; - - // let requestor_roles = idlock - // .getspecialuserroles( - // requestor.to_lowercase(), - // trgchnl, - // ) - // .await; - - // /* - // [ ] 3. If CmdSender is BotAdmin but not (Mod,SupMod,Broadcaster) - // 3a. , and is not -i (to instance) , return a Failure recommending BotAdmin promote themselves first - // 3b. , and is -i (to instance) , return a Success - // */ - - // if requestor_roles.contains(&identity::UserRole::BotAdmin) - // && !requestor_roles.contains(&identity::UserRole::Broadcaster) - // && !requestor_roles.contains(&identity::UserRole::Mod(trgchnl)) - // { - - // } botlog::debug( &format!("FAILURE involves : @@ -1016,10 +904,8 @@ impl ModulesManager { requestor: String, requestor_badge: Option, trg_module: ModType, - // channel: Option, trg_level: StatusLvl, force: bool, - // bot: BotAR, id: Arc>, ) -> ChangeResult { @@ -1047,8 +933,6 @@ impl ModulesManager { // [x] Validate in trg_module first - // let botlock = bot.read().await; - // let modmgr = Arc::clone(&botlock.botmodules); let modlist = self.moduleslist().await; let rslt = modlist.get(&trg_module); @@ -1057,9 +941,6 @@ impl ModulesManager { } - - // let botlock = bot.read().await; - // let id = botlock.get_identity(); let mut idlock = id.write().await; // if trg_level = StatusLvl::Instance , the temp_chnl = the broadcaster's or the chatter's @@ -1087,7 +968,7 @@ impl ModulesManager { /* - [ ] 1. If CmdSender is BotAdmin but not (Mod,SupMod,Broadcaster) + [x] 1. If CmdSender is BotAdmin but not (Mod,SupMod,Broadcaster) 1. can_user_run for cmdreqRoles including BotAdmin & not can_user_run for cmdreqRoles (Mod,SupMod,Broadcaster) 1a. , and is -f (forced) , return a Success 1b. , and is -i (to instance) , return a Success @@ -1116,11 +997,11 @@ impl ModulesManager { /* - [ ] 2. If CmdSender not a BotAdmin but is (Mod,SupMod,Broadcaster) - 2. not can_user_run for cmdreqRoles including BotAdmin & can_user_run for cmdreqRoles (Mod,SupMod,Broadcaster) - 2a. , and is -f (forced) , return a Failure they are not allowed - 2b. , and is -i (to instance) , return a Failure they are not allowed - 2c. , and has no special flags (-i / -f) , return a Success + [x] 2. If CmdSender not a BotAdmin but is (Mod,SupMod,Broadcaster) + 2. not can_user_run for cmdreqRoles including BotAdmin & can_user_run for cmdreqRoles (Mod,SupMod,Broadcaster) + 2a. , and is -f (forced) , return a Failure they are not allowed + 2b. , and is -i (to instance) , return a Failure they are not allowed + 2c. , and has no special flags (-i / -f) , return a Success */ @@ -1144,11 +1025,11 @@ impl ModulesManager { /* - [ ] 3. If CmdSender is (Mod,SupMod,Broadcaster) and a BotAdmin - 3. can_user_run for cmdreqRoles (Mod,SupMod,Broadcaster) & can_user_run for cmdreqRoles including BotAdmin - 3a. , and is -f (forced) , return a Success - 3b. , and is -i (to instance) , return a Success - 3c. , and has no special flags (-i / -f) , return a Success + [x] 3. If CmdSender is (Mod,SupMod,Broadcaster) and a BotAdmin + 3. can_user_run for cmdreqRoles (Mod,SupMod,Broadcaster) & can_user_run for cmdreqRoles including BotAdmin + 3a. , and is -f (forced) , return a Success + 3b. , and is -i (to instance) , return a Success + 3c. , and has no special flags (-i / -f) , return a Success */ @@ -1203,11 +1084,8 @@ impl ModulesManager { // at Instance level // - If core module, do nothing - // self.satusdb. - let mut dbt = self.statusdb.write().await; - // let a = dbt.entry(in_module.clone()).; let (mgrp,statusvector) = dbt.get_mut(&in_module).unwrap(); match mgrp { @@ -1244,7 +1122,6 @@ impl ModulesManager { let mut dbt = self.statusdb.write().await; - // let a = dbt.entry(in_module.clone()).; let (mgrp,statusvector) = dbt.get_mut(&in_module).unwrap(); match mgrp { @@ -1263,9 +1140,6 @@ impl ModulesManager { if (*x == StatusType::Enabled(StatusLvl::Instance)) || (*x == StatusType::Disabled(StatusLvl::Instance)) { true - // } else if let StatusType::Enabled(StatusLvl::Ch(_)) = (*x).clone() { - // true - // } else {false} } else { matches!((*x).clone(), StatusType::Enabled(StatusLvl::Ch(_))) } @@ -1291,7 +1165,6 @@ impl ModulesManager { let mut dbt = self.statusdb.write().await; - // let a = dbt.entry(in_module.clone()).; let (mgrp,statusvector) = dbt.get_mut(&in_module).unwrap(); match mgrp { @@ -1328,7 +1201,6 @@ impl ModulesManager { let mut dbt = self.statusdb.write().await; - // let a = dbt.entry(in_module.clone()).; let (mgrp,statusvector) = dbt.get_mut(&in_module).unwrap(); match mgrp { @@ -1366,7 +1238,6 @@ impl ModulesManager { let mut dbt = self.statusdb.write().await; - // let a = dbt.entry(in_module.clone()).; let (mgrp,statusvector) = dbt.get_mut(&in_module).unwrap(); match mgrp { @@ -1506,17 +1377,6 @@ impl ModulesManager { ) } - // let mut dbt = self.statusdb.write().await; - // // - // let statusvector = dbt.entry(in_module.clone()).or_insert((in_modgroup.clone(),Vec::new())); - - // match in_modgroup { - // ModGroup::Core => statusvector.1.push(StatusType::Enabled(StatusLvl::Instance)) , // Pushes the Module as Enabled at Instance Level - // ModGroup::Custom => statusvector.1.push(StatusType::Disabled(StatusLvl::Instance)), - // } - - // statusvector.push(ModStatusType::Enabled(StatusLvl::Instance)); // Pushes the Module as Enabled at Instance Level - self.affirm_in_statusdb(in_module.clone(),in_modgroup).await; let mut a = self.botactions.write().await; @@ -1571,8 +1431,6 @@ mod core_modulesmanager { } - - /* Possible Tests @@ -1862,20 +1720,8 @@ mod core_modulesmanager { // ModuleDoesNotExist, // preferring instead to handle in it's own smaller test } - - // let channel = ChType::Channel("somechannel".to_string()); - - - // let mut idlock = idmgr.write().await; let mut idlock = idmgr.clone(); - // if trg_level = StatusLvl::Instance , the temp_chnl = the broadcaster's or the chatter's - - // let arb_chnl = match trg_level.clone() { - // StatusLvl::Instance => ChType::Channel(requestor.to_lowercase()), - // StatusLvl::Ch(a) => a, - // }; - let requestor_badge = None; // If they are a Mod on the Given Channel already, that can be evaluated without the current badge const OF_CMD_CHANNEL:ChType = Channel(String::new()); @@ -1917,19 +1763,8 @@ mod core_modulesmanager { let in_module = BotModule("Experiments01".to_string()); let in_modgroup = ModGroup::Custom; - // match current_test_scenario { - // TestScenarios::BotadminUser => modsmgr.affirm_in_statusdb(in_module.clone(), in_modgroup.clone()).await, - // _ => self::panic!("Scenario not handled"), - // } - modsmgr.affirm_in_statusdb(in_module.clone(), in_modgroup.clone()).await; - // let in_module = match current_test_scenario { - // // TestScenarios::ModuleDoesNotExist => BotModule("NonExisting_Module".to_string()), - // _ => in_module, - // }; - - /* [x] 3. affirm when BotAdmin attempts to exec_enable on the following a. Channel Level , where they are not a Mod @@ -1956,8 +1791,6 @@ mod core_modulesmanager { trg_level.clone(), id.clone()).await; - // assert_eq!(rslt,ChangeResult::Failed("Promote yourself Temporarily First".to_string())); - match current_test_scenario { TestScenarios::BotadminUser => assert_eq!(rslt,ChangeResult::Failed("Promote yourself Temporarily First".to_string())), @@ -1965,10 +1798,6 @@ mod core_modulesmanager { assert_eq!(rslt,ChangeResult::Success("Enabled at Channel Level".to_string())), TestScenarios::RegularChatter => assert_eq!(rslt,ChangeResult::Failed("You're not allowed".to_string())), - // TestScenarios::ModuleDoesNotExist => - // assert_eq!(rslt,ChangeResult::Failed("You're not allowed".to_string())), - // _ => - // self::panic!("Scenario not handled"), } @@ -1978,7 +1807,7 @@ mod core_modulesmanager { */ // [x] requestor_badge: Option, - // let requestor_badge = ChatBadge::Mod; // setting badge to Mod + let requestor_badge = match current_test_scenario { TestScenarios::BotadminUser => Some(ChatBadge::Mod), // setting badge to Mod -- for the Problem Scenario . They are both BotAdmin & Mod @@ -1986,10 +1815,6 @@ mod core_modulesmanager { Some(ChatBadge::Mod), // setting badge to Mod TestScenarios::RegularChatter => None, // setting badge to None - // TestScenarios::ModuleDoesNotExist => - // None, - // _ => - // self::panic!("Scenario not handled"), } ; @@ -1999,8 +1824,6 @@ mod core_modulesmanager { trg_level.clone(), id.clone()).await; - // assert_eq!(rslt,ChangeResult::Success("Enabled at Channel Level".to_string())); - match current_test_scenario { TestScenarios::BotadminUser => assert_eq!(rslt,ChangeResult::Success("Enabled at Channel Level".to_string())), @@ -2008,10 +1831,6 @@ mod core_modulesmanager { assert_eq!(rslt,ChangeResult::Success("Enabled at Channel Level".to_string())), TestScenarios::RegularChatter => assert_eq!(rslt,ChangeResult::Failed("You're not allowed".to_string())), - // TestScenarios::ModuleDoesNotExist => - // assert_eq!(rslt,ChangeResult::Failed("You're not allowed".to_string())), - // _ => - // self::panic!("Scenario not handled"), } /* @@ -2028,10 +1847,6 @@ mod core_modulesmanager { Some(ChatBadge::Mod), TestScenarios::RegularChatter => None, // setting badge to None - // TestScenarios::ModuleDoesNotExist => - // None, // setting badge to None - // _ => - // self::panic!("Scenario not handled"), }; let rslt = modsmgr.exec_enable(requestor.clone(), @@ -2040,7 +1855,6 @@ mod core_modulesmanager { trg_level.clone(), id.clone()).await; - // assert_eq!(rslt,ChangeResult::Success("Enabled at Instance Level".to_string())); match current_test_scenario { TestScenarios::BotadminUser => @@ -2049,10 +1863,6 @@ mod core_modulesmanager { assert_eq!(rslt,ChangeResult::Failed("You're not allowed".to_string())), TestScenarios::RegularChatter => assert_eq!(rslt,ChangeResult::Failed("You're not allowed".to_string())), - // TestScenarios::ModuleDoesNotExist => - // assert_eq!(rslt,ChangeResult::Failed("You're not allowed".to_string())), - // _ => - // self::panic!("Scenario not handled"), } /* @@ -2069,7 +1879,6 @@ mod core_modulesmanager { false, id.clone()).await; - // assert_eq!(rslt,ChangeResult::Success("Disabled at Channel Level".to_string())); match current_test_scenario { TestScenarios::BotadminUser => assert_eq!(rslt,ChangeResult::Success("Disabled at Channel Level".to_string())), @@ -2077,10 +1886,6 @@ mod core_modulesmanager { assert_eq!(rslt,ChangeResult::Success("Disabled at Channel Level".to_string())), TestScenarios::RegularChatter => assert_eq!(rslt,ChangeResult::Failed("You're not allowed".to_string())), - // TestScenarios::ModuleDoesNotExist => - // assert_eq!(rslt,ChangeResult::Failed("You're not allowed".to_string())), - // _ => - // self::panic!("Scenario not handled"), } @@ -2091,7 +1896,7 @@ mod core_modulesmanager { let trg_level = StatusLvl::Ch(channel.clone()); // setting to Channel Level - // let requestor_badge = ChatBadge::Mod; // setting badge to Mod + let requestor_badge = match current_test_scenario { TestScenarios::BotadminUser => None, @@ -2099,10 +1904,6 @@ mod core_modulesmanager { Some(ChatBadge::Mod), TestScenarios::RegularChatter => None, // setting badge to None - // TestScenarios::ModuleDoesNotExist => - // None, - // _ => - // self::panic!("Scenario not handled"), }; let rslt: ChangeResult = modsmgr.exec_disable(requestor.clone(), @@ -2112,7 +1913,7 @@ mod core_modulesmanager { false, id.clone()).await; - // assert_eq!(rslt,ChangeResult::Success("Disabled at Channel Level".to_string())); + match current_test_scenario { TestScenarios::BotadminUser => assert_eq!(rslt,ChangeResult::Success("Disabled at Channel Level".to_string())), @@ -2120,10 +1921,6 @@ mod core_modulesmanager { assert_eq!(rslt,ChangeResult::Success("Disabled at Channel Level".to_string())), TestScenarios::RegularChatter => assert_eq!(rslt,ChangeResult::Failed("You're not allowed".to_string())), - // TestScenarios::ModuleDoesNotExist => - // assert_eq!(rslt,ChangeResult::Failed("You're not allowed".to_string())), - // _ => - // self::panic!("Scenario not handled"), } @@ -2133,8 +1930,8 @@ mod core_modulesmanager { */ let trg_level = StatusLvl::Instance; // setting to Instance level - // let requestor_badge = ChatBadge::Mod; // setting badge to Mod - + + let rslt: ChangeResult = modsmgr.exec_disable(requestor.clone(), None, // Does not have a ChatBadge like Mod trg_module.clone(), @@ -2142,7 +1939,6 @@ mod core_modulesmanager { false, id.clone()).await; - // assert_eq!(rslt,ChangeResult::Success("Disabled at Instance Level".to_string())); match current_test_scenario { TestScenarios::BotadminUser => assert_eq!(rslt,ChangeResult::Success("Disabled at Instance Level".to_string())), @@ -2150,10 +1946,6 @@ mod core_modulesmanager { assert_eq!(rslt,ChangeResult::Failed("You're not allowed".to_string())), TestScenarios::RegularChatter => assert_eq!(rslt,ChangeResult::Failed("You're not allowed".to_string())), - // TestScenarios::ModuleDoesNotExist => - // assert_eq!(rslt,ChangeResult::Failed("You're not allowed".to_string())), - // _ => - // self::panic!("Scenario not handled"), } /* @@ -2162,7 +1954,6 @@ mod core_modulesmanager { */ let trg_level = StatusLvl::Instance; // setting to Instance level - // let requestor_badge = ChatBadge::Mod; // setting badge to Mod let rslt: ChangeResult = modsmgr.exec_disable(requestor.clone(), None, // Does not have a ChatBadge like Mod @@ -2171,7 +1962,6 @@ mod core_modulesmanager { true, // force flag - true id.clone()).await; - // assert_eq!(rslt,ChangeResult::Success("Forced Disable".to_string())); match current_test_scenario { TestScenarios::BotadminUser => assert_eq!(rslt,ChangeResult::Success("Forced Disable".to_string())), @@ -2179,10 +1969,6 @@ mod core_modulesmanager { assert_eq!(rslt,ChangeResult::Failed("You're not allowed".to_string())), TestScenarios::RegularChatter => assert_eq!(rslt,ChangeResult::Failed("You're not allowed".to_string())), - // TestScenarios::ModuleDoesNotExist => - // assert_eq!(rslt,ChangeResult::Failed("You're not allowed".to_string())), - // _ => - // self::panic!("Scenario not handled"), } @@ -2214,14 +2000,6 @@ mod core_modulesmanager { let idmgr = IdentityManager::init(); let modsmgr = ModulesManager::init().await; - // // [x] 2. modmgr.affirm_in_statusdb(Experiments01,Custom) - - // let in_module = BotModule("Experiments01".to_string()); - // let in_modgroup = ModGroup::Custom; - - // modsmgr.affirm_in_statusdb(in_module.clone(), in_modgroup.clone()).await; - - /* [x] 3. affirm when BotAdmin attempts to exec_enable on the following a. Channel Level , where they are not a Mod @@ -2230,7 +2008,6 @@ mod core_modulesmanager { // [x] Create BotAdmin first let requestor = "botadministrator".to_string(); - // let botadmin_badge = &None; idmgr.affirm_chatter_in_db(requestor.clone()).await; idmgr @@ -2249,149 +2026,6 @@ mod core_modulesmanager { inner_enable_disable_complex(requestor, channel, idmgr, modsmgr).await; - /* - pub async fn exec_enable( - &self, - requestor: String, - requestor_badge: Option, - trg_module: ModType, - trg_level: StatusLvl, - id: Arc>, - ) -> ChangeResult - - */ - - /* - [x] 3. affirm when BotAdmin attempts to exec_enable on the following - a. Channel Level , where they are not a Mod - */ - - - // [-] requestor_badge: Option, - - // [x] trg_module: ModType, - // let trg_module = in_module; - - // [x] trg_level: StatusLvl, - - // let channel = ChType::Channel("somechannel".to_string()); - // let trg_level = StatusLvl::Ch(channel.clone()); // setting to Channel Level - - - // // [x] id: Arc>, - // let id = Arc::new(RwLock::new(idmgr)); - - - // let rslt = modsmgr.exec_enable(requestor.clone(), - // None, - // trg_module.clone(), - // trg_level.clone(), - // id.clone()).await; - - // assert_eq!(rslt,ChangeResult::Failed("Promote yourself Temporarily First".to_string())); - - // /* - // [x] 3. affirm when BotAdmin attempts to exec_enable on the following - // b. Channel Level , when they are a Mod - // */ - - // // [x] requestor_badge: Option, - // let requestor_badge = ChatBadge::Mod; // setting badge to Mod - - // let rslt = modsmgr.exec_enable(requestor.clone(), - // Some(requestor_badge), - // trg_module.clone(), - // trg_level.clone(), - // id.clone()).await; - - // assert_eq!(rslt,ChangeResult::Success("Enabled at Channel Level".to_string())); - - // /* - // [x] 3. affirm when BotAdmin attempts to exec_enable on the following - // c. Instance Level - // */ - - // let trg_level = StatusLvl::Instance; // setting to Instance level - - // let rslt = modsmgr.exec_enable(requestor.clone(), - // None, // setting them back to Non-Mod - // trg_module.clone(), - // trg_level.clone(), - // id.clone()).await; - - // assert_eq!(rslt,ChangeResult::Success("Enabled at Instance Level".to_string())); - - // /* - // [x] 4. affirm when BotAdmin attempts to exec_disable on the following - // a. Channel Level , where they are not a Mod - // */ - - // let trg_level = StatusLvl::Ch(channel.clone()); // setting to Channel Level - - // let rslt: ChangeResult = modsmgr.exec_disable(requestor.clone(), - // None, // Does not have a ChatBadge like Mod - // trg_module.clone(), - // trg_level.clone(), - // false, - // id.clone()).await; - - // assert_eq!(rslt,ChangeResult::Success("Disabled at Channel Level".to_string())); - - - // /* - // [x] 4. affirm when BotAdmin attempts to exec_disable on the following - // b. Channel Level , when they are a Mod - // */ - - - // let trg_level = StatusLvl::Ch(channel.clone()); // setting to Channel Level - // let requestor_badge = ChatBadge::Mod; // setting badge to Mod - - // let rslt: ChangeResult = modsmgr.exec_disable(requestor.clone(), - // Some(requestor_badge), - // trg_module.clone(), - // trg_level.clone(), - // false, - // id.clone()).await; - - // assert_eq!(rslt,ChangeResult::Success("Disabled at Channel Level".to_string())); - - // /* - // [x] 4. affirm when BotAdmin attempts to exec_disable on the following - // c. Instance Level - // */ - - // let trg_level = StatusLvl::Instance; // setting to Instance level - // // let requestor_badge = ChatBadge::Mod; // setting badge to Mod - - // let rslt: ChangeResult = modsmgr.exec_disable(requestor.clone(), - // None, // Does not have a ChatBadge like Mod - // trg_module.clone(), - // trg_level.clone(), - // false, - // id.clone()).await; - - // assert_eq!(rslt,ChangeResult::Success("Disabled at Instance Level".to_string())); - - // /* - // [ ] 4. affirm when BotAdmin attempts to exec_disable on the following - // d. force disable - // */ - - // let trg_level = StatusLvl::Instance; // setting to Instance level - // // let requestor_badge = ChatBadge::Mod; // setting badge to Mod - - // let rslt: ChangeResult = modsmgr.exec_disable(requestor.clone(), - // None, // Does not have a ChatBadge like Mod - // trg_module.clone(), - // trg_level.clone(), - // true, // force flag - true - // id.clone()).await; - - // assert_eq!(rslt,ChangeResult::Success("Forced Disable".to_string())); - - - } @@ -2475,15 +2109,11 @@ mod core_modulesmanager { let requestor = "regular_user".to_string(); - // let botadmin_badge = &None; let channel = ChType::Channel("somechannel".to_string()); idmgr.affirm_chatter_in_db(requestor.clone()).await; - // idmgr - // .add_role(requestor.clone(), identity::UserRole::Mod(channel.clone())) - // .await; - + let rslt = idmgr .getspecialuserroles( requestor.clone(), @@ -2511,14 +2141,12 @@ mod core_modulesmanager { let requestor = "regular_user".to_string(); - // let botadmin_badge = &None; + let channel = ChType::Channel("somechannel".to_string()); idmgr.affirm_chatter_in_db(requestor.clone()).await; - // idmgr - // .add_role(requestor.clone(), identity::UserRole::Mod(channel.clone())) - // .await; + let rslt = idmgr .getspecialuserroles( @@ -2555,7 +2183,7 @@ mod core_modulesmanager { assert_eq!(rslt,ChangeResult::Failed("Module doesn't exist".to_string())); - // [ ] Test with Non Existing module > disable + // [x] Test with Non Existing module > disable let trg_module = BotModule("Non_Existent_Module".to_string()); diff --git a/src/core/identity.rs b/src/core/identity.rs index accda4f..0a27b60 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -696,59 +696,6 @@ impl IdentityManager { } } - // if &msg.badges.contains(Badge{}) { - - // } - - // if let Some(sender_badge) = sender_badge { - // match sender_badge { - // Some(sender_badge) => { - // return &self.can_user_run(msg.sender.name.to_owned(), - // ChType::Channel(msg.channel_login.to_owned()), - // sender_badge, - // cmdreqroles - // return self.can_user_run(msg.sender.name.to_owned(), - // let a = Arc::new(Mutex::new(self)); - // let mut a = a.lock().await; - // let a = **a; - // let a = a.can_user_run(msg.sender.name.to_owned(), - // ChType::Channel(msg.channel_login.to_owned()), - // sender_badge, - // cmdreqroles - // ) ; - // let a = *self; - // let a = Arc::new(Mutex::new(a)); - // let a = a.lock().await.can_user_run(msg.sender.name.to_owned(), - // ChType::Channel(msg.channel_login.to_owned()), - // sender_badge, - // cmdreqroles - // ) ; - // return a; - // return self.can_user_run(msg.sender.name.to_owned(), - // ChType::Channel(msg.channel_login.to_owned()), - // sender_badge, - // cmdreqroles - // ).await - - // * NOTE : We're preferring to pass the ChangeResult up , where we have access to Chat via BotInstance - // that have more strained chatting rules - // let evalpermissible = self.can_user_run(msg.sender.name.to_owned(), - // ChType::Channel(msg.channel_login.to_owned()), - // sender_badge, - // cmdreqroles - // ).await ; - // evalpermissible - // // } - // None => { - - // } - // here , sender_badge is likely None - // This could be a regular chatter, BotAdmin,SupserMod - - // [ ] Call can_user_run() - // (self,Permissible::Block) - // (Permissible::Block,ChangeResult::NoChange("".to_string())) - self.can_user_run( msg.sender.name.to_owned(), ChType::Channel(msg.channel_login.to_owned()), @@ -756,6 +703,7 @@ impl IdentityManager { cmdreqroles, ) .await + } pub async fn can_user_run(