botmodules helper fns

This commit is contained in:
ModulatingForce 2024-03-21 00:05:52 -04:00
parent b353589576
commit a066329730
3 changed files with 62 additions and 17 deletions

View file

@ -19,12 +19,21 @@ use crate::core::ratelimiter::RateLimiter;
use crate::core::bot_actions::actions_util::BotAR; use crate::core::bot_actions::actions_util::BotAR;
use crate::core::botmodules::ModulesManager; use crate::core::botmodules::ModulesManager;
use crate::core::identity::{ChangeResult, IdentityManager, Permissible}; use crate::core::identity::{IdentityManager, Permissible};
use crate::core::botlog; use crate::core::botlog;
use crate::core::chat::Chat; use crate::core::chat::Chat;
#[derive(Debug, PartialEq, Eq)]
pub enum ChangeResult {
Success(String),
Failed(String),
NoChange(String),
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)] #[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum ChType { pub enum ChType {
Channel(String), Channel(String),

View file

@ -22,7 +22,7 @@ Example
use core::panic; use core::panic;
use std::collections::HashMap; use std::collections::HashMap;
use std::error::Error; // use std::error::Error;
use std::sync::Arc; use std::sync::Arc;
use twitch_irc::message::PrivmsgMessage; use twitch_irc::message::PrivmsgMessage;
@ -32,7 +32,7 @@ use tokio::sync::RwLock;
use async_trait::async_trait; use async_trait::async_trait;
use self::bot_actions::actions_util::BotAR; use self::bot_actions::actions_util::BotAR;
use crate::core::botinstance::{BotInstance, ChType}; use crate::core::botinstance::{BotInstance, ChType,ChangeResult};
use crate::core::botlog; use crate::core::botlog;
use crate::core::identity; use crate::core::identity;
@ -40,6 +40,9 @@ use crate::core::bot_actions;
pub use ChType::Channel; pub use ChType::Channel;
pub use ModType::BotModule; pub use ModType::BotModule;
// use super::identity::ChangeResult;
#[derive(Debug, PartialEq, Eq, Hash, Clone)] #[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum ModType { pub enum ModType {
BotModule(String), BotModule(String),
@ -237,17 +240,50 @@ impl ModulesManager {
StatusType::Enabled(StatusLvl::Instance) StatusType::Enabled(StatusLvl::Instance)
} }
pub fn togglestatus(&self, _: ModType, _: ChType) -> StatusType { // pub fn togglestatus(&self, _: ModType, _: ChType) -> StatusType {
// enables or disables based on current status // // enables or disables based on current status
StatusType::Enabled(StatusLvl::Instance) // StatusType::Enabled(StatusLvl::Instance)
// }
// pub fn setstatus(&self, _: ModType, _: StatusType) -> Result<&str, Box<dyn Error>> {
// // sets the status based given ModSatusType
// // e.g., b.setstatus(BodModule("GambaCore"), Enabled(Channel("modulatingforce"))).expect("ERROR")
// Ok("")
// }
pub fn set_instance_disabled(&self, _in_module: ModType) -> (StatusType,ChangeResult) {
// at Instance level
// - If core module, do nothing
(StatusType::Disabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string()))
} }
pub fn setstatus(&self, _: ModType, _: StatusType) -> Result<&str, Box<dyn Error>> { pub fn force_disabled(&self, _in_module: ModType) -> (StatusType,ChangeResult) {
// sets the status based given ModSatusType // Disables the module at Instance level, and removes all Enabled/Disabled at Channel level
// e.g., b.setstatus(BodModule("GambaCore"), Enabled(Channel("modulatingforce"))).expect("ERROR") // - Bot Moderators MUST Re-enable if they were enabled before
Ok("") // - If core module, do nothing
(StatusType::Disabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string()))
} }
pub fn set_instance_enabled(&self, _in_module: ModType) -> (StatusType,ChangeResult) {
// at Instance level
// - If core module, do nothing
(StatusType::Enabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string()))
}
pub fn set_ch_disabled(&self, _in_module: ModType , _in_chnl: ChType) -> (StatusType,ChangeResult) {
// at Instance level
// - If core module, do nothing
(StatusType::Disabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string()))
}
pub fn set_ch_enabled(&self, _in_module: ModType , _in_chnl: ChType) -> (StatusType,ChangeResult) {
// at Instance level
// - If core module, do nothing
(StatusType::Enabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string()))
}
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; self.int_add_botaction(in_module,ModGroup::Custom,in_action).await;
} }

View file

@ -8,7 +8,7 @@ use twitch_irc::message::PrivmsgMessage;
use casual_logger::Log; use casual_logger::Log;
use crate::core::bot_actions::actions_util::{self, BotAR}; use crate::core::bot_actions::actions_util::{self, BotAR};
use crate::core::botinstance::ChType; use crate::core::botinstance::{ChType,ChangeResult};
use crate::core::botlog; use crate::core::botlog;
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager}; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager};
@ -608,12 +608,12 @@ pub enum ChatBadge {
Mod, Mod,
} }
#[derive(Debug, PartialEq, Eq)] // #[derive(Debug, PartialEq, Eq)]
pub enum ChangeResult { // pub enum ChangeResult {
Success(String), // Success(String),
Failed(String), // Failed(String),
NoChange(String), // NoChange(String),
} // }
impl IdentityManager { impl IdentityManager {
pub fn init() -> IdentityManager { pub fn init() -> IdentityManager {