diff --git a/src/botcore/bot.rs b/src/botcore/bot.rs index e769efd..1a54cc6 100644 --- a/src/botcore/bot.rs +++ b/src/botcore/bot.rs @@ -249,9 +249,15 @@ impl Bot } /// loads a `Module` and its bot objects - pub fn load_module(&mut self,m: Module) { + pub async fn load_module(&mut self,m: Module) { + if m.get_status_by_default() == Status::Disabled { + for chnl in &self.botchannels { + self.disable_module(chnl.clone(), + m.get_names().first().unwrap().clone()).await + } + } self.modules.push(m) - } + } pub async fn get_channel_module_status(&self,channel:String,module:String) -> Status { let found_disabled:bool = { diff --git a/src/botcore/modules.rs b/src/botcore/modules.rs index 8a342c8..2ed44dc 100644 --- a/src/botcore/modules.rs +++ b/src/botcore/modules.rs @@ -2,7 +2,7 @@ use crate::{Command, Listener}; -#[derive(PartialEq, Eq,Debug)] +#[derive(PartialEq, Eq,Debug,Clone)] pub enum Status { Disabled, Enabled @@ -19,6 +19,8 @@ pub struct Module bot_read_description : String, listeners: Vec<Listener>, commands: Vec<Command>, + // disable module at load for bot channels + default_status_per_channel: Status, } impl Module @@ -30,7 +32,8 @@ impl Module // _alias: alias, bot_read_description, listeners: vec![], - commands: vec![] + commands: vec![], + default_status_per_channel: Status::Disabled, } } @@ -60,5 +63,13 @@ impl Module self.bot_read_description.clone() } + pub fn set_status_by_default(&mut self,status:Status){ + self.default_status_per_channel = status; + } + + pub fn get_status_by_default(&self) -> Status { + self.default_status_per_channel.clone() + } + } \ No newline at end of file