From 38e7060d86fdefb26f75e5bee5a26066a4fbc5fe Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Mon, 25 Mar 2024 17:46:57 -0400 Subject: [PATCH] auto VIP --- src/core/botinstance.rs | 53 +++++++++- src/core/botmodules.rs | 6 +- src/core/chat.rs | 2 + src/core/identity.rs | 121 +++++++++++++++++++---- src/custom/experimental/experiment001.rs | 6 +- src/custom/experimental/experiment002.rs | 9 +- 6 files changed, 168 insertions(+), 29 deletions(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 4bcb352..e9d83cf 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -465,12 +465,55 @@ impl BotInstance { }; - botlock.botmgrs.chat.say_in_reply_to( - msg, - outstr, - // c.module.clone(), - params + botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif( + outstr.to_string() + ), + params.clone(), ).await; + + + // botlock.botmgrs.chat.say_in_reply_to( + // msg, + // outstr, + // // c.module.clone(), + // params + // ).await; + } + + if innerstr + .to_lowercase() + .contains(&"Auto Promoted VIP".to_lowercase()) + { + botlog::notice( + "Assigning VIP UserRole to VIP", + Some("botinstance > listener_main_prvmsg()".to_string()), + Some(msg), + ); + + let botlock = bot.read().await; + let outstr = + "❤️ a VIP - love ya!".to_string(); + + + let params = ExecBodyParams { + bot : Arc::clone(&bot), + msg : (*msg).clone(), + parent_act : Arc::clone(&act_clone), + + }; + + botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif( + outstr.to_string() + ), + params.clone(), + ).await; + + // botlock.botmgrs.chat.say_in_reply_to( + // msg, + // outstr, + // // c.module.clone(), + // params + // ).await; } } diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 188b560..c104fdd 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -19,6 +19,10 @@ Example */ + +const OF_CMD_CHANNEL:Channel = Channel(String::new()); + + use core::panic; use std::collections::HashMap; @@ -45,8 +49,6 @@ use super::identity::ChatBadge; pub async fn init(mgr: Arc) { - const OF_CMD_CHANNEL:Channel = Channel(String::new()); - // 1. Define the BotAction let botc1 = BotCommand { module: BotModule(String::from("core")), diff --git a/src/core/chat.rs b/src/core/chat.rs index 27d36e3..bb938cc 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -249,10 +249,12 @@ impl Chat { // [x] If user has any of the following target roles, they will be allowed - otherwise, they will not be allowed to send // - Otherwise if not (checked here) , this will not run // - NOTE : For now, I've removed BotAdmin just for curiosity - BotAdmins can always elevate themselves if they want + // - Will be adding VIP to this as this should include Channel_Level Roles if !(user_roles.contains(&identity::UserRole::Mod(Channel(channel_login.clone()))) || user_roles.contains(&identity::UserRole::SupMod(Channel(channel_login.clone()))) || user_roles.contains(&identity::UserRole::Broadcaster) + || user_roles.contains(&identity::UserRole::VIP(Channel(channel_login.clone()))) ) { diff --git a/src/core/identity.rs b/src/core/identity.rs index 03d4a6a..5f9a1d0 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -1,3 +1,8 @@ + + +const OF_CMD_CHANNEL:Channel = Channel(String::new()); + + use std::collections::HashMap; use std::sync::Arc; @@ -61,8 +66,8 @@ pub async fn init(mgr: Arc) { exec_body: actions_util::asyncbox(cmd_promote), help: String::from("promote"), required_roles: vec![ - UserRole::Mod(Channel(String::new())), - UserRole::SupMod(Channel(String::new())), + UserRole::Mod(OF_CMD_CHANNEL), + UserRole::SupMod(OF_CMD_CHANNEL), UserRole::Broadcaster, UserRole::BotAdmin, ], @@ -235,8 +240,8 @@ pub async fn init(mgr: Arc) { exec_body: actions_util::asyncbox(cmd_demote), help: String::from("demote"), required_roles: vec![ - UserRole::Mod(Channel(String::new())), - UserRole::SupMod(Channel(String::new())), + UserRole::Mod(OF_CMD_CHANNEL), + UserRole::SupMod(OF_CMD_CHANNEL), UserRole::Broadcaster, UserRole::BotAdmin, ], @@ -427,8 +432,8 @@ pub async fn init(mgr: Arc) { exec_body: actions_util::asyncbox(getroles), help: String::from("getroles"), required_roles: vec![ - UserRole::Mod(Channel(String::new())), - UserRole::SupMod(Channel(String::new())), + UserRole::Mod(OF_CMD_CHANNEL), + UserRole::SupMod(OF_CMD_CHANNEL), UserRole::Broadcaster, UserRole::BotAdmin, ], @@ -492,6 +497,8 @@ pub async fn init(mgr: Arc) { ) .await; + // Below appears to be validating if getroles() should run based on caller's specific roles + // - No Need to add VIP here if callersproles.contains(&UserRole::Mod(Channel( targetchnl.to_lowercase().to_string(), ))) || callersproles.contains(&UserRole::SupMod(Channel( @@ -536,6 +543,8 @@ pub async fn init(mgr: Arc) { let mut outmsg = "FeelsWowMan they're the broadcaster. ".to_string(); + // Below appears to be validating if getroles() should run based on caller's specific roles + // - No Need to add VIP here if sproles.contains(&UserRole::Mod(Channel( params.msg.channel_login.to_lowercase(), ))) || sproles.contains(&UserRole::SupMod(Channel( @@ -584,8 +593,9 @@ pub async fn init(mgr: Arc) { #[derive(Debug, PartialEq, Eq, Clone)] pub enum UserRole { Chatter, - Mod(Channel), // String specifies Channel - SupMod(Channel), // String specifies Channel + Mod(Channel), + SupMod(Channel), + VIP(Channel), Broadcaster, BotAdmin, } @@ -787,7 +797,7 @@ impl IdentityManager { ); } - let mut modrolechange = ChangeResult::NoChange("".to_string()); + let mut rolechange = ChangeResult::NoChange("".to_string()); match chat_badge { // [x] If chatBadge::Broadcaster ... @@ -795,8 +805,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(Channel(String::new()))) - || cmdreqroles.contains(&UserRole::SupMod(Channel(String::new()))) + || cmdreqroles.contains(&UserRole::Mod(OF_CMD_CHANNEL)) + || cmdreqroles.contains(&UserRole::SupMod(OF_CMD_CHANNEL)) { // return Ok(Permissible::Allow) return ( @@ -850,7 +860,48 @@ impl IdentityManager { usrroles_lock.push(UserRole::Mod(channelname.clone())); - modrolechange = ChangeResult::Success("Auto Promoted Mod".to_string()); + rolechange = ChangeResult::Success("Auto Promoted Mod".to_string()); + } + } + } + Some(ChatBadge::VIP) => { + botlog::info( + "VIP Chatbadge detected", + Some("identity.rs > can_user_run()".to_string()), + None, + ); + + let rolesdb = Arc::clone(&self.special_roles_users); + + self.affirm_chatter_in_db(usr.clone()).await; + + let rolesdb_lock = rolesdb.write().await; + + match (*rolesdb_lock).get(&usr.to_lowercase()) { + Some(usrroles) + if usrroles + .read() + .await + .contains(&UserRole::VIP(channelname.clone())) => + { + // Do nothing when theh have a VIP badge and have VIP badge for the channel + botlog::trace( + "Already a VIP in roles", + Some("identity.rs > can_user_run()".to_string()), + None, + ); + } + + _ => { + // In the event they have a VIP badge , are running a bot command, but don't have a channel mod role yet... + + let mut rolesdb_lock_mut = rolesdb_lock; + let usrroles = rolesdb_lock_mut.get_mut(&usr.to_lowercase()).unwrap(); + let mut usrroles_lock = usrroles.write().await; + + usrroles_lock.push(UserRole::VIP(channelname.clone())); + + rolechange = ChangeResult::Success("Auto Promoted VIP".to_string()); } } } @@ -865,7 +916,7 @@ impl IdentityManager { None, ); - if cmdreqroles.contains(&UserRole::Mod(Channel(String::new()))) { + if cmdreqroles.contains(&UserRole::Mod(OF_CMD_CHANNEL)) { botlog::trace( "Command requires Mod Role", Some("identity.rs > can_user_run()".to_string()), @@ -894,14 +945,14 @@ impl IdentityManager { Some("identity.rs > can_user_run()".to_string()), None, ); - return (Permissible::Allow, modrolechange); + return (Permissible::Allow, rolechange); } } } // [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(String::new()))) { + if cmdreqroles.contains(&UserRole::SupMod(OF_CMD_CHANNEL)) { if let Some(a) = self .special_roles_users .read() @@ -912,7 +963,7 @@ impl IdentityManager { .await .contains(&UserRole::SupMod(channelname.clone())) { - return (Permissible::Allow, modrolechange); + return (Permissible::Allow, rolechange); } } } @@ -959,11 +1010,47 @@ impl IdentityManager { ); if a.read().await.contains(&UserRole::BotAdmin) { - return (Permissible::Allow, modrolechange); + return (Permissible::Allow, rolechange); } } } + // [x] If cmdreqroles includes UserRole::VIP and chatter has UserRole::VIP , Ok(Permissible::Allow) + + if cmdreqroles.contains(&UserRole::VIP(OF_CMD_CHANNEL)) { + + botlog::trace( + "Command requires VIP Role", + Some("identity.rs > can_user_run()".to_string()), + None, + ); + + if let Some(a) = self + .special_roles_users + .read() + .await + .get(&usr.to_lowercase()) + { + botlog::trace( + "Special roles found for user", + Some("identity.rs > can_user_run()".to_string()), + None, + ); + + if a.read().await.contains(&UserRole::VIP(channelname.clone())) + { + botlog::trace( + "> Special Role Identified : VIP ", + Some("identity.rs > can_user_run()".to_string()), + None, + ); + return (Permissible::Allow, rolechange); + } + } + + } + + ( Permissible::Block, ChangeResult::NoChange("Not any permissiable condition".to_string()), diff --git a/src/custom/experimental/experiment001.rs b/src/custom/experimental/experiment001.rs index 58d0c59..dd3cba4 100644 --- a/src/custom/experimental/experiment001.rs +++ b/src/custom/experimental/experiment001.rs @@ -10,6 +10,10 @@ */ + +const OF_CMD_CHANNEL:Channel = Channel(String::new()); + + use rand::Rng; use std::sync::Arc; @@ -26,8 +30,6 @@ use tokio::time::{sleep, Duration}; pub async fn init(mgr: Arc) { - const OF_CMD_CHANNEL:Channel = Channel(String::new()); - // 1. Define the BotAction let botc1 = BotCommand { module: BotModule(String::from("experiments001")), diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index 3be88ac..a4ecb25 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -10,6 +10,10 @@ */ + +const OF_CMD_CHANNEL:Channel = Channel(String::new()); + + use std::sync::Arc; use chrono::{TimeZone,Local}; @@ -28,8 +32,6 @@ use crate::core::identity::UserRole::*; pub async fn init(mgr: Arc) { - const OF_CMD_CHANNEL:Channel = Channel(String::new()); - // 1. Define the BotAction let botc1 = BotCommand { @@ -42,7 +44,8 @@ pub async fn init(mgr: Arc) { help: String::from("Test Command tester"), required_roles: vec![ BotAdmin, - Mod(OF_CMD_CHANNEL), + // Mod(OF_CMD_CHANNEL), + VIP(OF_CMD_CHANNEL), ], };