[init] enhancing module mgr > add_botaction
This commit is contained in:
parent
08f0043f48
commit
0f805bd1a8
2 changed files with 60 additions and 18 deletions
|
@ -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
|
||||
|
@ -142,7 +144,47 @@ impl ModulesManager {
|
|||
}
|
||||
|
||||
|
||||
fn statuscleanup(&self,chnl:Option<ChType>) -> () {
|
||||
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
|
||||
|
||||
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<ChType>) -> () {
|
||||
// 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")
|
||||
|
|
Loading…
Reference in a new issue