[init] enhancing module mgr > add_botaction
This commit is contained in:
parent
08f0043f48
commit
0f805bd1a8
2 changed files with 60 additions and 18 deletions
|
@ -157,7 +157,7 @@ impl BotInstance {
|
||||||
println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
||||||
|
|
||||||
println!("Privmsg section");
|
println!("Privmsg section");
|
||||||
|
|
||||||
// b.listener_main_prvmsg(&msg);
|
// b.listener_main_prvmsg(&msg);
|
||||||
self.listener_main_prvmsg(&msg).await;
|
self.listener_main_prvmsg(&msg).await;
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ Example
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||||
pub enum ModType {
|
pub enum ModType {
|
||||||
BotModule(String),
|
BotModule(String),
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ pub enum ModStatusType {
|
||||||
// pub use EnType::Enabled;
|
// pub use EnType::Enabled;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum BotAction {
|
pub enum BotAction {
|
||||||
C(BotCommand),
|
C(BotCommand),
|
||||||
L(Listener),
|
L(Listener),
|
||||||
R(Routine),
|
R(Routine),
|
||||||
|
@ -86,25 +86,25 @@ impl ModulesManager {
|
||||||
|
|
||||||
// let newmodule = BotModule(String::from("GambaCore"));
|
// let newmodule = BotModule(String::from("GambaCore"));
|
||||||
|
|
||||||
let newlistener = Listener {
|
// let newlistener = Listener {
|
||||||
module : BotModule(String::from("experiments").to_owned()),
|
// module : BotModule(String::from("experiments").to_owned()),
|
||||||
name : String::from("socklistener"),
|
// name : String::from("socklistener"),
|
||||||
help : String::from("This will listen and react to sock randomly"),
|
// 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
|
// // As a Demonstration, the listener's Module is added and Enabled at Instance level
|
||||||
let statusvector = m
|
// let statusvector = m
|
||||||
.entry(BotModule(String::from("experiments")))
|
// .entry(BotModule(String::from("experiments")))
|
||||||
.or_insert(Vec::new());
|
// .or_insert(Vec::new());
|
||||||
|
|
||||||
statusvector.push(ModStatusType::Enabled(StatusLvl::Instance));
|
// statusvector.push(ModStatusType::Enabled(StatusLvl::Instance));
|
||||||
|
|
||||||
let modactions = act
|
// let modactions = act
|
||||||
.entry( BotModule(String::from("experiments")))
|
// .entry( BotModule(String::from("experiments")))
|
||||||
.or_insert(Vec::new());
|
// .or_insert(Vec::new());
|
||||||
|
|
||||||
modactions.push(BotAction::L(newlistener));
|
// modactions.push(BotAction::L(newlistener));
|
||||||
|
|
||||||
|
|
||||||
let mgr = ModulesManager {
|
let mgr = ModulesManager {
|
||||||
|
@ -112,6 +112,8 @@ impl ModulesManager {
|
||||||
botactions : act,
|
botactions : act,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
println!(">> Modules Manager : {:?}",mgr);
|
println!(">> Modules Manager : {:?}",mgr);
|
||||||
|
|
||||||
mgr
|
mgr
|
||||||
|
@ -141,8 +143,48 @@ impl ModulesManager {
|
||||||
Ok("")
|
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<ChType>) -> () {
|
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 :
|
// internal cleans up statusdb . For example :
|
||||||
// - remove redudancies . If we see several Enabled("m"), only keep 1x
|
// - 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")
|
// - Clarify Conflict. If we see Enabled("m") and Disabled("m") , we remove Enabled("m") and keep Disabled("m")
|
||||||
|
|
Loading…
Reference in a new issue