adj off construct

adj off construct
This commit is contained in:
ModulatingForce 2024-03-23 14:00:20 -04:00
parent 0f1cb576a4
commit 9a3d0aacda
4 changed files with 61 additions and 51 deletions

View file

@ -415,14 +415,14 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// BotModule(String), // BotModule(String),
// } // }
pub struct BotModule(String); pub struct BotModule(pub String);
//botmodule simplified from enum to tuple struct // //botmodule simplified from enum to tuple struct
impl BotModule{ // impl BotModule{
pub fn construct(module_name:String) -> BotModule // pub fn construct(module_name:String) -> BotModule
{ // {
BotModule(module_name) // BotModule(module_name)
} // }
} // }
impl PartialEq for BotModule { impl PartialEq for BotModule {

View file

@ -58,7 +58,7 @@ impl Chat {
let contextratelimiter = rllock let contextratelimiter = rllock
// .get_mut() // .get_mut()
.get_mut(&Channel::construct(String::from(&msg.channel_login))) .get_mut(&Channel(String::from(&msg.channel_login)))
.expect("ERROR: Issue with Rate limiters"); .expect("ERROR: Issue with Rate limiters");
// Continue to check the limiter and sleep if required if the minimum is not reached // Continue to check the limiter and sleep if required if the minimum is not reached

View file

@ -54,14 +54,14 @@ pub async fn init(mgr: Arc<ModulesManager>) {
); );
let tempb = BotCommand { let tempb = BotCommand {
module: BotModule::construct(String::from("identity")), module: BotModule(String::from("identity")),
command: String::from("promote"), // command call name command: String::from("promote"), // command call name
alias: vec![], // String of alternative names alias: vec![], // String of alternative names
exec_body: actions_util::asyncbox(cmd_promote), exec_body: actions_util::asyncbox(cmd_promote),
help: String::from("promote"), help: String::from("promote"),
required_roles: vec![ required_roles: vec![
UserRole::Mod(Channel::construct(String::new())), UserRole::Mod(Channel(String::new())),
UserRole::SupMod(Channel::construct(String::new())), UserRole::SupMod(Channel(String::new())),
UserRole::Broadcaster, UserRole::Broadcaster,
UserRole::BotAdmin, UserRole::BotAdmin,
], ],
@ -172,7 +172,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
sendername.clone(), sendername.clone(),
&sender_badge, &sender_badge,
targetusr.to_string(), targetusr.to_string(),
Some(Channel::construct(targetchnl.clone())), Some(Channel(targetchnl.clone())),
target_bot_admin_role, target_bot_admin_role,
) )
.await .await
@ -226,14 +226,14 @@ pub async fn init(mgr: Arc<ModulesManager>) {
} }
let tempb = BotCommand { let tempb = BotCommand {
module: BotModule::construct(String::from("identity")), module: BotModule(String::from("identity")),
command: String::from("demote"), // command call name command: String::from("demote"), // command call name
alias: vec![], // String of alternative names alias: vec![], // String of alternative names
exec_body: actions_util::asyncbox(cmd_demote), exec_body: actions_util::asyncbox(cmd_demote),
help: String::from("demote"), help: String::from("demote"),
required_roles: vec![ required_roles: vec![
UserRole::Mod(Channel::construct(String::new())), UserRole::Mod(Channel(String::new())),
UserRole::SupMod(Channel::construct(String::new())), UserRole::SupMod(Channel(String::new())),
UserRole::Broadcaster, UserRole::Broadcaster,
UserRole::BotAdmin, UserRole::BotAdmin,
], ],
@ -368,7 +368,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
sendername.clone(), sendername.clone(),
&sender_badge, &sender_badge,
targetusr.to_string(), targetusr.to_string(),
Some(Channel::construct(targetchnl.clone())), Some(Channel(targetchnl.clone())),
) )
.await .await
} }
@ -418,14 +418,14 @@ pub async fn init(mgr: Arc<ModulesManager>) {
} }
let tempcomm = BotCommand { let tempcomm = BotCommand {
module: BotModule::construct(String::from("identity")), module: BotModule(String::from("identity")),
command: String::from("getroles"), // command call name command: String::from("getroles"), // command call name
alias: vec![], // String of alternative names alias: vec![], // String of alternative names
exec_body: actions_util::asyncbox(getroles), exec_body: actions_util::asyncbox(getroles),
help: String::from("getroles"), help: String::from("getroles"),
required_roles: vec![ required_roles: vec![
UserRole::Mod(Channel::construct(String::new())), UserRole::Mod(Channel(String::new())),
UserRole::SupMod(Channel::construct(String::new())), UserRole::SupMod(Channel(String::new())),
UserRole::Broadcaster, UserRole::Broadcaster,
UserRole::BotAdmin, UserRole::BotAdmin,
], ],
@ -477,7 +477,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
idlock idlock
.getspecialuserroles( .getspecialuserroles(
String::from(targetuser), String::from(targetuser),
Some(Channel::construct(msg.channel_login.to_lowercase())), Some(Channel(msg.channel_login.to_lowercase())),
) )
.await .await
} }
@ -486,20 +486,20 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let callersproles = idlock let callersproles = idlock
.getspecialuserroles( .getspecialuserroles(
msg.sender.name.to_lowercase(), msg.sender.name.to_lowercase(),
Some(Channel::construct(targetchnl.to_lowercase().to_string())), Some(Channel(targetchnl.to_lowercase().to_string())),
) )
.await; .await;
if callersproles.contains(&UserRole::Mod(Channel::construct( if callersproles.contains(&UserRole::Mod(Channel(
targetchnl.to_lowercase().to_string(), targetchnl.to_lowercase().to_string(),
))) || callersproles.contains(&UserRole::SupMod(Channel::construct( ))) || callersproles.contains(&UserRole::SupMod(Channel(
targetchnl.to_lowercase().to_string(), targetchnl.to_lowercase().to_string(),
))) || callersproles.contains(&UserRole::Broadcaster) ))) || callersproles.contains(&UserRole::Broadcaster)
{ {
idlock idlock
.getspecialuserroles( .getspecialuserroles(
String::from(targetuser), String::from(targetuser),
Some(Channel::construct(targetchnl.to_lowercase())), Some(Channel(targetchnl.to_lowercase())),
) )
.await .await
} else { } else {
@ -507,7 +507,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
idlock idlock
.getspecialuserroles( .getspecialuserroles(
String::from(targetuser), String::from(targetuser),
Some(Channel::construct(msg.channel_login.to_lowercase())), Some(Channel(msg.channel_login.to_lowercase())),
) )
.await .await
} }
@ -535,18 +535,18 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let mut outmsg = "FeelsWowMan they're the broadcaster. ".to_string(); let mut outmsg = "FeelsWowMan they're the broadcaster. ".to_string();
if sproles.contains(&UserRole::Mod(Channel::construct( if sproles.contains(&UserRole::Mod(Channel(
msg.channel_login.to_lowercase(), msg.channel_login.to_lowercase(),
))) || sproles.contains(&UserRole::SupMod(Channel::construct( ))) || sproles.contains(&UserRole::SupMod(Channel(
msg.channel_login.to_lowercase(), msg.channel_login.to_lowercase(),
))) || sproles.contains(&UserRole::BotAdmin) ))) || sproles.contains(&UserRole::BotAdmin)
{ {
outmsg += format!("Target chatter's user roles are : {:?}", sproles).as_str(); outmsg += format!("Target chatter's user roles are : {:?}", sproles).as_str();
} }
outmsg outmsg
} else if sproles.contains(&UserRole::Mod(Channel::construct( } else if sproles.contains(&UserRole::Mod(Channel(
msg.channel_login.to_lowercase(), msg.channel_login.to_lowercase(),
))) || sproles.contains(&UserRole::SupMod(Channel::construct( ))) || sproles.contains(&UserRole::SupMod(Channel(
msg.channel_login.to_lowercase(), msg.channel_login.to_lowercase(),
))) || sproles.contains(&UserRole::BotAdmin) ))) || sproles.contains(&UserRole::BotAdmin)
{ {
@ -698,7 +698,8 @@ impl IdentityManager {
self.can_user_run( self.can_user_run(
msg.sender.name.to_owned(), msg.sender.name.to_owned(),
Channel::construct(msg.channel_login.to_owned()), // Channel::construct(msg.channel_login.to_owned()),
Channel(msg.channel_login.to_owned()),
sender_badge, sender_badge,
cmdreqroles, cmdreqroles,
) )
@ -798,9 +799,13 @@ impl IdentityManager {
// [x] and cmdreqroles includes UserRole::Broadcaster , Ok(Permissible::Allow) // [x] and cmdreqroles includes UserRole::Broadcaster , Ok(Permissible::Allow)
// [x] and cmdreqroles includes UserRole::Mod("") OR UserRole::SupMod("") , Ok(Permissible::Allow) // [x] and cmdreqroles includes UserRole::Mod("") OR UserRole::SupMod("") , Ok(Permissible::Allow)
Some(ChatBadge::Broadcaster) => { Some(ChatBadge::Broadcaster) => {
// if cmdreqroles.contains(&UserRole::Broadcaster)
// || cmdreqroles.contains(&UserRole::Mod(Channel::construct(String::new())))
// || cmdreqroles.contains(&UserRole::SupMod(Channel::construct(String::new())))
// {
if cmdreqroles.contains(&UserRole::Broadcaster) if cmdreqroles.contains(&UserRole::Broadcaster)
|| cmdreqroles.contains(&UserRole::Mod(Channel::construct(String::new()))) || cmdreqroles.contains(&UserRole::Mod(Channel(String::new())))
|| cmdreqroles.contains(&UserRole::SupMod(Channel::construct(String::new()))) || cmdreqroles.contains(&UserRole::SupMod(Channel(String::new())))
{ {
// return Ok(Permissible::Allow) // return Ok(Permissible::Allow)
return ( return (
@ -869,7 +874,8 @@ impl IdentityManager {
None, None,
); );
if cmdreqroles.contains(&UserRole::Mod(Channel::construct(String::new()))) { // if cmdreqroles.contains(&UserRole::Mod(Channel::construct(String::new()))) {
if cmdreqroles.contains(&UserRole::Mod(Channel(String::new()))) {
botlog::trace( botlog::trace(
"Command requires Mod Role", "Command requires Mod Role",
Some("identity.rs > can_user_run()".to_string()), Some("identity.rs > can_user_run()".to_string()),
@ -905,7 +911,8 @@ impl IdentityManager {
// [x] If cmdreqroles includes UserRole::SupMod("") , checks if chatter has UserRole::SupMod(channelname::ChType) to determine if Ok(Permissible::Allow) // [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(Channel::construct(String::new()))) { // if cmdreqroles.contains(&UserRole::SupMod(Channel::construct(String::new()))) {
if cmdreqroles.contains(&UserRole::SupMod(Channel(String::new()))) {
if let Some(a) = self if let Some(a) = self
.special_roles_users .special_roles_users
.read() .read()
@ -1376,8 +1383,8 @@ mod core_identity {
fn user_role_identity() { fn user_role_identity() {
Log::set_file_ext(Extension::Log); Log::set_file_ext(Extension::Log);
assert_eq!( assert_eq!(
UserRole::SupMod(Channel::construct("strong".to_string())), UserRole::SupMod(Channel("strong".to_string())),
UserRole::SupMod(Channel::construct("Strong".to_lowercase())) UserRole::SupMod(Channel("Strong".to_lowercase()))
); );
} }
@ -1392,7 +1399,8 @@ mod core_identity {
let (usr, channelname, chat_badge, cmdreqroles) = ( let (usr, channelname, chat_badge, cmdreqroles) = (
bot, bot,
Channel::construct("twitchchanneltest".to_string()), // Channel::construct("twitchchanneltest".to_string()),
Channel("twitchchanneltest".to_string()),
None, None,
vec![] vec![]
); );
@ -1417,7 +1425,8 @@ mod core_identity {
let test_id_mgr = IdentityManager::init(); let test_id_mgr = IdentityManager::init();
// [x] Mod Attempts to Promote User // [x] Mod Attempts to Promote User
let channel = Some(Channel::construct("twitchchanneltest".to_string())); // let channel = Some(Channel::construct("twitchchanneltest".to_string()));
let channel = Some(Channel("twitchchanneltest".to_string()));
let trgchatter = "regularChatter".to_string(); let trgchatter = "regularChatter".to_string();
let authorizer_badge = &Some(ChatBadge::Mod); let authorizer_badge = &Some(ChatBadge::Mod);
let authorizer = "chatMod".to_string(); let authorizer = "chatMod".to_string();
@ -1447,7 +1456,8 @@ mod core_identity {
let test_id_mgr = IdentityManager::init(); let test_id_mgr = IdentityManager::init();
// [x] Broadcaster Promotes Chatter to SupMod // [x] Broadcaster Promotes Chatter to SupMod
let channel = Some(Channel::construct("broadcasterer".to_string())); // let channel = Some(Channel::construct("broadcasterer".to_string()));
let channel = Some(Channel("broadcasterer".to_string()));
let trgchatter = "regularChatter".to_string(); let trgchatter = "regularChatter".to_string();
let authorizer_badge = &Some(ChatBadge::Broadcaster); let authorizer_badge = &Some(ChatBadge::Broadcaster);
let authorizer = "broadcasterer".to_string(); let authorizer = "broadcasterer".to_string();
@ -1472,7 +1482,7 @@ mod core_identity {
.getspecialuserroles(trgchatter.clone(), channel.clone()) .getspecialuserroles(trgchatter.clone(), channel.clone())
.await; .await;
assert!(rslt.contains(&UserRole::Mod(Channel::construct("broadcasterer".to_string())))); assert!(rslt.contains(&UserRole::Mod(Channel("broadcasterer".to_string()))));
let rslt = test_id_mgr let rslt = test_id_mgr
.promote( .promote(
@ -1493,7 +1503,7 @@ mod core_identity {
.getspecialuserroles(trgchatter.clone(), channel.clone()) .getspecialuserroles(trgchatter.clone(), channel.clone())
.await; .await;
assert!(rslt.contains(&UserRole::SupMod(Channel::construct( assert!(rslt.contains(&UserRole::SupMod(Channel(
"broadcasterer".to_string() "broadcasterer".to_string()
)))); ))));
@ -1527,7 +1537,7 @@ mod core_identity {
let broadcaster = "broadcasterer".to_string(); let broadcaster = "broadcasterer".to_string();
let broadcaster_badge = &Some(ChatBadge::Broadcaster); let broadcaster_badge = &Some(ChatBadge::Broadcaster);
// let channel = Some(ChType::Channel(broadcaster.clone())); // let channel = Some(ChType::Channel(broadcaster.clone()));
let channel = Channel::construct(broadcaster.clone()); let channel = Channel(broadcaster.clone());
let supchatter = "superModerator".to_string(); let supchatter = "superModerator".to_string();
let trg_role = None; let trg_role = None;
@ -1572,7 +1582,7 @@ mod core_identity {
// let broadcaster = "broadcasterer".to_string(); // let broadcaster = "broadcasterer".to_string();
let authorizer = supchatter; let authorizer = supchatter;
let authorizer_badge = &Some(ChatBadge::Broadcaster); let authorizer_badge = &Some(ChatBadge::Broadcaster);
let channel = Some(Channel::construct(broadcaster.clone())); let channel = Some(Channel(broadcaster.clone()));
let trgchatter = "regularChatter".to_string(); let trgchatter = "regularChatter".to_string();
let trg_role = None; let trg_role = None;
@ -1643,7 +1653,7 @@ mod core_identity {
// let broadcaster = "broadcasterer".to_string(); // let broadcaster = "broadcasterer".to_string();
let authorizer = botadmin; let authorizer = botadmin;
let authorizer_badge = botadmin_badge; let authorizer_badge = botadmin_badge;
let channel = Some(Channel::construct("somechannel".to_string())); let channel = Some(Channel("somechannel".to_string()));
let trgchatter = "regularChatter".to_string(); let trgchatter = "regularChatter".to_string();
let trg_role = None; let trg_role = None;
@ -1718,7 +1728,7 @@ mod core_identity {
let supmod = "supmoder".to_string(); let supmod = "supmoder".to_string();
let channel = Some(Channel::construct("somechannel".to_string())); let channel = Some(Channel("somechannel".to_string()));
test_id_mgr.affirm_chatter_in_db(supmod.clone()).await; test_id_mgr.affirm_chatter_in_db(supmod.clone()).await;
test_id_mgr test_id_mgr

View file

@ -28,11 +28,11 @@ use tokio::time::{sleep, Duration};
pub async fn init(mgr: Arc<ModulesManager>) { pub async fn init(mgr: Arc<ModulesManager>) {
const OF_CMD_CHANNEL:Channel = Channel::construct(String::new()); const OF_CMD_CHANNEL:Channel = Channel(String::new());
// 1. Define the BotAction // 1. Define the BotAction
let botc1 = BotCommand { let botc1 = BotCommand {
module: BotModule::construct(String::from("experiments001")), module: BotModule(String::from("experiments001")),
command: String::from("test1"), // command call name command: String::from("test1"), // command call name
alias: vec![ alias: vec![
String::from("tester1"), String::from("tester1"),
@ -50,7 +50,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// 1. Define the BotAction // 1. Define the BotAction
let list1 = Listener { let list1 = Listener {
module: BotModule::construct(String::from("experiments001")), module: BotModule(String::from("experiments001")),
name: String::from("GoodGirl Listener"), name: String::from("GoodGirl Listener"),
exec_body: actions_util::asyncbox(good_girl), exec_body: actions_util::asyncbox(good_girl),
help: String::from(""), help: String::from(""),
@ -73,7 +73,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// 1. Define the BotAction // 1. Define the BotAction
let botc1 = BotCommand { let botc1 = BotCommand {
module: BotModule::construct(String::from("experiments001")), module: BotModule(String::from("experiments001")),
command: String::from("babygirl"), // command call name command: String::from("babygirl"), // command call name
alias: vec![], // String of alternative names alias: vec![], // String of alternative names
exec_body: actions_util::asyncbox(babygirl), exec_body: actions_util::asyncbox(babygirl),
@ -92,7 +92,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// 1. Define the BotAction // 1. Define the BotAction
let botc1 = BotCommand { let botc1 = BotCommand {
module: BotModule::construct(String::from("experiments001")), module: BotModule(String::from("experiments001")),
command: String::from("rtest"), // command call name command: String::from("rtest"), // command call name
alias: vec![], // String of alternative names alias: vec![], // String of alternative names
exec_body: actions_util::asyncbox(routinelike), exec_body: actions_util::asyncbox(routinelike),