diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 0bfe4fa..2fa8945 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -45,6 +45,12 @@ pub enum ModType { BotModule(String), } +#[derive(Debug, PartialEq, Eq, Hash, Clone)] +pub enum ModGroup { + Core, + Custom, +} + #[derive(Debug)] pub enum StatusLvl { Instance, @@ -77,6 +83,8 @@ impl BotAction { pub trait BotActionTrait { async fn add_to_bot(self, bot: BotInstance); async fn add_to_modmgr(self, modmgr: Arc); + async fn add_core_to_bot(self, bot: BotInstance); + async fn add_core_to_modmgr(self, modmgr: Arc); } pub struct BotCommand { @@ -105,6 +113,16 @@ impl BotActionTrait for BotCommand { .add_botaction(self.module.clone(), BotAction::C(self)) .await } + + async fn add_core_to_bot(self, bot: BotInstance) { + self.add_core_to_modmgr(bot.botmodules).await; + } + + async fn add_core_to_modmgr(self, modmgr: Arc) { + modmgr + .add_core_act(self.module.clone(), BotAction::C(self)) + .await + } } pub struct Listener { @@ -142,13 +160,24 @@ impl BotActionTrait for Listener { .add_botaction(self.module.clone(), BotAction::L(self)) .await; } + + async fn add_core_to_bot(self, bot: BotInstance) { + self.add_core_to_modmgr(bot.botmodules).await; + } + + async fn add_core_to_modmgr(self, modmgr: Arc) { + modmgr + .add_core_act(self.module.clone(), BotAction::L(self)) + .await + } } #[derive(Debug)] pub struct Routine {} pub struct ModulesManager { - statusdb: Arc>>>, + // statusdb: Arc>>>, + statusdb: Arc>>>, pub botactions: Arc>>>, } @@ -220,6 +249,14 @@ impl ModulesManager { } pub async fn add_botaction(&self, in_module: ModType, in_action: BotAction) { + self.int_add_botaction(in_module,ModGroup::Custom,in_action).await; + } + + pub async fn add_core_act(&self, in_module: ModType, in_action: BotAction) { + self.int_add_botaction(in_module,ModGroup::Core,in_action).await; + } + + async fn int_add_botaction(&self, in_module: ModType, in_modgroup: ModGroup, in_action: BotAction) { botlog::trace( "Add botaction called", Some("ModulesManager > init()".to_string()), @@ -300,7 +337,8 @@ impl ModulesManager { } let mut dbt = self.statusdb.write().await; - let statusvector = dbt.entry(in_module.clone()).or_insert(Vec::new()); + // + let statusvector = dbt.entry((in_module.clone(),in_modgroup.clone())).or_insert(Vec::new()); statusvector.push(ModStatusType::Enabled(StatusLvl::Instance)); // Pushes the Module as Enabled at Instance Level