From 0f805bd1a8c7978f5a42f840c3af7262cc13b8dd Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Thu, 21 Dec 2023 17:22:40 -0500 Subject: [PATCH] [init] enhancing module mgr > add_botaction --- src/core/botinstance.rs | 2 +- src/core/botmodules.rs | 76 ++++++++++++++++++++++++++++++++--------- 2 files changed, 60 insertions(+), 18 deletions(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 540a130..d6241d1 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -157,7 +157,7 @@ impl BotInstance { println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); println!("Privmsg section"); - + // b.listener_main_prvmsg(&msg); self.listener_main_prvmsg(&msg).await; diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 633e099..ea746f2 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -14,7 +14,7 @@ Example */ -#[derive(Debug, PartialEq, Eq, Hash)] +#[derive(Debug, PartialEq, Eq, Hash, Clone)] pub enum ModType { BotModule(String), } @@ -45,7 +45,7 @@ pub enum ModStatusType { // pub use EnType::Enabled; #[derive(Debug)] -enum BotAction { +pub enum BotAction { C(BotCommand), L(Listener), R(Routine), @@ -86,25 +86,25 @@ impl ModulesManager { // let newmodule = BotModule(String::from("GambaCore")); - let newlistener = Listener { - module : BotModule(String::from("experiments").to_owned()), - name : String::from("socklistener"), - help : String::from("This will listen and react to sock randomly"), - }; + // let newlistener = Listener { + // module : BotModule(String::from("experiments").to_owned()), + // name : String::from("socklistener"), + // help : String::from("This will listen and react to sock randomly"), + // }; - // As a Demonstration, the listener's Module is added and Enabled at Instance level - let statusvector = m - .entry(BotModule(String::from("experiments"))) - .or_insert(Vec::new()); + // // As a Demonstration, the listener's Module is added and Enabled at Instance level + // let statusvector = m + // .entry(BotModule(String::from("experiments"))) + // .or_insert(Vec::new()); - statusvector.push(ModStatusType::Enabled(StatusLvl::Instance)); + // statusvector.push(ModStatusType::Enabled(StatusLvl::Instance)); - let modactions = act - .entry( BotModule(String::from("experiments"))) - .or_insert(Vec::new()); + // let modactions = act + // .entry( BotModule(String::from("experiments"))) + // .or_insert(Vec::new()); - modactions.push(BotAction::L(newlistener)); + // modactions.push(BotAction::L(newlistener)); let mgr = ModulesManager { @@ -112,6 +112,8 @@ impl ModulesManager { botactions : act, }; + + println!(">> Modules Manager : {:?}",mgr); mgr @@ -141,8 +143,48 @@ impl ModulesManager { Ok("") } + + pub fn add_botaction(&mut self, in_module:ModType, _:BotAction ) -> () { + // adds a BotAction to the Modules Manager - This will require a BotModule passed as well + // This will including the logic of a valid add + // If it fails to add, either a PANIC or some default coded business rules that handles the botaction add + // For example, this Should PANIC (ideally Panic?) if it does not successfully add a bot module + // -- Being unable to indicates a Programming/Developer code logic issue : They cannot add botactions that already exists (?) + // -- In particular to BotCommands, which must have Unique command call names and aliases that to not conflict with any other + // already BotCommand added name or alias + // Other types might be fine? For example, if 2 modules have their own listeners but each have the name "targetchatter" , + // both would be called separately, even if they both have the same or different logic - fn statuscleanup(&self,chnl:Option) -> () { + let newlistener = Listener { + // module : BotModule(String::from("experiments").to_owned()), + module : in_module.clone(), + name : String::from("socklistener"), + help : String::from("This will listen and react to sock randomly"), + }; + + + // As a Demonstration, the listener's Module is added and Enabled at Instance level + let statusvector = self.statusdb + // .entry(BotModule(String::from("experiments"))) + .entry(in_module.clone()) + .or_insert(Vec::new()); + + statusvector.push(ModStatusType::Enabled(StatusLvl::Instance)); + + let modactions = self.botactions + //.entry( BotModule(String::from("experiments"))) + .entry( in_module.clone()) + .or_insert(Vec::new()); + + modactions.push(BotAction::L(newlistener)); + + (); + } + + + + + fn statuscleanup(&self,_:Option) -> () { // internal cleans up statusdb . For example : // - remove redudancies . If we see several Enabled("m"), only keep 1x // - Clarify Conflict. If we see Enabled("m") and Disabled("m") , we remove Enabled("m") and keep Disabled("m")