module disable by default

This commit is contained in:
modulatingforce 2025-02-01 03:43:53 -05:00
parent 739f7aeeef
commit 802fd714c2
2 changed files with 21 additions and 4 deletions
src/botcore

View file

@ -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 = {

View file

@ -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()
}
}