From 3fcd9cdcce3133c28fd31d260b15af7c42713d29 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Fri, 22 Dec 2023 09:21:49 -0500 Subject: [PATCH] BotCommands can be defined in modules --- src/core.rs | 7 +++++- src/core/botinstance.rs | 5 ++++ src/core/botmodules.rs | 50 +++++++++++++++++++++++++++----------- src/main.rs | 1 + src/modules.rs | 30 +++++++++++++++++++++++ src/modules/experiments.rs | 33 +++++++++++++++++++++++++ 6 files changed, 111 insertions(+), 15 deletions(-) create mode 100644 src/modules.rs create mode 100644 src/modules/experiments.rs diff --git a/src/core.rs b/src/core.rs index 57d7061..320ee73 100644 --- a/src/core.rs +++ b/src/core.rs @@ -1,3 +1,8 @@ pub mod botinstance; pub mod ratelimiter; -pub mod botmodules; \ No newline at end of file +pub mod botmodules; + +// pub fn init() -> () +// { +// println!("I was here"); +// } diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index be5e528..0bd38af 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -22,6 +22,11 @@ use crate::core::ratelimiter::RateLimiter; use crate::core::ratelimiter; // use crate::core::ratelimiter; +// pub fn init() -> () +// { +// println!("I was here"); +// } + use crate::core::botmodules; use crate::core::botmodules::ModulesManager; diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index bb21b49..23e9904 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -54,13 +54,13 @@ pub enum BotAction { R(Routine), } #[derive(Debug)] -struct BotCommand { - module : ModType, - command : String, // command call name - alias : Vec, // String of alternative names +pub struct BotCommand { + pub module : ModType, + pub command : String, // command call name + pub alias : Vec, // String of alternative names // bot_prefix : char, // although should be global? // exec_body : fn, - help : String, + pub help : String, } impl BotCommand { @@ -177,17 +177,36 @@ impl ModulesManager { // mgr.add_botaction(BotModule(String::from("experiments 002")), BotAction::C(bcmd)); + // -- Below working demonstration of BotCommand.add_to_modmgr() - 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); + // BotCommand { + // module : BotModule(String::from("experiments 003")), + // command : String::from("DUPCMD3"), // command call name + // alias : vec![String::from("DUPALIAS3A"),String::from("DUPALIAS3B")], // String of alternative names + // // bot_prefix : char, // although should be global? + // // exec_body : fn, + // help : String::from("DUPCMD3 tester"), + // }.add_to_modmgr(&mut mgr); - + // crate::core::botmodules::BotCommand{ + // module : BotModule(String::from("experiments 003")), + // command : String::from("DUPCMD3"), // command call name + // alias : vec![String::from("DUPALIAS3A"),String::from("DUPALIAS3B")], // String of alternative names + // // bot_prefix : char, // although should be global? + // // exec_body : fn, + // help : String::from("DUPCMD3 tester"), + // }; + + // // => 2023.12.22 - [ ] MF : How can I call submods:init() ? + // crate::core::botinstance::init(); // works + // crate::core::init(); // works + //crate::submods:: + //crate::arbfile; + crate::modules::init(&mut mgr); + + + + println!(">> Modules Manager : End of Init"); println!(">> Modules Manager : {:?}",mgr); mgr @@ -354,6 +373,9 @@ impl ModulesManager { // modactions.push(BotAction::L(newlistener)); modactions.push(in_action); + println!(">> Modules Manager : Called Add bot Action"); + println!(">> Modules Manager : {:?}",&self); + (); } diff --git a/src/main.rs b/src/main.rs index 4942696..90a3244 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ pub mod core; +pub mod modules; use crate::core::botinstance::BotInstance; #[tokio::main] diff --git a/src/modules.rs b/src/modules.rs new file mode 100644 index 0000000..74cd893 --- /dev/null +++ b/src/modules.rs @@ -0,0 +1,30 @@ +/* + `modules` will : + - be a starting refrence point for the bot instance to pull module definitions for + +*/ + +//mod crate::core::botmodules; +// use crate::core::botmodules; +pub use crate::core::botmodules::ModulesManager; + +// use crate::core::botinstance; +pub use crate::core::botinstance::BotInstance; + + +// [ ] Load submodules + +mod experiments; + + +// [ ] init() function that accepts bot instance - this is passed to init() on submodules + +pub fn init(mgr:&mut ModulesManager) -> () { + // Modules initializer loads modules into the bot + // this is achieved by calling submodules that also have fn init() defined + + experiments::init(mgr); + + + (); +} \ No newline at end of file diff --git a/src/modules/experiments.rs b/src/modules/experiments.rs new file mode 100644 index 0000000..756883b --- /dev/null +++ b/src/modules/experiments.rs @@ -0,0 +1,33 @@ + +/* + Submodules - + + - should have definitions of BotAction that will be added to a bit + - therefore, will be defined in modules.rs file + - will define one init(&BotInstance) take within the module that will contain : + - BotAction definitions that each call &BotInstance module manager to add itself + +*/ + +// mod crate::modules; +//use crate::modules; + +use crate::core::botmodules::{ModulesManager,BotCommand,BotModule}; + +pub fn init(mgr:&mut ModulesManager) -> () { + + + BotCommand { + module : BotModule(String::from("experiments 004")), + command : String::from("DUPCMD4"), // command call name + alias : vec![String::from("DUPALIAS4A"),String::from("DUPALIAS4B")], // String of alternative names + // bot_prefix : char, // although should be global? + // exec_body : fn, + help : String::from("DUPCMD4 tester"), + }.add_to_modmgr(mgr); + + println!("At Experiments module"); + + + (); +} \ No newline at end of file