ModulesManager #37
1 changed files with 40 additions and 2 deletions
|
@ -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<ModulesManager>);
|
||||
async fn add_core_to_bot(self, bot: BotInstance);
|
||||
async fn add_core_to_modmgr(self, modmgr: Arc<ModulesManager>);
|
||||
}
|
||||
|
||||
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<ModulesManager>) {
|
||||
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<ModulesManager>) {
|
||||
modmgr
|
||||
.add_core_act(self.module.clone(), BotAction::L(self))
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Routine {}
|
||||
|
||||
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>>>>,
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue