diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index ee589b4..243d2d9 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -6,14 +6,16 @@ use tokio::sync::RwLock; use crate::core::botinstance::BotInstance; +use super::botmodules::BotAction; + pub type BotAR = Arc>; - +pub type ActAR = Arc>; pub struct ExecBodyParams { pub bot : BotAR, pub msg : PrivmsgMessage, - // parent_act : BotAction , + pub parent_act : ActAR , } pub mod actions_util { diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index a714d9a..5cdc60a 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -47,7 +47,7 @@ pub enum ChangeResult { pub struct Channel(pub String); use super::bot_actions::ExecBodyParams; -use super::botmodules::StatusType; +use super::botmodules::{BotAction, StatusType}; #[derive(Clone)] pub struct BotManagers { @@ -264,16 +264,6 @@ impl BotInstance { // // [ ] #todo Need to run through all Listener Bodies for Enabled Modules for the context of the message (e.g., ModStatus is Enabled in the context for the channel) - let botlock = bot.read().await; - let actsdb = Arc::clone(&botlock.botmodules.botactions); - let actsdblock = actsdb.read().await; - - botlog::debug( - format!("# of BotModules: {}", (*actsdblock).len()).as_str(), - Some("BotInstance > listener_main_prvmsg()".to_string()), - Some(msg), - ); - /* [ ] What we should do instead is : @@ -309,9 +299,30 @@ impl BotInstance { }, }; + + let botlock = bot.read().await; + let actsdb = Arc::clone(&botlock.botmodules.botactions); + let actsdblock = actsdb.read().await; + + botlog::debug( + format!("# of BotModules: {}", (*actsdblock).len()).as_str(), + Some("BotInstance > listener_main_prvmsg()".to_string()), + Some(msg), + ); + + for acts in (*actsdblock).values() { + + for a in acts { - match a { + + // let act_ar = Arc::new(RwLock::new(a)); + // let act_ar_clone = Arc::clone(&act_ar); + let act_clone = Arc::clone(a); + + // match a { + // match &(*act_ar_clone.read().await) { + match &(*act_clone.read().await) { crate::core::botmodules::BotAction::C(c) => { /* BotCommand handling - @@ -454,7 +465,13 @@ impl BotInstance { let a = Arc::clone(&bot); // c.execute(a, msg.clone()).await; - c.execute(ExecBodyParams { bot : a, msg : msg.clone() }).await; + // c.execute(ExecBodyParams { bot : a, msg : msg.clone() }).await; + c.execute(ExecBodyParams { + bot : a, + msg : msg.clone() , + // parent_act : BotAction::C(c) , + parent_act : Arc::clone(&act_clone), + }).await; botlog::trace( "exit out of execution", @@ -501,7 +518,12 @@ impl BotInstance { } else { let a = Arc::clone(&bot); // l.execute(a, msg.clone()).await; - l.execute(ExecBodyParams { bot : a, msg : msg.clone()} ).await; + l.execute(ExecBodyParams { + bot : a, + msg : msg.clone() , + // parent_act : BotAction::L(l) , + parent_act : Arc::clone(&act_clone), + } ).await; } } diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 81f5ae0..3796d82 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -573,10 +573,11 @@ impl BotActionTrait for Listener { pub struct Routine {} type StatusdbEntry = (ModGroup, Vec); +type ModuleActions = Vec>>; pub struct ModulesManager { statusdb: Arc>>, - pub botactions: Arc>>>, + pub botactions: Arc>>, } /* @@ -1329,12 +1330,20 @@ impl ModulesManager { // Check All Other BotAction Command Names & Aliases to ensure they don't conflict async fn find_conflict_module(mgr: &ModulesManager, act: &BotAction) -> Option { + if let BotAction::C(incmd) = act { let actdb = mgr.botactions.read().await; for (module, moduleactions) in &(*actdb) { - for modact in moduleactions.iter() { - if let BotAction::C(dbcmd) = &modact { + + + // for modact in moduleactions.iter() { + for modact_prelock in moduleactions.iter() { + + let modact = modact_prelock.read().await; + + // if let BotAction::C(dbcmd) = &modact { + if let BotAction::C(dbcmd) = &(*modact) { // At this point, there is an command incmd and looked up dbcmd // [x] check if given botcommand c.command:String conflicts with any in botactions @@ -1390,7 +1399,7 @@ impl ModulesManager { let mut a = self.botactions.write().await; let modactions = a.entry(in_module.clone()).or_insert(Vec::new()); - modactions.push(in_action); + modactions.push(Arc::new(RwLock::new(in_action))); botlog::trace( format!( diff --git a/src/main.rs b/src/main.rs index 40b5598..6bc6c0f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,7 +33,11 @@ pub async fn main() { for acts in (*actsdb_lock).values() { for act in acts { - let outstr = match act { + + let act_prelock = act; + let act = act_prelock.read().await; + + let outstr = match &(*act) { botmodules::BotAction::C(b) => { format!("bot actions > Command : {}", b.command) }