This commit is contained in:
ModulatingForce 2024-03-25 17:46:57 -04:00
parent 1129e0d28a
commit 38e7060d86
6 changed files with 168 additions and 29 deletions

View file

@ -465,12 +465,55 @@ impl BotInstance {
}; };
botlock.botmgrs.chat.say_in_reply_to( botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
msg, outstr.to_string()
outstr, ),
// c.module.clone(), params.clone(),
params
).await; ).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;
} }
} }

View file

@ -19,6 +19,10 @@ Example
*/ */
const OF_CMD_CHANNEL:Channel = Channel(String::new());
use core::panic; use core::panic;
use std::collections::HashMap; use std::collections::HashMap;
@ -45,8 +49,6 @@ use super::identity::ChatBadge;
pub async fn init(mgr: Arc<ModulesManager>) { pub async fn init(mgr: Arc<ModulesManager>) {
const OF_CMD_CHANNEL:Channel = Channel(String::new());
// 1. Define the BotAction // 1. Define the BotAction
let botc1 = BotCommand { let botc1 = BotCommand {
module: BotModule(String::from("core")), module: BotModule(String::from("core")),

View file

@ -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 // [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 // - 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 // - 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()))) 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::SupMod(Channel(channel_login.clone())))
|| user_roles.contains(&identity::UserRole::Broadcaster) || user_roles.contains(&identity::UserRole::Broadcaster)
|| user_roles.contains(&identity::UserRole::VIP(Channel(channel_login.clone())))
) )
{ {

View file

@ -1,3 +1,8 @@
const OF_CMD_CHANNEL:Channel = Channel(String::new());
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
@ -61,8 +66,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
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(String::new())), UserRole::Mod(OF_CMD_CHANNEL),
UserRole::SupMod(Channel(String::new())), UserRole::SupMod(OF_CMD_CHANNEL),
UserRole::Broadcaster, UserRole::Broadcaster,
UserRole::BotAdmin, UserRole::BotAdmin,
], ],
@ -235,8 +240,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
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(String::new())), UserRole::Mod(OF_CMD_CHANNEL),
UserRole::SupMod(Channel(String::new())), UserRole::SupMod(OF_CMD_CHANNEL),
UserRole::Broadcaster, UserRole::Broadcaster,
UserRole::BotAdmin, UserRole::BotAdmin,
], ],
@ -427,8 +432,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
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(String::new())), UserRole::Mod(OF_CMD_CHANNEL),
UserRole::SupMod(Channel(String::new())), UserRole::SupMod(OF_CMD_CHANNEL),
UserRole::Broadcaster, UserRole::Broadcaster,
UserRole::BotAdmin, UserRole::BotAdmin,
], ],
@ -492,6 +497,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
) )
.await; .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( if callersproles.contains(&UserRole::Mod(Channel(
targetchnl.to_lowercase().to_string(), targetchnl.to_lowercase().to_string(),
))) || callersproles.contains(&UserRole::SupMod(Channel( ))) || callersproles.contains(&UserRole::SupMod(Channel(
@ -536,6 +543,8 @@ 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();
// 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( if sproles.contains(&UserRole::Mod(Channel(
params.msg.channel_login.to_lowercase(), params.msg.channel_login.to_lowercase(),
))) || sproles.contains(&UserRole::SupMod(Channel( ))) || sproles.contains(&UserRole::SupMod(Channel(
@ -584,8 +593,9 @@ pub async fn init(mgr: Arc<ModulesManager>) {
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]
pub enum UserRole { pub enum UserRole {
Chatter, Chatter,
Mod(Channel), // String specifies Channel Mod(Channel),
SupMod(Channel), // String specifies Channel SupMod(Channel),
VIP(Channel),
Broadcaster, Broadcaster,
BotAdmin, BotAdmin,
} }
@ -787,7 +797,7 @@ impl IdentityManager {
); );
} }
let mut modrolechange = ChangeResult::NoChange("".to_string()); let mut rolechange = ChangeResult::NoChange("".to_string());
match chat_badge { match chat_badge {
// [x] If chatBadge::Broadcaster ... // [x] If chatBadge::Broadcaster ...
@ -795,8 +805,8 @@ impl IdentityManager {
// [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) if cmdreqroles.contains(&UserRole::Broadcaster)
|| cmdreqroles.contains(&UserRole::Mod(Channel(String::new()))) || cmdreqroles.contains(&UserRole::Mod(OF_CMD_CHANNEL))
|| cmdreqroles.contains(&UserRole::SupMod(Channel(String::new()))) || cmdreqroles.contains(&UserRole::SupMod(OF_CMD_CHANNEL))
{ {
// return Ok(Permissible::Allow) // return Ok(Permissible::Allow)
return ( return (
@ -850,7 +860,48 @@ impl IdentityManager {
usrroles_lock.push(UserRole::Mod(channelname.clone())); 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, None,
); );
if cmdreqroles.contains(&UserRole::Mod(Channel(String::new()))) { if cmdreqroles.contains(&UserRole::Mod(OF_CMD_CHANNEL)) {
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()),
@ -894,14 +945,14 @@ impl IdentityManager {
Some("identity.rs > can_user_run()".to_string()), Some("identity.rs > can_user_run()".to_string()),
None, 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) // [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 if let Some(a) = self
.special_roles_users .special_roles_users
.read() .read()
@ -912,7 +963,7 @@ impl IdentityManager {
.await .await
.contains(&UserRole::SupMod(channelname.clone())) .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) { 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, Permissible::Block,
ChangeResult::NoChange("Not any permissiable condition".to_string()), ChangeResult::NoChange("Not any permissiable condition".to_string()),

View file

@ -10,6 +10,10 @@
*/ */
const OF_CMD_CHANNEL:Channel = Channel(String::new());
use rand::Rng; use rand::Rng;
use std::sync::Arc; use std::sync::Arc;
@ -26,8 +30,6 @@ 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(String::new());
// 1. Define the BotAction // 1. Define the BotAction
let botc1 = BotCommand { let botc1 = BotCommand {
module: BotModule(String::from("experiments001")), module: BotModule(String::from("experiments001")),

View file

@ -10,6 +10,10 @@
*/ */
const OF_CMD_CHANNEL:Channel = Channel(String::new());
use std::sync::Arc; use std::sync::Arc;
use chrono::{TimeZone,Local}; use chrono::{TimeZone,Local};
@ -28,8 +32,6 @@ use crate::core::identity::UserRole::*;
pub async fn init(mgr: Arc<ModulesManager>) { pub async fn init(mgr: Arc<ModulesManager>) {
const OF_CMD_CHANNEL:Channel = Channel(String::new());
// 1. Define the BotAction // 1. Define the BotAction
let botc1 = BotCommand { let botc1 = BotCommand {
@ -42,7 +44,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
help: String::from("Test Command tester"), help: String::from("Test Command tester"),
required_roles: vec![ required_roles: vec![
BotAdmin, BotAdmin,
Mod(OF_CMD_CHANNEL), // Mod(OF_CMD_CHANNEL),
VIP(OF_CMD_CHANNEL),
], ],
}; };