BotCommands can be defined in modules
This commit is contained in:
parent
a577f502a2
commit
3fcd9cdcce
6 changed files with 111 additions and 15 deletions
|
@ -1,3 +1,8 @@
|
|||
pub mod botinstance;
|
||||
pub mod ratelimiter;
|
||||
pub mod botmodules;
|
||||
pub mod botmodules;
|
||||
|
||||
// pub fn init() -> ()
|
||||
// {
|
||||
// println!("I was here");
|
||||
// }
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -54,13 +54,13 @@ pub enum BotAction {
|
|||
R(Routine),
|
||||
}
|
||||
#[derive(Debug)]
|
||||
struct BotCommand {
|
||||
module : ModType,
|
||||
command : String, // command call name
|
||||
alias : Vec<String>, // String of alternative names
|
||||
pub struct BotCommand {
|
||||
pub module : ModType,
|
||||
pub command : String, // command call name
|
||||
pub alias : Vec<String>, // 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);
|
||||
|
||||
();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
|
||||
pub mod core;
|
||||
pub mod modules;
|
||||
use crate::core::botinstance::BotInstance;
|
||||
|
||||
#[tokio::main]
|
||||
|
|
30
src/modules.rs
Normal file
30
src/modules.rs
Normal file
|
@ -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);
|
||||
|
||||
|
||||
();
|
||||
}
|
33
src/modules/experiments.rs
Normal file
33
src/modules/experiments.rs
Normal file
|
@ -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");
|
||||
|
||||
|
||||
();
|
||||
}
|
Loading…
Reference in a new issue