ModGroup enum

This commit is contained in:
ModulatingForce 2024-03-20 23:20:46 -04:00
parent b5873a6ac1
commit eb8877f0c1

View file

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