From a577f502a203a95b7ef4b20e7da7ef8247c68637 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Thu, 21 Dec 2023 20:43:10 -0500 Subject: [PATCH] Enh Botcommand with add to modmgr --- src/core/botinstance.rs | 4 ++-- src/core/botmodules.rs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index d6241d1..be5e528 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -61,7 +61,7 @@ pub struct BotInstance { pub incoming_messages : UnboundedReceiver, pub ratelimiters : HashMap, // used to limit messages sent per channel // botmodules : HashMap>, - botmodules : ModulesManager, + pub botmodules : ModulesManager, twitch_oauth : String, pub bot_channels : Vec, /*bot_commands : Vec[BotCommand], @@ -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 920d92e..bb21b49 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -63,6 +63,34 @@ struct BotCommand { help : String, } +impl BotCommand { + pub fn add_to_bot(self, bot:BotInstance) { + // let mut mgr = bot.botmodules; + // let nmod = self.module.clone(); + // mgr.add_botaction(nmod, BotAction::C(self)); + let mut mgr = bot.botmodules; + //let nmod = self.module.clone(); + // mgr.add_botaction(self.module.clone(), BotAction::C(self)); + + self.add_to_modmgr(&mut mgr); + } + + + pub fn add_to_modmgr(self, modmgr:&mut ModulesManager) { + // // let mut mgr = bot.botmodules; + // // let nmod = self.module.clone(); + // // mgr.add_botaction(nmod, BotAction::C(self)); + // let mut mgr = modmgr; + // //let nmod = self.module.clone(); + // mgr.add_botaction(self.module.clone(), BotAction::C(self)); + // let mut mgr = modmgr; + // //let nmod = self.module.clone(); + modmgr.add_botaction(self.module.clone(), BotAction::C(self)); + } + + +} + #[derive(Debug)] struct Listener { module : ModType, @@ -150,6 +178,16 @@ impl ModulesManager { // mgr.add_botaction(BotModule(String::from("experiments 002")), BotAction::C(bcmd)); + BotCommand { + module : BotModule(String::from("experiments 002")), + command : String::from("DUPCMD2"), // command call name + alias : vec![String::from("DUPALIAS2A"),String::from("DUPALIAS2B")], // String of alternative names + // bot_prefix : char, // although should be global? + // exec_body : fn, + help : String::from("DUPCMD2 tester"), + }.add_to_modmgr(&mut mgr); + + println!(">> Modules Manager : {:?}",mgr); mgr