From 960cd5724c1c3d533d0c43d44e07ab309724623f Mon Sep 17 00:00:00 2001 From: haruyuumei Date: Fri, 22 Mar 2024 16:55:56 -0300 Subject: [PATCH] Simplifying enums I hope this doesn't explode everything Prayge --- src/core/botinstance.rs | 24 ++++--- src/core/botmodules.rs | 133 +++++++++++++++++++------------------- src/core/chat.rs | 10 +-- src/core/identity.rs | 86 ++++++++++++------------ src/custom/experiments.rs | 5 +- 5 files changed, 132 insertions(+), 126 deletions(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 1aa0e49..a668dac 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -35,11 +35,15 @@ pub enum ChangeResult { #[derive(Debug, PartialEq, Eq, Hash, Clone)] -pub enum ChType { - Channel(String), -} -pub use ChType::Channel; +// pub enum ChType { +// Channel(String), +// } +// +// pub use ChType::Channel; +// +//simplifying from enum to struct +pub struct Channel(pub String); use super::botmodules::StatusType; @@ -51,7 +55,7 @@ pub struct BotManagers { impl BotManagers { pub fn init( - ratelimiters: HashMap, + ratelimiters: HashMap, client: TwitchIRCClient, StaticLoginCredentials>, ) -> BotManagers { BotManagers { @@ -75,11 +79,11 @@ impl ArcBox { pub struct BotInstance { pub prefix: char, - pub bot_channel: ChType, + pub bot_channel: Channel, pub incoming_messages: Arc>>, pub botmodules: Arc, pub twitch_oauth: String, - pub bot_channels: Vec, + pub bot_channels: Vec, pub botmgrs: BotManagers, //modesmgr : ModesManager, // [FUTURE] Silent/Quiet , uwu , frisky/horny } @@ -299,7 +303,7 @@ impl BotInstance { let modmgr = Arc::clone(&botlock.botmodules); let modstatus = modmgr.modstatus( c.module.clone(), - ChType::Channel(msg.channel_login.to_string())).await; + Channel(msg.channel_login.to_string())).await; if let StatusType::Disabled(a) = modstatus { @@ -314,7 +318,7 @@ impl BotInstance { ); - const OF_CMD_CHANNEL:ChType = Channel(String::new()); + const OF_CMD_CHANNEL:Channel = Channel(String::new()); let elevated_access = { let mut idlock = id.write().await; @@ -417,7 +421,7 @@ impl BotInstance { let modmgr = Arc::clone(&botlock.botmodules); let modstatus = modmgr.modstatus( l.module.clone(), - ChType::Channel(msg.channel_login.to_string())).await; + Channel(msg.channel_login.to_string())).await; if let StatusType::Disabled(a) = modstatus { diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index cef3b2f..9c7152f 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -3,12 +3,12 @@ ModulesManager is used to manage Modules and BotActions associated with those modules pub struct ModulesManager { - statusdb: HashMap>, - botactions: HashMap>, + statusdb: HashMap>, + botactions: HashMap>, } -- statusdb: HashMap> - Defines Modules and their ModStatusType (e.g., Enabled at an Instance level, Disabled at a Channel Level) -- botactions: HashMap> - Defines Modules and their BotActions (e.g., BotCommand , Listener, Routine) +- statusdb: HashMap> - Defines Modules and their ModStatusType (e.g., Enabled at an Instance level, Disabled at a Channel Level) +- botactions: HashMap> - Defines Modules and their BotActions (e.g., BotCommand , Listener, Routine) Example { @@ -34,13 +34,13 @@ use async_trait::async_trait; use self::bot_actions::actions_util::BotAR; use crate::core::bot_actions::actions_util; -use crate::core::botinstance::{BotInstance, ChType,ChangeResult}; +use crate::core::botinstance::{BotInstance, Channel,ChangeResult}; use crate::core::botlog; use crate::core::identity::{self, Permissible,IdentityManager}; use crate::core::bot_actions; -pub use ChType::Channel; -pub use ModType::BotModule; + +//pub use BotModule; use std::hash::{Hash, Hasher}; @@ -49,7 +49,7 @@ use super::identity::ChatBadge; pub async fn init(mgr: Arc) { - const OF_CMD_CHANNEL:ChType = Channel(String::new()); + const OF_CMD_CHANNEL:Channel = Channel(String::new()); // 1. Define the BotAction let botc1 = BotCommand { @@ -126,8 +126,8 @@ pub async fn init(mgr: Arc) { &self, requestor: String, requestor_badge: Option, - trg_module: ModType, - // channel: Option, + trg_module: BotModule, + // channel: Option, trg_level: StatusLvl, bot: BotAR, ) -> ChangeResult @@ -153,8 +153,8 @@ pub async fn init(mgr: Arc) { let requestor_badge = requestor_badge_mut; - // [x] trg_module: ModType, - // - [x] Need to validate an actual ModType - otherwise, fail or exit the cmd + // [x] trg_module: BotModule, + // - [x] Need to validate an actual BotModule - otherwise, fail or exit the cmd let trg_module = if (arg1 == Some("-i")) || (arg1 == Some("-f")) { arg2 } else { arg1 }; @@ -190,7 +190,7 @@ pub async fn init(mgr: Arc) { let trg_level = if arg1 == Some("-i") || arg1 == Some("-f") { StatusLvl::Instance } // else if arg1 == Some("-f") { StatusLvl::Instance } - else { StatusLvl::Ch(ChType::Channel(currchnl)) } + else { StatusLvl::Ch(Channel(currchnl)) } ; @@ -204,7 +204,7 @@ pub async fn init(mgr: Arc) { let rslt = modmgr.exec_enable( requestor, requestor_badge, - ModType::BotModule(trg_module.unwrap().to_string()), + BotModule(trg_module.unwrap().to_string()), trg_level, id).await; @@ -302,8 +302,8 @@ pub async fn init(mgr: Arc) { &self, requestor: String, requestor_badge: Option, - trg_module: ModType, - // channel: Option, + trg_module: BotModule, + // channel: Option, trg_level: StatusLvl, force: bool, // bot: BotAR, @@ -330,8 +330,8 @@ pub async fn init(mgr: Arc) { let requestor_badge = requestor_badge_mut; - // [x] trg_module: ModType, - // - [x] Need to validate an actual ModType - otherwise, fail or exit the cmd + // [x] trg_module: BotModule, + // - [x] Need to validate an actual BotModule - otherwise, fail or exit the cmd let trg_module = if (arg1 == Some("-i")) || (arg1 == Some("-f")) { arg2 } else { arg1 }; @@ -368,7 +368,7 @@ pub async fn init(mgr: Arc) { let trg_level = if arg1 == Some("-i") || arg1 == Some("-f") { StatusLvl::Instance } // else if arg1 == Some("-f") { StatusLvl::Instance } - else { StatusLvl::Ch(ChType::Channel(currchnl)) } + else { StatusLvl::Ch(Channel(currchnl)) } ; @@ -383,7 +383,7 @@ pub async fn init(mgr: Arc) { let rslt = modmgr.exec_disable( requestor, requestor_badge, - ModType::BotModule(trg_module.unwrap().to_string()), + BotModule(trg_module.unwrap().to_string()), trg_level, force, id).await; @@ -411,20 +411,23 @@ pub async fn init(mgr: Arc) { #[derive(Debug, Clone)] -pub enum ModType { - BotModule(String), -} +// pub enum BotModule { +// BotModule(String), +// } -impl PartialEq for ModType { +pub struct BotModule(pub String); +//botmodule simplified from enum to tuple struct + +impl PartialEq for BotModule { fn eq(&self, other: &Self) -> bool { let BotModule(name1) = self.clone(); let BotModule(name2) = other.clone(); name1.to_lowercase() == name2.to_lowercase() } } -impl Eq for ModType {} +impl Eq for BotModule {} -impl Hash for ModType{ +impl Hash for BotModule{ fn hash(&self, state: &mut H) { // self.id.hash(state); // self.phone.hash(state); @@ -443,7 +446,7 @@ pub enum ModGroup { #[derive(Debug, PartialEq, Eq, Hash, Clone)] pub enum StatusLvl { Instance, - Ch(ChType), + Ch(Channel), } #[derive(Debug, PartialEq, Eq, Hash, Clone)] @@ -477,7 +480,7 @@ pub trait BotActionTrait { } pub struct BotCommand { - pub module: ModType, + pub module: BotModule, pub command: String, // command call name pub alias: Vec, // String of alternative names pub exec_body: bot_actions::actions_util::ExecBody, @@ -515,7 +518,7 @@ impl BotActionTrait for BotCommand { } pub struct Listener { - pub module: ModType, + pub module: BotModule, pub name: String, pub exec_body: bot_actions::actions_util::ExecBody, pub help: String, @@ -567,20 +570,20 @@ pub struct Routine {} type StatusdbEntry = (ModGroup, Vec); pub struct ModulesManager { - statusdb: Arc>>, - pub botactions: Arc>>>, + statusdb: Arc>>, + pub botactions: Arc>>>, } /* statusdb <-- shows Enabled/Disabled per Status level botactions HashMap< - ModType, <-- e.g., BotModule(String::from("experiments001")) + BotModule, <-- e.g., BotModule(String::from("experiments001")) Vec> BotCommand, Listener */ @@ -618,7 +621,7 @@ impl ModulesManager { } - pub async fn moduleslist(&self) -> HashMap + pub async fn moduleslist(&self) -> HashMap { // let db = Arc::clone(&self.statusdb); @@ -635,7 +638,7 @@ impl ModulesManager { outmap } - pub async fn modstatus(&self, in_module: ModType, in_chnl: ChType) -> StatusType { + pub async fn modstatus(&self, in_module: BotModule, in_chnl: Channel) -> StatusType { // Example usage : botmanager.modstatus( // BotModule("GambaCore"), // Channel("modulatingforce") @@ -714,7 +717,7 @@ impl ModulesManager { &self, requestor: String, requestor_badge: Option, - trg_module: ModType, + trg_module: BotModule, trg_level: StatusLvl, id: Arc>, ) -> ChangeResult @@ -764,11 +767,11 @@ impl ModulesManager { // if trg_level = StatusLvl::Instance , the temp_chnl = the broadcaster's or the chatter's let arb_chnl = match trg_level.clone() { - StatusLvl::Instance => ChType::Channel(requestor.to_lowercase()), + StatusLvl::Instance => Channel(requestor.to_lowercase()), StatusLvl::Ch(a) => a, }; - const OF_CMD_CHANNEL:ChType = Channel(String::new()); + const OF_CMD_CHANNEL:Channel = Channel(String::new()); let (admin_level_access,_) = idlock.can_user_run(requestor.clone(), arb_chnl.clone(), requestor_badge.clone(), vec![ @@ -903,7 +906,7 @@ impl ModulesManager { &self, requestor: String, requestor_badge: Option, - trg_module: ModType, + trg_module: BotModule, trg_level: StatusLvl, force: bool, id: Arc>, @@ -946,11 +949,11 @@ impl ModulesManager { // if trg_level = StatusLvl::Instance , the temp_chnl = the broadcaster's or the chatter's let arb_chnl = match trg_level.clone() { - StatusLvl::Instance => ChType::Channel(requestor.to_lowercase()), + StatusLvl::Instance => Channel(requestor.to_lowercase()), StatusLvl::Ch(a) => a, }; - const OF_CMD_CHANNEL:ChType = Channel(String::new()); + const OF_CMD_CHANNEL:Channel = Channel(String::new()); let (admin_level_access,_) = idlock.can_user_run(requestor.clone(), arb_chnl.clone(), requestor_badge.clone(), vec![ @@ -1080,7 +1083,7 @@ impl ModulesManager { ChangeResult::Failed("ERROR : Not implemented yet".to_string()) } - pub async fn set_instance_disabled(&self, in_module: ModType) -> (StatusType,ChangeResult) { + pub async fn set_instance_disabled(&self, in_module: BotModule) -> (StatusType,ChangeResult) { // at Instance level // - If core module, do nothing @@ -1115,7 +1118,7 @@ impl ModulesManager { // (StatusType::Disabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string())) } - pub async fn force_disable(&self, in_module: ModType) -> (StatusType,ChangeResult) { + pub async fn force_disable(&self, in_module: BotModule) -> (StatusType,ChangeResult) { // Disables the module at Instance level, and removes all Enabled at Channel level // - Bot Moderators MUST Re-enable if they were enabled before // - If core module, do nothing @@ -1159,7 +1162,7 @@ impl ModulesManager { // (StatusType::Disabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string())) } - pub async fn set_instance_enabled(&self, in_module: ModType) -> (StatusType,ChangeResult) { + pub async fn set_instance_enabled(&self, in_module: BotModule) -> (StatusType,ChangeResult) { // at Instance level // - If core module, do nothing @@ -1194,7 +1197,7 @@ impl ModulesManager { // (StatusType::Enabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string())) } - pub async fn set_ch_disabled(&self, in_module: ModType , in_chnl: ChType) -> (StatusType,ChangeResult) { + pub async fn set_ch_disabled(&self, in_module: BotModule , in_chnl: Channel) -> (StatusType,ChangeResult) { // at Instance level // - If core module, do nothing @@ -1232,7 +1235,7 @@ impl ModulesManager { // (StatusType::Disabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string())) } - pub async fn set_ch_enabled(&self, in_module: ModType , in_chnl: ChType) -> (StatusType,ChangeResult) { + pub async fn set_ch_enabled(&self, in_module: BotModule , in_chnl: Channel) -> (StatusType,ChangeResult) { // at Instance level // - If core module, do nothing @@ -1272,16 +1275,16 @@ impl ModulesManager { - pub async fn add_botaction(&self, in_module: ModType, in_action: BotAction) { + pub async fn add_botaction(&self, in_module: BotModule, 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) { + pub async fn add_core_act(&self, in_module: BotModule, in_action: BotAction) { self.int_add_botaction(in_module,ModGroup::Core,in_action).await; } - pub async fn affirm_in_statusdb(&self,in_module:ModType,in_modgroup: ModGroup) { + pub async fn affirm_in_statusdb(&self,in_module:BotModule,in_modgroup: ModGroup) { let mut dbt = self.statusdb.write().await; @@ -1297,7 +1300,7 @@ impl ModulesManager { } - async fn int_add_botaction(&self, in_module: ModType, in_modgroup: ModGroup, in_action: BotAction) { + async fn int_add_botaction(&self, in_module: BotModule, in_modgroup: ModGroup, in_action: BotAction) { botlog::trace( "Add botaction called", Some("ModulesManager > init()".to_string()), @@ -1320,7 +1323,7 @@ impl ModulesManager { // - If BotAction to Add is a BotCommand , In Module Manager DB (botactions), // Check All Other BotAction Command Names & Aliases to ensure they don't conflict - async fn find_conflict_module(mgr: &ModulesManager, act: &BotAction) -> Option { + async fn find_conflict_module(mgr: &ModulesManager, act: &BotAction) -> Option { if let BotAction::C(incmd) = act { let actdb = mgr.botactions.read().await; @@ -1395,12 +1398,12 @@ impl ModulesManager { ); } - fn _statuscleanup(&self, _: Option) { + fn _statuscleanup(&self, _: Option) { // internal cleans up statusdb . For example : // - remove redudancies . If we see several Enabled("m"), only keep 1x // - Clarify Conflict. If we see Enabled("m") and Disabled("m") , we remove Enabled("m") and keep Disabled("m") // the IDEAL is that this is ran before every read/update operation to ensure quality - // Option can pass Some(Channel("m")) (as an example) so statuscleanup only works on the given channel + // Option can pass Some(Channel("m")) (as an example) so statuscleanup only works on the given channel // Passing None to chnl may be a heavy operation, as this will review and look at the whole table } } @@ -1467,10 +1470,10 @@ mod core_modulesmanager { */ async fn complex_workflow( - in_module: ModType , + in_module: BotModule , in_modgroup : ModGroup , - in_chnl1 : ChType, - in_chnl2 : ChType) + in_chnl1 : Channel, + in_chnl2 : Channel) { @@ -1643,7 +1646,7 @@ mod core_modulesmanager { let in_module = BotModule("Experiments01".to_string()); let in_modgroup = ModGroup::Custom; let (in_chnl1,in_chnl2) = - (ChType::Channel("TestChannel01".to_string()),ChType::Channel("TestChannel02".to_string())); + (Channel("TestChannel01".to_string()),Channel("TestChannel02".to_string())); complex_workflow(in_module, in_modgroup, in_chnl1, in_chnl2).await; @@ -1659,7 +1662,7 @@ mod core_modulesmanager { let in_module = BotModule("CoreModule01".to_string()); let in_modgroup = ModGroup::Core; let (in_chnl1,in_chnl2) = - (ChType::Channel("TestChannel01".to_string()),ChType::Channel("TestChannel02".to_string())); + (Channel("TestChannel01".to_string()),Channel("TestChannel02".to_string())); complex_workflow(in_module, in_modgroup, in_chnl1, in_chnl2).await; @@ -1701,7 +1704,7 @@ mod core_modulesmanager { async fn inner_enable_disable_complex( requestor:String, - channel:ChType, + channel:Channel, idmgr:IdentityManager, modsmgr:Arc) { @@ -1724,7 +1727,7 @@ mod core_modulesmanager { let requestor_badge = None; // If they are a Mod on the Given Channel already, that can be evaluated without the current badge - const OF_CMD_CHANNEL:ChType = Channel(String::new()); + const OF_CMD_CHANNEL:Channel = Channel(String::new()); let (admin_level_access,_) = idlock.can_user_run(requestor.clone(), channel.clone(), requestor_badge.clone(), vec![ @@ -1773,7 +1776,7 @@ mod core_modulesmanager { // [-] requestor_badge: Option, - // [x] trg_module: ModType, + // [x] trg_module: BotModule, let trg_module = in_module; // [x] trg_level: StatusLvl, @@ -2020,7 +2023,7 @@ mod core_modulesmanager { assert!(rslt.contains(&identity::UserRole::BotAdmin)); - let channel = ChType::Channel("somechannel".to_string()); + let channel = Channel("somechannel".to_string()); inner_enable_disable_complex(requestor, channel, idmgr, modsmgr).await; @@ -2058,7 +2061,7 @@ mod core_modulesmanager { let requestor = "mod_user".to_string(); // let botadmin_badge = &None; - let channel = ChType::Channel("somechannel".to_string()); + let channel = Channel("somechannel".to_string()); idmgr.affirm_chatter_in_db(requestor.clone()).await; @@ -2109,7 +2112,7 @@ mod core_modulesmanager { let requestor = "regular_user".to_string(); - let channel = ChType::Channel("somechannel".to_string()); + let channel = Channel("somechannel".to_string()); idmgr.affirm_chatter_in_db(requestor.clone()).await; @@ -2142,7 +2145,7 @@ mod core_modulesmanager { let requestor = "regular_user".to_string(); - let channel = ChType::Channel("somechannel".to_string()); + let channel = Channel("somechannel".to_string()); idmgr.affirm_chatter_in_db(requestor.clone()).await; diff --git a/src/core/chat.rs b/src/core/chat.rs index fe49896..717b485 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -15,21 +15,21 @@ use rand::Rng; use crate::core::ratelimiter; use crate::core::ratelimiter::RateLimiter; -use crate::core::botinstance::ChType; +use crate::core::botinstance::Channel; use crate::core::botlog; -pub use ChType::Channel; + use tokio::time::{sleep, Duration}; #[derive(Clone)] pub struct Chat { - pub ratelimiters: Arc>>, // used to limit messages sent per channel + pub ratelimiters: Arc>>, // used to limit messages sent per channel pub client: TwitchIRCClient, StaticLoginCredentials>, } impl Chat { pub fn init( - ratelimiters: HashMap, + ratelimiters: HashMap, client: TwitchIRCClient, StaticLoginCredentials>, ) -> Chat { Chat { @@ -38,7 +38,7 @@ impl Chat { } } - pub async fn init_channel(&mut self, chnl: ChType) { + pub async fn init_channel(&mut self, chnl: Channel) { let n = RateLimiter::new(); self.ratelimiters.lock().await.insert(chnl, n); } diff --git a/src/core/identity.rs b/src/core/identity.rs index 0a27b60..20edc3e 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -8,7 +8,7 @@ use twitch_irc::message::PrivmsgMessage; use casual_logger::Log; use crate::core::bot_actions::actions_util::{self, BotAR}; -use crate::core::botinstance::{ChType,ChangeResult}; +use crate::core::botinstance::{Channel,ChangeResult}; use crate::core::botlog; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager}; @@ -60,8 +60,8 @@ pub async fn init(mgr: Arc) { exec_body: actions_util::asyncbox(cmd_promote), help: String::from("promote"), required_roles: vec![ - UserRole::Mod(ChType::Channel(String::new())), - UserRole::SupMod(ChType::Channel(String::new())), + UserRole::Mod(Channel(String::new())), + UserRole::SupMod(Channel(String::new())), UserRole::Broadcaster, UserRole::BotAdmin, ], @@ -172,7 +172,7 @@ pub async fn init(mgr: Arc) { sendername.clone(), &sender_badge, targetusr.to_string(), - Some(ChType::Channel(targetchnl.clone())), + Some(Channel(targetchnl.clone())), target_bot_admin_role, ) .await @@ -232,8 +232,8 @@ pub async fn init(mgr: Arc) { exec_body: actions_util::asyncbox(cmd_demote), help: String::from("demote"), required_roles: vec![ - UserRole::Mod(ChType::Channel(String::new())), - UserRole::SupMod(ChType::Channel(String::new())), + UserRole::Mod(Channel(String::new())), + UserRole::SupMod(Channel(String::new())), UserRole::Broadcaster, UserRole::BotAdmin, ], @@ -368,7 +368,7 @@ pub async fn init(mgr: Arc) { sendername.clone(), &sender_badge, targetusr.to_string(), - Some(ChType::Channel(targetchnl.clone())), + Some(Channel(targetchnl.clone())), ) .await } @@ -424,8 +424,8 @@ pub async fn init(mgr: Arc) { exec_body: actions_util::asyncbox(getroles), help: String::from("getroles"), required_roles: vec![ - UserRole::Mod(ChType::Channel(String::new())), - UserRole::SupMod(ChType::Channel(String::new())), + UserRole::Mod(Channel(String::new())), + UserRole::SupMod(Channel(String::new())), UserRole::Broadcaster, UserRole::BotAdmin, ], @@ -477,7 +477,7 @@ pub async fn init(mgr: Arc) { idlock .getspecialuserroles( String::from(targetuser), - Some(ChType::Channel(msg.channel_login.to_lowercase())), + Some(Channel(msg.channel_login.to_lowercase())), ) .await } @@ -486,20 +486,20 @@ pub async fn init(mgr: Arc) { let callersproles = idlock .getspecialuserroles( msg.sender.name.to_lowercase(), - Some(ChType::Channel(targetchnl.to_lowercase().to_string())), + Some(Channel(targetchnl.to_lowercase().to_string())), ) .await; - if callersproles.contains(&UserRole::Mod(ChType::Channel( + if callersproles.contains(&UserRole::Mod(Channel( targetchnl.to_lowercase().to_string(), - ))) || callersproles.contains(&UserRole::SupMod(ChType::Channel( + ))) || callersproles.contains(&UserRole::SupMod(Channel( targetchnl.to_lowercase().to_string(), ))) || callersproles.contains(&UserRole::Broadcaster) { idlock .getspecialuserroles( String::from(targetuser), - Some(ChType::Channel(targetchnl.to_lowercase())), + Some(Channel(targetchnl.to_lowercase())), ) .await } else { @@ -507,7 +507,7 @@ pub async fn init(mgr: Arc) { idlock .getspecialuserroles( String::from(targetuser), - Some(ChType::Channel(msg.channel_login.to_lowercase())), + Some(Channel(msg.channel_login.to_lowercase())), ) .await } @@ -535,18 +535,18 @@ pub async fn init(mgr: Arc) { let mut outmsg = "FeelsWowMan they're the broadcaster. ".to_string(); - if sproles.contains(&UserRole::Mod(ChType::Channel( + if sproles.contains(&UserRole::Mod(Channel( msg.channel_login.to_lowercase(), - ))) || sproles.contains(&UserRole::SupMod(ChType::Channel( + ))) || sproles.contains(&UserRole::SupMod(Channel( msg.channel_login.to_lowercase(), ))) || sproles.contains(&UserRole::BotAdmin) { outmsg += format!("Target chatter's user roles are : {:?}", sproles).as_str(); } outmsg - } else if sproles.contains(&UserRole::Mod(ChType::Channel( + } else if sproles.contains(&UserRole::Mod(Channel( msg.channel_login.to_lowercase(), - ))) || sproles.contains(&UserRole::SupMod(ChType::Channel( + ))) || sproles.contains(&UserRole::SupMod(Channel( msg.channel_login.to_lowercase(), ))) || sproles.contains(&UserRole::BotAdmin) { @@ -578,8 +578,8 @@ pub async fn init(mgr: Arc) { #[derive(Debug, PartialEq, Eq, Clone)] pub enum UserRole { Chatter, - Mod(ChType), // String specifies Channel - SupMod(ChType), // String specifies Channel + Mod(Channel), // String specifies Channel + SupMod(Channel), // String specifies Channel Broadcaster, BotAdmin, } @@ -698,7 +698,7 @@ impl IdentityManager { self.can_user_run( msg.sender.name.to_owned(), - ChType::Channel(msg.channel_login.to_owned()), + Channel(msg.channel_login.to_owned()), sender_badge, cmdreqroles, ) @@ -709,7 +709,7 @@ impl IdentityManager { pub async fn can_user_run( &mut self, usr: String, - channelname: ChType, + channelname: Channel, chat_badge: Option, cmdreqroles: Vec, // ) -> Result> { ) -> (Permissible, ChangeResult) { @@ -799,8 +799,8 @@ impl IdentityManager { // [x] and cmdreqroles includes UserRole::Mod("") OR UserRole::SupMod("") , Ok(Permissible::Allow) Some(ChatBadge::Broadcaster) => { if cmdreqroles.contains(&UserRole::Broadcaster) - || cmdreqroles.contains(&UserRole::Mod(ChType::Channel(String::new()))) - || cmdreqroles.contains(&UserRole::SupMod(ChType::Channel(String::new()))) + || cmdreqroles.contains(&UserRole::Mod(Channel(String::new()))) + || cmdreqroles.contains(&UserRole::SupMod(Channel(String::new()))) { // return Ok(Permissible::Allow) return ( @@ -869,7 +869,7 @@ impl IdentityManager { None, ); - if cmdreqroles.contains(&UserRole::Mod(ChType::Channel(String::new()))) { + if cmdreqroles.contains(&UserRole::Mod(Channel(String::new()))) { botlog::trace( "Command requires Mod Role", Some("identity.rs > can_user_run()".to_string()), @@ -905,7 +905,7 @@ impl IdentityManager { // [x] If cmdreqroles includes UserRole::SupMod("") , checks if chatter has UserRole::SupMod(channelname::ChType) to determine if Ok(Permissible::Allow) - if cmdreqroles.contains(&UserRole::SupMod(ChType::Channel(String::new()))) { + if cmdreqroles.contains(&UserRole::SupMod(Channel(String::new()))) { if let Some(a) = self .special_roles_users .read() @@ -979,7 +979,7 @@ impl IdentityManager { authorizer: String, authorizer_badge: &Option, trgchatter: String, - channel: Option, + channel: Option, trg_role: Option, ) -> ChangeResult { botlog::trace( @@ -1163,7 +1163,7 @@ impl IdentityManager { authorizer: String, authorizer_badge: &Option, trgchatter: String, - channel: Option, + channel: Option, ) -> ChangeResult { botlog::trace(&format!("IN VARS for demote() : Authorizer : {:?} ; Target Chatter : {} ; Target Channel : {:?}", authorizer,trgchatter,channel), Some("identity.rs > demote()".to_string()), None); @@ -1260,7 +1260,7 @@ impl IdentityManager { pub async fn getspecialuserroles( &self, chattername: String, - channel: Option, + channel: Option, ) -> Vec { /* Note : Ideally this be called for a given chatter name ? @@ -1285,14 +1285,14 @@ impl IdentityManager { let channel_out = match channel { Some(channel_tmp) => { match channel_tmp { - ChType::Channel(channel_tmp) => { + Channel(channel_tmp) => { // In this block, Some input channel is given // We're comparing the channel name with chattername to determine if they're a broadcaster if chattername == channel_tmp.to_lowercase() { evalsproles.push(UserRole::Broadcaster); } - Some(ChType::Channel(channel_tmp)) + Some(Channel(channel_tmp)) } // _ => () } } @@ -1379,8 +1379,8 @@ mod core_identity { fn user_role_identity() { Log::set_file_ext(Extension::Log); assert_eq!( - UserRole::SupMod(ChType::Channel("strong".to_string())), - UserRole::SupMod(ChType::Channel("Strong".to_lowercase())) + UserRole::SupMod(Channel("strong".to_string())), + UserRole::SupMod(Channel("Strong".to_lowercase())) ); } @@ -1395,7 +1395,7 @@ mod core_identity { let (usr, channelname, chat_badge, cmdreqroles) = ( bot, - ChType::Channel("twitchchanneltest".to_string()), + Channel("twitchchanneltest".to_string()), None, vec![] ); @@ -1420,7 +1420,7 @@ mod core_identity { let test_id_mgr = IdentityManager::init(); // [x] Mod Attempts to Promote User - let channel = Some(ChType::Channel("twitchchanneltest".to_string())); + let channel = Some(Channel("twitchchanneltest".to_string())); let trgchatter = "regularChatter".to_string(); let authorizer_badge = &Some(ChatBadge::Mod); let authorizer = "chatMod".to_string(); @@ -1450,7 +1450,7 @@ mod core_identity { let test_id_mgr = IdentityManager::init(); // [x] Broadcaster Promotes Chatter to SupMod - let channel = Some(ChType::Channel("broadcasterer".to_string())); + let channel = Some(Channel("broadcasterer".to_string())); let trgchatter = "regularChatter".to_string(); let authorizer_badge = &Some(ChatBadge::Broadcaster); let authorizer = "broadcasterer".to_string(); @@ -1475,7 +1475,7 @@ mod core_identity { .getspecialuserroles(trgchatter.clone(), channel.clone()) .await; - assert!(rslt.contains(&UserRole::Mod(ChType::Channel("broadcasterer".to_string())))); + assert!(rslt.contains(&UserRole::Mod(Channel("broadcasterer".to_string())))); let rslt = test_id_mgr .promote( @@ -1496,7 +1496,7 @@ mod core_identity { .getspecialuserroles(trgchatter.clone(), channel.clone()) .await; - assert!(rslt.contains(&UserRole::SupMod(ChType::Channel( + assert!(rslt.contains(&UserRole::SupMod(Channel( "broadcasterer".to_string() )))); @@ -1530,7 +1530,7 @@ mod core_identity { let broadcaster = "broadcasterer".to_string(); let broadcaster_badge = &Some(ChatBadge::Broadcaster); // let channel = Some(ChType::Channel(broadcaster.clone())); - let channel = ChType::Channel(broadcaster.clone()); + let channel = Channel(broadcaster.clone()); let supchatter = "superModerator".to_string(); let trg_role = None; @@ -1575,7 +1575,7 @@ mod core_identity { // let broadcaster = "broadcasterer".to_string(); let authorizer = supchatter; let authorizer_badge = &Some(ChatBadge::Broadcaster); - let channel = Some(ChType::Channel(broadcaster.clone())); + let channel = Some(Channel(broadcaster.clone())); let trgchatter = "regularChatter".to_string(); let trg_role = None; @@ -1646,7 +1646,7 @@ mod core_identity { // let broadcaster = "broadcasterer".to_string(); let authorizer = botadmin; let authorizer_badge = botadmin_badge; - let channel = Some(ChType::Channel("somechannel".to_string())); + let channel = Some(Channel("somechannel".to_string())); let trgchatter = "regularChatter".to_string(); let trg_role = None; @@ -1721,7 +1721,7 @@ mod core_identity { let supmod = "supmoder".to_string(); - let channel = Some(ChType::Channel("somechannel".to_string())); + let channel = Some(Channel("somechannel".to_string())); test_id_mgr.affirm_chatter_in_db(supmod.clone()).await; test_id_mgr diff --git a/src/custom/experiments.rs b/src/custom/experiments.rs index 529e551..f83693a 100644 --- a/src/custom/experiments.rs +++ b/src/custom/experiments.rs @@ -16,8 +16,7 @@ use std::sync::Arc; use twitch_irc::message::PrivmsgMessage; // use crate::core::botinstance::ChType::Channel; -use crate::core::botinstance::ChType; -use ChType::Channel; +use crate::core::botinstance::Channel; use crate::core::botlog; use crate::core::bot_actions::actions_util::{self, BotAR}; @@ -29,7 +28,7 @@ use tokio::time::{sleep, Duration}; pub async fn init(mgr: Arc) { - const OF_CMD_CHANNEL:ChType = Channel(String::new()); + const OF_CMD_CHANNEL:Channel = Channel(String::new()); // 1. Define the BotAction let botc1 = BotCommand {