From 616d1f564fe5ecd33e532ecc7a84775599d41b5c Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sun, 24 Mar 2024 14:09:08 -0400 Subject: [PATCH 01/18] reorg botactions.rs --- src/core/bot_actions.rs | 29 +++++++++++++++++------- src/core/botinstance.rs | 3 ++- src/core/botmodules.rs | 3 ++- src/core/identity.rs | 3 ++- src/custom/experimental/experiment001.rs | 3 ++- src/custom/experimental/experiment002.rs | 3 ++- 6 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index 2e6b456..474291c 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -1,18 +1,31 @@ + +use twitch_irc::message::PrivmsgMessage; +use std::sync::Arc; +// use tokio::sync::{Mutex, RwLock}; +use tokio::sync::RwLock; + +use crate::core::botinstance::BotInstance; + + +pub type BotAR = Arc>; + + +pub struct ExecBodyParams { + bot : BotAR, + msg : PrivmsgMessage, + // parent_act : BotAction , +} + pub mod actions_util { + use super::*; + use std::boxed::Box; use std::future::Future; use std::pin::Pin; - use std::sync::Arc; - use tokio::sync::{Mutex, RwLock}; - use twitch_irc::message::PrivmsgMessage; - - use crate::core::botinstance::BotInstance; - - pub type BotAM = Arc>; - pub type BotAR = Arc>; + // pub type BotAM = Arc>; pub type ExecBody = Box< dyn Fn(BotAR, PrivmsgMessage) -> Pin + Send>> + Send + Sync, diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index c5b6dca..15f16a1 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -17,7 +17,8 @@ use casual_logger::Log; use crate::core::ratelimiter::RateLimiter; -use crate::core::bot_actions::actions_util::BotAR; +// use crate::core::bot_actions::actions_util::BotAR; +use crate::core::bot_actions::BotAR; use crate::core::botmodules::ModulesManager; use crate::core::identity::{IdentityManager, Permissible,self}; diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index f9d7ff0..d0028e3 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -32,7 +32,8 @@ use tokio::sync::RwLock; use async_trait::async_trait; -use self::bot_actions::actions_util::BotAR; +// use self::bot_actions::actions_util::BotAR; +use crate::core::bot_actions::BotAR; use crate::core::bot_actions::actions_util; use crate::core::botinstance::{BotInstance, Channel,ChangeResult}; use crate::core::botlog; diff --git a/src/core/identity.rs b/src/core/identity.rs index e816e9f..4243d26 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -7,7 +7,8 @@ use twitch_irc::message::PrivmsgMessage; use casual_logger::Log; -use crate::core::bot_actions::actions_util::{self, BotAR}; +use crate::core::bot_actions::actions_util; +use crate::core::bot_actions::BotAR; use crate::core::botinstance::{Channel,ChangeResult}; use crate::core::botlog; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager}; diff --git a/src/custom/experimental/experiment001.rs b/src/custom/experimental/experiment001.rs index f83693a..9b2c174 100644 --- a/src/custom/experimental/experiment001.rs +++ b/src/custom/experimental/experiment001.rs @@ -19,7 +19,8 @@ use twitch_irc::message::PrivmsgMessage; use crate::core::botinstance::Channel; use crate::core::botlog; -use crate::core::bot_actions::actions_util::{self, BotAR}; +use crate::core::bot_actions::actions_util; +use crate::core::bot_actions::BotAR; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager}; use crate::core::identity::UserRole::*; diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index 2a97b30..2dd63f4 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -24,7 +24,8 @@ use crate::core::botlog; use casual_logger::Log; -use crate::core::bot_actions::actions_util::{self, BotAR}; +use crate::core::bot_actions::actions_util; +use crate::core::bot_actions::BotAR; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager}; use crate::core::identity::UserRole::*; From 203f6af869787e6a96ef07b2073d052e40576482 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sun, 24 Mar 2024 14:38:09 -0400 Subject: [PATCH 02/18] ExecBodyParams --- src/core/bot_actions.rs | 12 ++-- src/core/botinstance.rs | 7 ++- src/core/botmodules.rs | 60 ++++++++++--------- src/core/identity.rs | 76 +++++++++++++----------- src/custom/experimental/experiment001.rs | 41 +++++++------ src/custom/experimental/experiment002.rs | 29 +++++---- 6 files changed, 124 insertions(+), 101 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index 474291c..ee589b4 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -11,8 +11,8 @@ pub type BotAR = Arc>; pub struct ExecBodyParams { - bot : BotAR, - msg : PrivmsgMessage, + pub bot : BotAR, + pub msg : PrivmsgMessage, // parent_act : BotAction , } @@ -28,13 +28,15 @@ pub mod actions_util { // pub type BotAM = Arc>; pub type ExecBody = Box< - dyn Fn(BotAR, PrivmsgMessage) -> Pin + Send>> + Send + Sync, + // dyn Fn(BotAR, PrivmsgMessage) -> Pin + Send>> + Send + Sync, + dyn Fn(ExecBodyParams) -> Pin + Send>> + Send + Sync, >; - pub fn asyncbox(f: fn(BotAR, PrivmsgMessage) -> T) -> ExecBody + // pub fn asyncbox(f: fn(BotAR, PrivmsgMessage) -> T) -> ExecBody + pub fn asyncbox(f: fn(ExecBodyParams) -> T) -> ExecBody where T: Future + Send + 'static, { - Box::new(move |a, b| Box::pin(f(a, b))) + Box::new(move |a| Box::pin(f(a))) } } diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 15f16a1..a714d9a 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -46,6 +46,7 @@ pub enum ChangeResult { //simplifying from enum to struct pub struct Channel(pub String); +use super::bot_actions::ExecBodyParams; use super::botmodules::StatusType; #[derive(Clone)] @@ -452,7 +453,8 @@ impl BotInstance { ); let a = Arc::clone(&bot); - c.execute(a, msg.clone()).await; + // c.execute(a, msg.clone()).await; + c.execute(ExecBodyParams { bot : a, msg : msg.clone() }).await; botlog::trace( "exit out of execution", @@ -498,7 +500,8 @@ impl BotInstance { } else { let a = Arc::clone(&bot); - l.execute(a, msg.clone()).await; + // l.execute(a, msg.clone()).await; + l.execute(ExecBodyParams { bot : a, msg : msg.clone()} ).await; } } diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index d0028e3..81f5ae0 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -35,6 +35,7 @@ use async_trait::async_trait; // use self::bot_actions::actions_util::BotAR; use crate::core::bot_actions::BotAR; use crate::core::bot_actions::actions_util; +use crate::core::bot_actions::ExecBodyParams; use crate::core::botinstance::{BotInstance, Channel,ChangeResult}; use crate::core::botlog; use crate::core::identity::{self, Permissible,IdentityManager}; @@ -70,7 +71,8 @@ pub async fn init(mgr: Arc) { // 2. Add the BotAction to ModulesManager botc1.add_core_to_modmgr(Arc::clone(&mgr)).await; - async fn cmd_enable(bot: BotAR, msg: PrivmsgMessage) { + // async fn cmd_enable(bot: BotAR, msg: PrivmsgMessage) { + async fn cmd_enable(params : ExecBodyParams) { /* There should be additional validation checks - BotAdmins can only run instance level (-i) enables @@ -108,7 +110,7 @@ pub async fn init(mgr: Arc) { let (arg1, arg2) = { - let mut argv = msg.message_text.split(' '); + let mut argv = params.msg.message_text.split(' '); argv.next(); // Skip the command name @@ -134,14 +136,14 @@ pub async fn init(mgr: Arc) { // [x] requestor: String, - let requestor = msg.clone().sender.name; + let requestor = params.msg.clone().sender.name; // [x] requestor_badge: Option, let mut requestor_badge_mut: Option = None; - for b in &msg.badges { + for b in ¶ms.msg.badges { if b.name == "moderator" { requestor_badge_mut = Some(ChatBadge::Mod); } else if b.name == "broadcaster" { @@ -161,20 +163,20 @@ pub async fn init(mgr: Arc) { // if let None = trg_module { if trg_module.is_none() { - let botlock = bot.read().await; + let botlock = params.bot.read().await; let outmsg = "uuh You need to pass a module"; botlog::debug( outmsg, Some("botmodules.rs > cmd_enable()".to_string()), - Some(&msg), + Some(¶ms.msg), ); botlock .botmgrs .chat - .say_in_reply_to(&msg, outmsg.to_string()) + .say_in_reply_to(¶ms.msg, outmsg.to_string()) .await; return; @@ -184,7 +186,7 @@ pub async fn init(mgr: Arc) { // [x] trg_level: StatusLvl, - let currchnl = msg.channel_login.to_lowercase(); + let currchnl = params.msg.channel_login.to_lowercase(); let trg_level = if arg1 == Some("-i") || arg1 == Some("-f") { StatusLvl::Instance } @@ -194,7 +196,7 @@ pub async fn init(mgr: Arc) { - let botlock = bot.read().await; + let botlock = params.bot.read().await; let modmgr = Arc::clone(&botlock.botmodules); let id = botlock.get_identity(); @@ -217,7 +219,7 @@ pub async fn init(mgr: Arc) { botlock .botmgrs .chat - .say_in_reply_to(&msg, outmsg.to_string()) + .say_in_reply_to(¶ms.msg, outmsg.to_string()) .await; @@ -244,7 +246,8 @@ pub async fn init(mgr: Arc) { // 2. Add the BotAction to ModulesManager botc1.add_core_to_modmgr(Arc::clone(&mgr)).await; - async fn cmd_disable(bot: BotAR, msg: PrivmsgMessage) { + // async fn cmd_disable(bot: BotAR, msg: PrivmsgMessage) { + async fn cmd_disable(params : ExecBodyParams) { /* There should be additional validation checks - BotAdmins can only run instance level (-i) disables and (-f) force disable @@ -284,7 +287,7 @@ pub async fn init(mgr: Arc) { let (arg1, arg2) = { - let mut argv = msg.message_text.split(' '); + let mut argv = params.msg.message_text.split(' '); argv.next(); // Skip the command name @@ -312,14 +315,14 @@ pub async fn init(mgr: Arc) { // [x] requestor: String, - let requestor = msg.clone().sender.name; + let requestor = params.msg.clone().sender.name; // [x] requestor_badge: Option, let mut requestor_badge_mut: Option = None; - for b in &msg.badges { + for b in ¶ms.msg.badges { if b.name == "moderator" { requestor_badge_mut = Some(ChatBadge::Mod); } else if b.name == "broadcaster" { @@ -338,20 +341,20 @@ pub async fn init(mgr: Arc) { // if let None = trg_module { if trg_module.is_none() { - let botlock = bot.read().await; + let botlock = params.bot.read().await; let outmsg = "uuh You need to pass a module"; botlog::debug( outmsg, Some("botmodules.rs > cmd_disable()".to_string()), - Some(&msg), + Some(¶ms.msg), ); botlock .botmgrs .chat - .say_in_reply_to(&msg, outmsg.to_string()) + .say_in_reply_to(¶ms.msg, outmsg.to_string()) .await; return; @@ -362,7 +365,7 @@ pub async fn init(mgr: Arc) { // [x] trg_level: StatusLvl, - let currchnl = msg.channel_login.to_lowercase(); + let currchnl = params.msg.channel_login.to_lowercase(); let trg_level = if arg1 == Some("-i") || arg1 == Some("-f") { StatusLvl::Instance } @@ -372,7 +375,7 @@ pub async fn init(mgr: Arc) { - let botlock = bot.read().await; + let botlock = params.bot.read().await; let modmgr = Arc::clone(&botlock.botmodules); let id = botlock.get_identity(); @@ -397,7 +400,7 @@ pub async fn init(mgr: Arc) { botlock .botmgrs .chat - .say_in_reply_to(&msg, outmsg.to_string()) + .say_in_reply_to(¶ms.msg, outmsg.to_string()) .await; @@ -461,10 +464,11 @@ pub enum BotAction { } impl BotAction { - pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) { + // pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) { + pub async fn execute(&self, params : ExecBodyParams) { match self { - BotAction::L(a) => a.execute(m, n).await, - BotAction::C(a) => a.execute(m, n).await, + BotAction::L(a) => a.execute(params).await, + BotAction::C(a) => a.execute(params).await, _ => (), } } @@ -488,8 +492,9 @@ pub struct BotCommand { } impl BotCommand { - pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) { - (*self.exec_body)(m, n).await; + // pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) { + pub async fn execute(&self, params : ExecBodyParams) { + (*self.exec_body)(params).await; } } @@ -524,8 +529,9 @@ pub struct Listener { } impl Listener { - pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) { - (self.exec_body)(m, n).await; + // pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) { + pub async fn execute(&self, params : ExecBodyParams) { + (self.exec_body)(params).await; } } diff --git a/src/core/identity.rs b/src/core/identity.rs index 4243d26..973ebe4 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -9,6 +9,7 @@ use casual_logger::Log; use crate::core::bot_actions::actions_util; use crate::core::bot_actions::BotAR; +use crate::core::bot_actions::ExecBodyParams; use crate::core::botinstance::{Channel,ChangeResult}; use crate::core::botlog; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager}; @@ -71,11 +72,12 @@ pub async fn init(mgr: Arc) { // tempb.add_to_modmgr(Arc::clone(&mgr)).await; tempb.add_core_to_modmgr(Arc::clone(&mgr)).await; - async fn cmd_promote(bot: BotAR, msg: PrivmsgMessage) { + // async fn cmd_promote(bot: BotAR, msg: PrivmsgMessage) { + async fn cmd_promote(params : ExecBodyParams) { botlog::trace( "Called cmd promote", Some("identity.rs > cmd_prommote()".to_string()), - Some(&msg), + Some(¶ms.msg), ); // -- If the BotCommand.command was called (e.g., promote) & required roles were validated OUTSIDE of this call @@ -104,16 +106,16 @@ pub async fn init(mgr: Arc) { */ - // println!("{}",msg.message_text); + // println!("{}",params.msg.message_text); botlog::trace( - format!("Twich Message > {}", msg.message_text).as_str(), + format!("Twich Message > {}", params.msg.message_text).as_str(), Some("identity.rs > cmd_promote()".to_string()), None, ); - let sendername = msg.clone().sender.name; + let sendername = params.msg.clone().sender.name; - let mut argv = msg.message_text.split(' '); + let mut argv = params.msg.message_text.split(' '); argv.next(); // Skip the command name @@ -123,7 +125,7 @@ pub async fn init(mgr: Arc) { let mut sender_badge: Option = None; - for b in &msg.badges { + for b in ¶ms.msg.badges { if b.name == "moderator" { sender_badge = Some(ChatBadge::Mod); } else if b.name == "broadcaster" { @@ -131,7 +133,7 @@ pub async fn init(mgr: Arc) { } } - let targetchnl = msg.channel_login.to_lowercase(); + let targetchnl = params.msg.channel_login.to_lowercase(); /* @@ -149,7 +151,7 @@ pub async fn init(mgr: Arc) { // [x] Get a required lock first - let botlock = bot.read().await; + let botlock = params.bot.read().await; let id = botlock.get_identity(); let idlock = id.read().await; @@ -209,13 +211,13 @@ pub async fn init(mgr: Arc) { botlog::debug( outmsg.as_str(), Some("identity.rs > cmd_prommote()".to_string()), - Some(&msg), + Some(¶ms.msg), ); botlock .botmgrs .chat - .say_in_reply_to(&msg, outmsg.to_string()) + .say_in_reply_to(¶ms.msg, outmsg.to_string()) .await; botlog::trace( @@ -244,11 +246,12 @@ pub async fn init(mgr: Arc) { // add_core_to_modmgr tempb.add_core_to_modmgr(Arc::clone(&mgr)).await; - async fn cmd_demote(bot: BotAR, msg: PrivmsgMessage) { + // async fn cmd_demote(bot: BotAR, msg: PrivmsgMessage) { + async fn cmd_demote(params : ExecBodyParams) { botlog::debug( "Called cmd demote", Some("identity.rs > cmd_demote()".to_string()), - Some(&msg), + Some(¶ms.msg), ); Log::flush(); @@ -281,7 +284,7 @@ pub async fn init(mgr: Arc) { // [x] Unwraps arguments from message let (arg1, _arg2) = { - let mut argv = msg.message_text.split(' '); + let mut argv = params.msg.message_text.split(' '); argv.next(); // Skip the command name @@ -320,11 +323,11 @@ pub async fn init(mgr: Arc) { */ - let sendername = msg.clone().sender.name; + let sendername = params.msg.clone().sender.name; let mut sender_badge_mut: Option = None; - for b in &msg.badges { + for b in ¶ms.msg.badges { if b.name == "moderator" { sender_badge_mut = Some(ChatBadge::Mod); } else if b.name == "broadcaster" { @@ -336,7 +339,7 @@ pub async fn init(mgr: Arc) { let targetusr = arg1; - let targetchnl = msg.channel_login.to_lowercase(); + let targetchnl = params.msg.channel_login.to_lowercase(); /* @@ -350,7 +353,7 @@ pub async fn init(mgr: Arc) { // [x] Get a required lock first - let botlock = bot.read().await; + let botlock = params.bot.read().await; let id = botlock.get_identity(); let idlock = id.read().await; @@ -408,13 +411,13 @@ pub async fn init(mgr: Arc) { botlog::debug( outmsg.as_str(), Some("identity.rs > cmd_demote()".to_string()), - Some(&msg), + Some(¶ms.msg), ); botlock .botmgrs .chat - .say_in_reply_to(&msg, outmsg.to_string()) + .say_in_reply_to(¶ms.msg, outmsg.to_string()) .await; } @@ -436,11 +439,12 @@ pub async fn init(mgr: Arc) { // add_core_to_modmgr tempcomm.add_core_to_modmgr(Arc::clone(&mgr)).await; - async fn getroles(bot: BotAR, msg: PrivmsgMessage) { + // async fn getroles(bot: BotAR, msg: PrivmsgMessage) { + async fn getroles(params : ExecBodyParams) { botlog::debug( "Called cmd getroles", Some("identity.rs > cmd_getroles()".to_string()), - Some(&msg), + Some(¶ms.msg), ); /* @@ -451,7 +455,7 @@ pub async fn init(mgr: Arc) { */ - let mut argv = msg.message_text.split(' '); + let mut argv = params.msg.message_text.split(' '); argv.next(); // Skip the command name @@ -466,7 +470,7 @@ pub async fn init(mgr: Arc) { let targetchnl = arg2; - let botlock = bot.read().await; + let botlock = params.bot.read().await; let id = botlock.get_identity(); @@ -478,7 +482,7 @@ pub async fn init(mgr: Arc) { idlock .getspecialuserroles( String::from(targetuser), - Some(Channel(msg.channel_login.to_lowercase())), + Some(Channel(params.msg.channel_login.to_lowercase())), ) .await } @@ -486,7 +490,7 @@ pub async fn init(mgr: Arc) { // [x] gets special roles for caller let callersproles = idlock .getspecialuserroles( - msg.sender.name.to_lowercase(), + params.msg.sender.name.to_lowercase(), Some(Channel(targetchnl.to_lowercase().to_string())), ) .await; @@ -508,7 +512,7 @@ pub async fn init(mgr: Arc) { idlock .getspecialuserroles( String::from(targetuser), - Some(Channel(msg.channel_login.to_lowercase())), + Some(Channel(params.msg.channel_login.to_lowercase())), ) .await } @@ -518,17 +522,17 @@ pub async fn init(mgr: Arc) { botlog::debug( &format!("User roles of Target Chatter >> {:?}", sproles), Some("identity.rs > init > getroles()".to_string()), - Some(&msg), + Some(¶ms.msg), ); botlog::trace( // &format!("Evaluating special roles"), "Evaluating special roles", Some("identity.rs > init > getroles()".to_string()), - Some(&msg), + Some(¶ms.msg), ); - let outmsg = if ((targetuser.to_lowercase() == msg.channel_login.to_lowercase()) + let outmsg = if ((targetuser.to_lowercase() == params.msg.channel_login.to_lowercase()) && arg2.is_none()) || (arg2.is_some() && arg2.unwrap() == targetuser.to_lowercase()) { @@ -537,18 +541,18 @@ pub async fn init(mgr: Arc) { let mut outmsg = "FeelsWowMan they're the broadcaster. ".to_string(); if sproles.contains(&UserRole::Mod(Channel( - msg.channel_login.to_lowercase(), + params.msg.channel_login.to_lowercase(), ))) || sproles.contains(&UserRole::SupMod(Channel( - msg.channel_login.to_lowercase(), + params.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(Channel( - msg.channel_login.to_lowercase(), + params.msg.channel_login.to_lowercase(), ))) || sproles.contains(&UserRole::SupMod(Channel( - msg.channel_login.to_lowercase(), + params.msg.channel_login.to_lowercase(), ))) || sproles.contains(&UserRole::BotAdmin) { format!("Target chatter's user roles are : {:?}", sproles) @@ -559,10 +563,10 @@ pub async fn init(mgr: Arc) { botlog::debug( format!("Chat Say Reply message : {}", outmsg).as_str(), Some("identity.rs > init > getroles()".to_string()), - Some(&msg), + Some(¶ms.msg), ); - botlock.botmgrs.chat.say_in_reply_to(&msg, outmsg).await; + botlock.botmgrs.chat.say_in_reply_to(¶ms.msg, outmsg).await; // [ ] NOTE : After the above, I should receive only the roles in the context of the current channel I received this ideally and maybe BotAdmin ; not outside } diff --git a/src/custom/experimental/experiment001.rs b/src/custom/experimental/experiment001.rs index 9b2c174..bcdb9e5 100644 --- a/src/custom/experimental/experiment001.rs +++ b/src/custom/experimental/experiment001.rs @@ -15,6 +15,7 @@ use std::sync::Arc; use twitch_irc::message::PrivmsgMessage; +use crate::core::bot_actions::ExecBodyParams; // use crate::core::botinstance::ChType::Channel; use crate::core::botinstance::Channel; use crate::core::botlog; @@ -110,19 +111,20 @@ pub async fn init(mgr: Arc) { } -async fn good_girl(bot: BotAR, msg: PrivmsgMessage) { +// async fn good_girl(bot: BotAR, msg: PrivmsgMessage) { + async fn good_girl(params : ExecBodyParams) { // [ ] Uses gen_ratio() to output bool based on a ratio probability . // - For example gen_ratio(2,3) is 2 out of 3 or 0.67% (numerator,denomitator) // - More Info : https://rust-random.github.io/rand/rand/trait.Rng.html#method.gen_ratio - if msg.sender.name.to_lowercase() == "ModulatingForce".to_lowercase() - || msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase() - // if msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase() + if params.msg.sender.name.to_lowercase() == "ModulatingForce".to_lowercase() + || params.msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase() + // if params.msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase() { botlog::debug( "Good Girl Detected > Pausechamp", Some("experiments > goodgirl()".to_string()), - Some(&msg), + Some(¶ms.msg), ); let rollwin = rand::thread_rng().gen_ratio(1, 1); @@ -131,10 +133,10 @@ async fn good_girl(bot: BotAR, msg: PrivmsgMessage) { botlog::debug( "Oh that's a good girl!", Some("experiments > goodgirl()".to_string()), - Some(&msg), + Some(¶ms.msg), ); - let bot = Arc::clone(&bot); + let bot = Arc::clone(¶ms.bot); let botlock = bot.read().await; @@ -142,32 +144,34 @@ async fn good_girl(bot: BotAR, msg: PrivmsgMessage) { botlock .botmgrs .chat - .say_in_reply_to(&msg, String::from("GoodGirl xdd ")) + .say_in_reply_to(¶ms.msg, String::from("GoodGirl xdd ")) .await; } } } -async fn testy(mut _chat: BotAR, msg: PrivmsgMessage) { +// async fn testy(mut _chat: BotAR, msg: PrivmsgMessage) { +async fn testy(params : ExecBodyParams) { println!("testy triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call botlog::debug( "testy triggered!", Some("experiments > testy()".to_string()), - Some(&msg), + Some(¶ms.msg), ); } -async fn babygirl(bot: BotAR, msg: PrivmsgMessage) { +// async fn babygirl(bot: BotAR, msg: PrivmsgMessage) { +async fn babygirl(params : ExecBodyParams) { println!("babygirl triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call botlog::debug( "babygirl triggered!", Some("experiments > babygirl()".to_string()), - Some(&msg), + Some(¶ms.msg), ); - let bot = Arc::clone(&bot); + let bot = Arc::clone(¶ms.bot); let botlock = bot.read().await; @@ -175,7 +179,7 @@ async fn babygirl(bot: BotAR, msg: PrivmsgMessage) { botlock .botmgrs .chat - .say_in_reply_to(&msg, String::from("16:13 notohh: cafdk")) + .say_in_reply_to(¶ms.msg, String::from("16:13 notohh: cafdk")) .await; @@ -184,7 +188,7 @@ async fn babygirl(bot: BotAR, msg: PrivmsgMessage) { botlock .botmgrs .chat - .say_in_reply_to(&msg, String::from("16:13 notohh: have fun eating princess")) + .say_in_reply_to(¶ms.msg, String::from("16:13 notohh: have fun eating princess")) .await; @@ -193,7 +197,7 @@ async fn babygirl(bot: BotAR, msg: PrivmsgMessage) { botlock .botmgrs .chat - .say_in_reply_to(&msg, String::from("16:13 notohh: baby girl")) + .say_in_reply_to(¶ms.msg, String::from("16:13 notohh: baby girl")) .await; @@ -202,12 +206,13 @@ async fn babygirl(bot: BotAR, msg: PrivmsgMessage) { -async fn routinelike(_bot: BotAR, msg: PrivmsgMessage) { +// async fn routinelike(_bot: BotAR, msg: PrivmsgMessage) { +async fn routinelike(params : ExecBodyParams) { println!("routinelike triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call botlog::debug( "routinelike triggered!", Some("experiments > routinelike()".to_string()), - Some(&msg), + Some(¶ms.msg), ); // spawn an async block that runs independently from others diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index 2dd63f4..8799f5a 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -17,6 +17,7 @@ use chrono::{TimeZone,Local}; use twitch_irc::message::PrivmsgMessage; +use crate::core::bot_actions::ExecBodyParams; // use crate::core::botinstance::ChType::Channel; use crate::core::botinstance::Channel; // use ChType::Channel; @@ -61,14 +62,16 @@ pub async fn init(mgr: Arc) { } -async fn sayout(bot: BotAR, msg: PrivmsgMessage) { +// async fn sayout(bot: BotAR, msg: PrivmsgMessage) { +async fn sayout(params : ExecBodyParams) { + /* usage : */ - let reply_parent = if let Some(Some(reply)) = msg.source.tags.0.get("reply-parent-msg-body") { + let reply_parent = if let Some(Some(reply)) = params.msg.source.tags.0.get("reply-parent-msg-body") { Some(reply) } else { None } ; @@ -79,7 +82,7 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { // } else { None } // ; - let reply_parent_ts = if let Some(Some(replyts)) = msg.source.tags.0.get("tmi-sent-ts") { + let reply_parent_ts = if let Some(Some(replyts)) = params.msg.source.tags.0.get("tmi-sent-ts") { let a: i64 = replyts.parse().unwrap(); let b = Local.timestamp_millis_opt(a).unwrap(); @@ -93,7 +96,7 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { let argrslt = - if let Some((_,str1)) = msg.message_text.split_once(' ') { + if let Some((_,str1)) = params.msg.message_text.split_once(' ') { if reply_parent.is_none() { if let Some((channelstr,msgstr)) = str1.split_once(' ') { Some((channelstr,msgstr)) @@ -114,7 +117,7 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { match argrslt { Some((trgchnl,outmsg)) => { - let bot = Arc::clone(&bot); + let bot = Arc::clone(¶ms.bot); let botlock = bot.read().await; @@ -141,7 +144,7 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { botlock .botmgrs .chat - .say_in_reply_to(&msg, format!("Not a Joined Channel : {}",trgchnl)) + .say_in_reply_to(¶ms.msg, format!("Not a Joined Channel : {}",trgchnl)) .await; @@ -178,8 +181,8 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { // srcmsg) format!("{} {} @ {} : {}", reply_parent_ts.unwrap(), - msg.sender.name, - msg.channel_login, + params.msg.sender.name, + params.msg.channel_login, srcmsg) } else { // format!("{} from #{} says : {}", @@ -187,8 +190,8 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { // msg.channel_login, // outmsg) format!("in {} - {} : {}", - msg.channel_login, - msg.sender.name, + params.msg.channel_login, + params.msg.sender.name, outmsg) }; @@ -206,10 +209,10 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { botlog::debug( "sayout had issues trying to parse arguments", Some("experiment002 > sayout".to_string()), - Some(&msg), + Some(¶ms.msg), ); - let bot = Arc::clone(&bot); + let bot = Arc::clone(¶ms.bot); let botlock = bot.read().await; @@ -217,7 +220,7 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) { botlock .botmgrs .chat - .say_in_reply_to(&msg, String::from("Invalid arguments")) + .say_in_reply_to(¶ms.msg, String::from("Invalid arguments")) .await; }, From 7e5e43fec3cb16af2b8cbd3b8c6708a786517761 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sun, 24 Mar 2024 15:46:08 -0400 Subject: [PATCH 03/18] parentact to ExecBodyParams --- src/core/bot_actions.rs | 6 +++-- src/core/botinstance.rs | 50 +++++++++++++++++++++++++++++------------ src/core/botmodules.rs | 17 ++++++++++---- src/main.rs | 6 ++++- 4 files changed, 58 insertions(+), 21 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index ee589b4..243d2d9 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -6,14 +6,16 @@ use tokio::sync::RwLock; use crate::core::botinstance::BotInstance; +use super::botmodules::BotAction; + pub type BotAR = Arc>; - +pub type ActAR = Arc>; pub struct ExecBodyParams { pub bot : BotAR, pub msg : PrivmsgMessage, - // parent_act : BotAction , + pub parent_act : ActAR , } pub mod actions_util { diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index a714d9a..5cdc60a 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -47,7 +47,7 @@ pub enum ChangeResult { pub struct Channel(pub String); use super::bot_actions::ExecBodyParams; -use super::botmodules::StatusType; +use super::botmodules::{BotAction, StatusType}; #[derive(Clone)] pub struct BotManagers { @@ -264,16 +264,6 @@ impl BotInstance { // // [ ] #todo Need to run through all Listener Bodies for Enabled Modules for the context of the message (e.g., ModStatus is Enabled in the context for the channel) - let botlock = bot.read().await; - let actsdb = Arc::clone(&botlock.botmodules.botactions); - let actsdblock = actsdb.read().await; - - botlog::debug( - format!("# of BotModules: {}", (*actsdblock).len()).as_str(), - Some("BotInstance > listener_main_prvmsg()".to_string()), - Some(msg), - ); - /* [ ] What we should do instead is : @@ -309,9 +299,30 @@ impl BotInstance { }, }; + + let botlock = bot.read().await; + let actsdb = Arc::clone(&botlock.botmodules.botactions); + let actsdblock = actsdb.read().await; + + botlog::debug( + format!("# of BotModules: {}", (*actsdblock).len()).as_str(), + Some("BotInstance > listener_main_prvmsg()".to_string()), + Some(msg), + ); + + for acts in (*actsdblock).values() { + + for a in acts { - match a { + + // let act_ar = Arc::new(RwLock::new(a)); + // let act_ar_clone = Arc::clone(&act_ar); + let act_clone = Arc::clone(a); + + // match a { + // match &(*act_ar_clone.read().await) { + match &(*act_clone.read().await) { crate::core::botmodules::BotAction::C(c) => { /* BotCommand handling - @@ -454,7 +465,13 @@ impl BotInstance { let a = Arc::clone(&bot); // c.execute(a, msg.clone()).await; - c.execute(ExecBodyParams { bot : a, msg : msg.clone() }).await; + // c.execute(ExecBodyParams { bot : a, msg : msg.clone() }).await; + c.execute(ExecBodyParams { + bot : a, + msg : msg.clone() , + // parent_act : BotAction::C(c) , + parent_act : Arc::clone(&act_clone), + }).await; botlog::trace( "exit out of execution", @@ -501,7 +518,12 @@ impl BotInstance { } else { let a = Arc::clone(&bot); // l.execute(a, msg.clone()).await; - l.execute(ExecBodyParams { bot : a, msg : msg.clone()} ).await; + l.execute(ExecBodyParams { + bot : a, + msg : msg.clone() , + // parent_act : BotAction::L(l) , + parent_act : Arc::clone(&act_clone), + } ).await; } } diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 81f5ae0..3796d82 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -573,10 +573,11 @@ impl BotActionTrait for Listener { pub struct Routine {} type StatusdbEntry = (ModGroup, Vec); +type ModuleActions = Vec>>; pub struct ModulesManager { statusdb: Arc>>, - pub botactions: Arc>>>, + pub botactions: Arc>>, } /* @@ -1329,12 +1330,20 @@ impl ModulesManager { // Check All Other BotAction Command Names & Aliases to ensure they don't conflict async fn find_conflict_module(mgr: &ModulesManager, act: &BotAction) -> Option { + if let BotAction::C(incmd) = act { let actdb = mgr.botactions.read().await; for (module, moduleactions) in &(*actdb) { - for modact in moduleactions.iter() { - if let BotAction::C(dbcmd) = &modact { + + + // for modact in moduleactions.iter() { + for modact_prelock in moduleactions.iter() { + + let modact = modact_prelock.read().await; + + // if let BotAction::C(dbcmd) = &modact { + if let BotAction::C(dbcmd) = &(*modact) { // At this point, there is an command incmd and looked up dbcmd // [x] check if given botcommand c.command:String conflicts with any in botactions @@ -1390,7 +1399,7 @@ impl ModulesManager { let mut a = self.botactions.write().await; let modactions = a.entry(in_module.clone()).or_insert(Vec::new()); - modactions.push(in_action); + modactions.push(Arc::new(RwLock::new(in_action))); botlog::trace( format!( diff --git a/src/main.rs b/src/main.rs index 40b5598..6bc6c0f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,7 +33,11 @@ pub async fn main() { for acts in (*actsdb_lock).values() { for act in acts { - let outstr = match act { + + let act_prelock = act; + let act = act_prelock.read().await; + + let outstr = match &(*act) { botmodules::BotAction::C(b) => { format!("bot actions > Command : {}", b.command) } From ee0b9ee19661a4821819aedee628c9ad1eae3bab Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sun, 24 Mar 2024 16:59:50 -0400 Subject: [PATCH 04/18] (init) say require parent module --- src/core/botinstance.rs | 11 +- src/core/botmodules.rs | 127 ++++++++++++++++++----- src/core/chat.rs | 15 ++- src/core/identity.rs | 98 +++++++++++++++-- src/custom/experimental/experiment001.rs | 100 +++++++++++++----- src/custom/experimental/experiment002.rs | 74 ++++++++++--- 6 files changed, 344 insertions(+), 81 deletions(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 5cdc60a..c09050a 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -412,7 +412,10 @@ impl BotInstance { let botlock = bot.read().await; let outstr = format!("sadg Module is disabled : {:?}",a); - botlock.botmgrs.chat.say_in_reply_to(msg, outstr).await; + botlock.botmgrs.chat.say_in_reply_to( + msg, + outstr, + c.module.clone()).await; } return; @@ -451,7 +454,11 @@ impl BotInstance { let botlock = bot.read().await; let outstr = "o7 a Mod. I kneel to serve! pepeKneel ".to_string(); - botlock.botmgrs.chat.say_in_reply_to(msg, outstr).await; + botlock.botmgrs.chat.say_in_reply_to( + msg, + outstr, + c.module.clone(), + ).await; } } diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 3796d82..87dd243 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -104,6 +104,22 @@ pub async fn init(mgr: Arc) { */ + /* + + Get parent module + + */ + + let params_clone = Arc::clone(¶ms.parent_act); + let actlock = params_clone.read().await; + let act = &(*actlock); + let parent_module = match act { + BotAction::C(c) => Some(&(*c).module), + BotAction::L(l) => Some(&(*l).module), + _ => None, + }; + + // [x] Unwraps arguments from message @@ -172,12 +188,17 @@ pub async fn init(mgr: Arc) { Some("botmodules.rs > cmd_enable()".to_string()), Some(¶ms.msg), ); - - botlock - .botmgrs - .chat - .say_in_reply_to(¶ms.msg, outmsg.to_string()) - .await; + + // Only call Say if there is a parent module passed + if parent_module.is_some() { + + + botlock + .botmgrs + .chat + .say_in_reply_to(¶ms.msg, outmsg.to_string() , parent_module.unwrap().clone()) + .await; + } return; @@ -216,11 +237,19 @@ pub async fn init(mgr: Arc) { ChangeResult::Success(a) => format!("YAAY Success : {}",a), }; - botlock - .botmgrs - .chat - .say_in_reply_to(¶ms.msg, outmsg.to_string()) - .await; + + // Only call Say if there is a parent module passed + if parent_module.is_some() { + + + botlock + .botmgrs + .chat + .say_in_reply_to(¶ms.msg, outmsg.to_string(),parent_module.unwrap().clone()) + .await; + + } + } @@ -282,6 +311,20 @@ pub async fn init(mgr: Arc) { 3c. , and is -f (forced) , return a Success */ + /* + [x] Get the parent module + */ + + let params_clone = Arc::clone(¶ms.parent_act); + let actlock = params_clone.read().await; + let act = &(*actlock); + let parent_module = match act { + BotAction::C(c) => Some(&(*c).module), + BotAction::L(l) => Some(&(*l).module), + _ => None, + }; + + // [x] Unwraps arguments from message @@ -350,13 +393,30 @@ pub async fn init(mgr: Arc) { Some("botmodules.rs > cmd_disable()".to_string()), Some(¶ms.msg), ); - - botlock + + + // let params_clone = Arc::clone(¶ms.parent_act); + // let actlock = params_clone.read().await; + // let act = &(*actlock); + // let parent_module = match act { + // BotAction::C(c) => Some(&(*c).module), + // BotAction::L(l) => Some(&(*l).module), + // _ => None, + // }; + + + + // Only call Say if there is a parent module passed + if parent_module.is_some() { + + botlock .botmgrs .chat - .say_in_reply_to(¶ms.msg, outmsg.to_string()) + .say_in_reply_to(¶ms.msg, outmsg.to_string(),parent_module.unwrap().clone()) .await; + } + return; } @@ -397,11 +457,35 @@ pub async fn init(mgr: Arc) { ChangeResult::Success(a) => format!("YAAY Success : {}",a), }; - botlock - .botmgrs - .chat - .say_in_reply_to(¶ms.msg, outmsg.to_string()) - .await; + + // let actlock = params.parent_act.read().await; + // let act = *actlock; + // let parent_module = match act { + // BotAction::C(c) => Some(c.module), + // BotAction::L(l) => Some(l.module), + // _ => None, + // }; + + + // let params_clone = Arc::clone(¶ms.parent_act); + // let actlock = params_clone.read().await; + // let act = &(*actlock); + // let parent_module = match act { + // BotAction::C(c) => Some(&(*c).module), + // BotAction::L(l) => Some(&(*l).module), + // _ => None, + // }; + + // Only call Say if there is a parent module passed + if parent_module.is_some() { + + botlock + .botmgrs + .chat + .say_in_reply_to(¶ms.msg, outmsg.to_string(),parent_module.unwrap().clone()) + .await; + + } @@ -413,13 +497,8 @@ pub async fn init(mgr: Arc) { #[derive(Debug, Clone)] -// pub enum BotModule { -// BotModule(String), -// } - pub struct BotModule(pub String); - impl PartialEq for BotModule { fn eq(&self, other: &Self) -> bool { let BotModule(name1) = self.clone(); diff --git a/src/core/chat.rs b/src/core/chat.rs index 1ba85e7..d379472 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -21,6 +21,8 @@ use crate::core::botlog; use tokio::time::{sleep, Duration}; +use super::botmodules::BotModule; + #[derive(Clone)] pub struct Chat { pub ratelimiters: Arc>>, // used to limit messages sent per channel @@ -54,7 +56,8 @@ impl Chat { - async fn send_botmsg(&self, msginput: BotMsgType<'_>) { + // async fn send_botmsg(&self, msginput: BotMsgType<'_>) { + async fn send_botmsg(&self, msginput: BotMsgType<'_>, _ : BotModule) { /* formats message before sending to TwitchIRC @@ -159,16 +162,18 @@ impl Chat { - pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String) { + // pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String) { + pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , parent_module : BotModule) { - self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg)).await; + self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg) , parent_module).await; } - pub async fn say(&self, channel_login: String, message: String) { + // pub async fn say(&self, channel_login: String, message: String) { + pub async fn say(&self, channel_login: String, message: String , parent_module : BotModule) { // more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say - self.send_botmsg(BotMsgType::Say(channel_login.to_lowercase(), message)).await; + self.send_botmsg(BotMsgType::Say(channel_login.to_lowercase(), message), parent_module).await; } async fn _me(&self, _: String, _: String) { diff --git a/src/core/identity.rs b/src/core/identity.rs index 973ebe4..5c2ede2 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -12,6 +12,7 @@ use crate::core::bot_actions::BotAR; use crate::core::bot_actions::ExecBodyParams; use crate::core::botinstance::{Channel,ChangeResult}; use crate::core::botlog; +use crate::core::botmodules::BotAction; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager}; use dotenv::dotenv; @@ -106,6 +107,21 @@ pub async fn init(mgr: Arc) { */ + + /* + [x] Get the parent module + */ + + let params_clone = Arc::clone(¶ms.parent_act); + let actlock = params_clone.read().await; + let act = &(*actlock); + let parent_module = match act { + BotAction::C(c) => Some(&(*c).module), + BotAction::L(l) => Some(&(*l).module), + _ => None, + }; + + // println!("{}",params.msg.message_text); botlog::trace( format!("Twich Message > {}", params.msg.message_text).as_str(), @@ -214,11 +230,20 @@ pub async fn init(mgr: Arc) { Some(¶ms.msg), ); - botlock - .botmgrs - .chat - .say_in_reply_to(¶ms.msg, outmsg.to_string()) - .await; + // Only call Say if there is a parent module passed + if parent_module.is_some() { + + + botlock + .botmgrs + .chat + .say_in_reply_to( + ¶ms.msg, + outmsg.to_string(), + parent_module.unwrap().clone()) + .await; + + } botlog::trace( // &format!("End of cmd_promote()"), @@ -281,6 +306,22 @@ pub async fn init(mgr: Arc) { */ + + /* + [x] Get the parent module + */ + + let params_clone = Arc::clone(¶ms.parent_act); + let actlock = params_clone.read().await; + let act = &(*actlock); + let parent_module = match act { + BotAction::C(c) => Some(&(*c).module), + BotAction::L(l) => Some(&(*l).module), + _ => None, + }; + + + // [x] Unwraps arguments from message let (arg1, _arg2) = { @@ -414,11 +455,23 @@ pub async fn init(mgr: Arc) { Some(¶ms.msg), ); - botlock - .botmgrs - .chat - .say_in_reply_to(¶ms.msg, outmsg.to_string()) - .await; + + // Only call Say if there is a parent module passed + if parent_module.is_some() { + + botlock + .botmgrs + .chat + .say_in_reply_to( + ¶ms.msg, + outmsg.to_string(), + parent_module.unwrap().clone()) + .await; + + } + + + } let tempcomm = BotCommand { @@ -455,6 +508,20 @@ pub async fn init(mgr: Arc) { */ + /* + [x] Get the parent module + */ + + let params_clone = Arc::clone(¶ms.parent_act); + let actlock = params_clone.read().await; + let act = &(*actlock); + let parent_module = match act { + BotAction::C(c) => Some(&(*c).module), + BotAction::L(l) => Some(&(*l).module), + _ => None, + }; + + let mut argv = params.msg.message_text.split(' '); argv.next(); // Skip the command name @@ -566,7 +633,16 @@ pub async fn init(mgr: Arc) { Some(¶ms.msg), ); - botlock.botmgrs.chat.say_in_reply_to(¶ms.msg, outmsg).await; + if parent_module.is_some() { + + botlock.botmgrs.chat.say_in_reply_to( + ¶ms.msg, + outmsg, + parent_module.unwrap().clone() + ).await; + + } + // [ ] NOTE : After the above, I should receive only the roles in the context of the current channel I received this ideally and maybe BotAdmin ; not outside } diff --git a/src/custom/experimental/experiment001.rs b/src/custom/experimental/experiment001.rs index bcdb9e5..dcd45a2 100644 --- a/src/custom/experimental/experiment001.rs +++ b/src/custom/experimental/experiment001.rs @@ -22,6 +22,7 @@ use crate::core::botlog; use crate::core::bot_actions::actions_util; use crate::core::bot_actions::BotAR; +use crate::core::botmodules::BotAction; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager}; use crate::core::identity::UserRole::*; @@ -113,6 +114,19 @@ pub async fn init(mgr: Arc) { // async fn good_girl(bot: BotAR, msg: PrivmsgMessage) { async fn good_girl(params : ExecBodyParams) { + + + let params_clone = Arc::clone(¶ms.parent_act); + let actlock = params_clone.read().await; + let act = &(*actlock); + let parent_module = match act { + BotAction::C(c) => Some(&(*c).module), + BotAction::L(l) => Some(&(*l).module), + _ => None, + }; + + + // [ ] Uses gen_ratio() to output bool based on a ratio probability . // - For example gen_ratio(2,3) is 2 out of 3 or 0.67% (numerator,denomitator) // - More Info : https://rust-random.github.io/rand/rand/trait.Rng.html#method.gen_ratio @@ -140,12 +154,21 @@ pub async fn init(mgr: Arc) { let botlock = bot.read().await; - // uses chat.say_in_reply_to() for the bot controls for messages - botlock - .botmgrs - .chat - .say_in_reply_to(¶ms.msg, String::from("GoodGirl xdd ")) - .await; + + if parent_module.is_some() { + + // uses chat.say_in_reply_to() for the bot controls for messages + botlock + .botmgrs + .chat + .say_in_reply_to( + ¶ms.msg, + String::from("GoodGirl xdd "), + parent_module.unwrap().clone() + ).await; + + } + } } } @@ -163,6 +186,22 @@ async fn testy(params : ExecBodyParams) { // async fn babygirl(bot: BotAR, msg: PrivmsgMessage) { async fn babygirl(params : ExecBodyParams) { + + /* + [x] Get the parent module + */ + + let params_clone = Arc::clone(¶ms.parent_act); + let actlock = params_clone.read().await; + let act = &(*actlock); + let parent_module = match act { + BotAction::C(c) => Some(&(*c).module), + BotAction::L(l) => Some(&(*l).module), + _ => None, + }; + + + println!("babygirl triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call botlog::debug( "babygirl triggered!", @@ -175,30 +214,43 @@ async fn babygirl(params : ExecBodyParams) { let botlock = bot.read().await; - // uses chat.say_in_reply_to() for the bot controls for messages - botlock + if parent_module.is_some() { + + // uses chat.say_in_reply_to() for the bot controls for messages + botlock + .botmgrs + .chat + .say_in_reply_to( + ¶ms.msg, + String::from("16:13 notohh: cafdk"), + parent_module.unwrap().clone() + ).await; + + + sleep(Duration::from_secs_f64(0.5)).await; + + botlock .botmgrs .chat - .say_in_reply_to(¶ms.msg, String::from("16:13 notohh: cafdk")) - .await; + .say_in_reply_to( + ¶ms.msg, + String::from("16:13 notohh: have fun eating princess"), + parent_module.unwrap().clone() + ).await; - sleep(Duration::from_secs_f64(0.5)).await; + sleep(Duration::from_secs_f64(2.0)).await; - botlock - .botmgrs - .chat - .say_in_reply_to(¶ms.msg, String::from("16:13 notohh: have fun eating princess")) - .await; + botlock + .botmgrs + .chat + .say_in_reply_to( + ¶ms.msg, + String::from("16:13 notohh: baby girl"), + parent_module.unwrap().clone() + ).await; - - sleep(Duration::from_secs_f64(2.0)).await; - - botlock - .botmgrs - .chat - .say_in_reply_to(¶ms.msg, String::from("16:13 notohh: baby girl")) - .await; + } } diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index 8799f5a..4709394 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -22,6 +22,7 @@ use crate::core::bot_actions::ExecBodyParams; use crate::core::botinstance::Channel; // use ChType::Channel; use crate::core::botlog; +use crate::core::botmodules::BotAction; use casual_logger::Log; @@ -71,6 +72,24 @@ async fn sayout(params : ExecBodyParams) { */ + + + + /* + [x] Get the parent module + */ + + let params_clone = Arc::clone(¶ms.parent_act); + let actlock = params_clone.read().await; + let act = &(*actlock); + let parent_module = match act { + BotAction::C(c) => Some(&(*c).module), + BotAction::L(l) => Some(&(*l).module), + _ => None, + }; + + + let reply_parent = if let Some(Some(reply)) = params.msg.source.tags.0.get("reply-parent-msg-body") { Some(reply) } else { None } @@ -141,11 +160,19 @@ async fn sayout(params : ExecBodyParams) { ); // return ; - botlock - .botmgrs - .chat - .say_in_reply_to(¶ms.msg, format!("Not a Joined Channel : {}",trgchnl)) - .await; + if parent_module.is_some() { + + + botlock + .botmgrs + .chat + .say_in_reply_to( + ¶ms.msg, + format!("Not a Joined Channel : {}",trgchnl), + parent_module.unwrap().clone() + ).await; + + } } @@ -195,12 +222,21 @@ async fn sayout(params : ExecBodyParams) { outmsg) }; - // uses chat.say_in_reply_to() for the bot controls for messages - botlock - .botmgrs - .chat - .say(trgchnl.to_string(), newoutmsg.to_string()) - .await; + + if parent_module.is_some() { + + + // uses chat.say_in_reply_to() for the bot controls for messages + botlock + .botmgrs + .chat + .say( + trgchnl.to_string(), + newoutmsg.to_string(), + parent_module.unwrap().clone()) + .await; + + } @@ -216,12 +252,20 @@ async fn sayout(params : ExecBodyParams) { let botlock = bot.read().await; - // uses chat.say_in_reply_to() for the bot controls for messages - botlock + + if parent_module.is_some() { + + // uses chat.say_in_reply_to() for the bot controls for messages + botlock .botmgrs .chat - .say_in_reply_to(¶ms.msg, String::from("Invalid arguments")) - .await; + .say_in_reply_to( + ¶ms.msg, + String::from("Invalid arguments"), + parent_module.unwrap().clone() + ).await; + + } }, From 0eb43c87f2581d3309fd0d26a64088cb77fa0349 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sun, 24 Mar 2024 17:40:57 -0400 Subject: [PATCH 05/18] ExecBodyParams get_parent_module() --- src/core/bot_actions.rs | 53 +++++++++++++++++++++++- src/core/botmodules.rs | 36 ++++++++-------- src/core/identity.rs | 51 ++++++++++++----------- src/custom/experimental/experiment001.rs | 42 ++++++++++--------- src/custom/experimental/experiment002.rs | 24 ++++++----- 5 files changed, 134 insertions(+), 72 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index 243d2d9..b1ce97f 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -6,7 +6,7 @@ use tokio::sync::RwLock; use crate::core::botinstance::BotInstance; -use super::botmodules::BotAction; +use super::botmodules::{BotAction, BotModule}; pub type BotAR = Arc>; @@ -18,6 +18,57 @@ pub struct ExecBodyParams { pub parent_act : ActAR , } + +impl ExecBodyParams { + + // pub async fn get_parent_module(&self) -> Arc> { + pub async fn get_parent_module(&self) -> Option { + + // let params_clone = Arc::clone(&self.parent_act); + // // let actlock = params_clone.read().await; + // // let act = &(*actlock); + // // let a = Arc::new(&act); + // // let parent_module = match act { + // // let parent_module = match &(*actlock) { + // let parent_module = match &(*(params_clone.read().await)) { + // BotAction::C(c) => Some(&(*c).module), + // BotAction::L(l) => Some(&(*l).module), + // _ => None, + // }; + + // // Some(BotModule("Tester".to_string())) + // let a = Arc::new(parent_module); + // a + + + let parent_act = Arc::clone(&self.parent_act); + let parent_act_lock = parent_act.read().await; + let act = &(*parent_act_lock); + let parent_module = match act { + BotAction::C(c) => { + let temp = c.module.clone(); + Some(temp) + }, + BotAction::L(l) => { + let temp = l.module.clone(); + Some(temp) + }, + _ => None + }; + + // Arc::new(a) + parent_module + // let a = BotModule("hello".to_string()); + // Arc::new(Some(a)) + + } + + + +} + + + pub mod actions_util { use super::*; diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 87dd243..de1a4a5 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -110,14 +110,16 @@ pub async fn init(mgr: Arc) { */ - let params_clone = Arc::clone(¶ms.parent_act); - let actlock = params_clone.read().await; - let act = &(*actlock); - let parent_module = match act { - BotAction::C(c) => Some(&(*c).module), - BotAction::L(l) => Some(&(*l).module), - _ => None, - }; + // let params_clone = Arc::clone(¶ms.parent_act); + // let actlock = params_clone.read().await; + // let act = &(*actlock); + // let parent_module = match act { + // BotAction::C(c) => Some(&(*c).module), + // BotAction::L(l) => Some(&(*l).module), + // _ => None, + // }; + + let parent_module = params.get_parent_module().await; @@ -315,16 +317,16 @@ pub async fn init(mgr: Arc) { [x] Get the parent module */ - let params_clone = Arc::clone(¶ms.parent_act); - let actlock = params_clone.read().await; - let act = &(*actlock); - let parent_module = match act { - BotAction::C(c) => Some(&(*c).module), - BotAction::L(l) => Some(&(*l).module), - _ => None, - }; - + // let params_clone = Arc::clone(¶ms.parent_act); + // let actlock = params_clone.read().await; + // let act = &(*actlock); + // let parent_module = match act { + // BotAction::C(c) => Some(&(*c).module), + // BotAction::L(l) => Some(&(*l).module), + // _ => None, + // }; + let parent_module = params.get_parent_module().await; // [x] Unwraps arguments from message diff --git a/src/core/identity.rs b/src/core/identity.rs index 5c2ede2..835fb0e 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -112,15 +112,16 @@ pub async fn init(mgr: Arc) { [x] Get the parent module */ - let params_clone = Arc::clone(¶ms.parent_act); - let actlock = params_clone.read().await; - let act = &(*actlock); - let parent_module = match act { - BotAction::C(c) => Some(&(*c).module), - BotAction::L(l) => Some(&(*l).module), - _ => None, - }; + // let params_clone = Arc::clone(¶ms.parent_act); + // let actlock = params_clone.read().await; + // let act = &(*actlock); + // let parent_module = match act { + // BotAction::C(c) => Some(&(*c).module), + // BotAction::L(l) => Some(&(*l).module), + // _ => None, + // }; + let parent_module = params.get_parent_module().await; // println!("{}",params.msg.message_text); botlog::trace( @@ -311,15 +312,16 @@ pub async fn init(mgr: Arc) { [x] Get the parent module */ - let params_clone = Arc::clone(¶ms.parent_act); - let actlock = params_clone.read().await; - let act = &(*actlock); - let parent_module = match act { - BotAction::C(c) => Some(&(*c).module), - BotAction::L(l) => Some(&(*l).module), - _ => None, - }; + // let params_clone = Arc::clone(¶ms.parent_act); + // let actlock = params_clone.read().await; + // let act = &(*actlock); + // let parent_module = match act { + // BotAction::C(c) => Some(&(*c).module), + // BotAction::L(l) => Some(&(*l).module), + // _ => None, + // }; + let parent_module = params.get_parent_module().await; // [x] Unwraps arguments from message @@ -512,15 +514,16 @@ pub async fn init(mgr: Arc) { [x] Get the parent module */ - let params_clone = Arc::clone(¶ms.parent_act); - let actlock = params_clone.read().await; - let act = &(*actlock); - let parent_module = match act { - BotAction::C(c) => Some(&(*c).module), - BotAction::L(l) => Some(&(*l).module), - _ => None, - }; + // let params_clone = Arc::clone(¶ms.parent_act); + // let actlock = params_clone.read().await; + // let act = &(*actlock); + // let parent_module = match act { + // BotAction::C(c) => Some(&(*c).module), + // BotAction::L(l) => Some(&(*l).module), + // _ => None, + // }; + let parent_module = params.get_parent_module().await; let mut argv = params.msg.message_text.split(' '); diff --git a/src/custom/experimental/experiment001.rs b/src/custom/experimental/experiment001.rs index dcd45a2..8a93cc6 100644 --- a/src/custom/experimental/experiment001.rs +++ b/src/custom/experimental/experiment001.rs @@ -116,16 +116,17 @@ pub async fn init(mgr: Arc) { async fn good_girl(params : ExecBodyParams) { - let params_clone = Arc::clone(¶ms.parent_act); - let actlock = params_clone.read().await; - let act = &(*actlock); - let parent_module = match act { - BotAction::C(c) => Some(&(*c).module), - BotAction::L(l) => Some(&(*l).module), - _ => None, - }; - + // let params_clone = Arc::clone(¶ms.parent_act); + // let actlock = params_clone.read().await; + // let act = &(*actlock); + // let parent_module = match act { + // BotAction::C(c) => Some(&(*c).module), + // BotAction::L(l) => Some(&(*l).module), + // _ => None, + // }; + + let parent_module = params.get_parent_module().await; // [ ] Uses gen_ratio() to output bool based on a ratio probability . // - For example gen_ratio(2,3) is 2 out of 3 or 0.67% (numerator,denomitator) @@ -191,16 +192,19 @@ async fn babygirl(params : ExecBodyParams) { [x] Get the parent module */ - let params_clone = Arc::clone(¶ms.parent_act); - let actlock = params_clone.read().await; - let act = &(*actlock); - let parent_module = match act { - BotAction::C(c) => Some(&(*c).module), - BotAction::L(l) => Some(&(*l).module), - _ => None, - }; + // let params_clone = Arc::clone(¶ms.parent_act); + // let actlock = params_clone.read().await; + // let act = &(*actlock); + // let parent_module = match act { + // BotAction::C(c) => Some(&(*c).module), + // BotAction::L(l) => Some(&(*l).module), + // _ => None, + // }; + + let parent_module = params.get_parent_module().await; + println!("babygirl triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call botlog::debug( @@ -223,7 +227,7 @@ async fn babygirl(params : ExecBodyParams) { .say_in_reply_to( ¶ms.msg, String::from("16:13 notohh: cafdk"), - parent_module.unwrap().clone() + parent_module.clone().unwrap().clone() ).await; @@ -235,7 +239,7 @@ async fn babygirl(params : ExecBodyParams) { .say_in_reply_to( ¶ms.msg, String::from("16:13 notohh: have fun eating princess"), - parent_module.unwrap().clone() + parent_module.clone().unwrap().clone() ).await; diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index 4709394..fe603fd 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -79,14 +79,16 @@ async fn sayout(params : ExecBodyParams) { [x] Get the parent module */ - let params_clone = Arc::clone(¶ms.parent_act); - let actlock = params_clone.read().await; - let act = &(*actlock); - let parent_module = match act { - BotAction::C(c) => Some(&(*c).module), - BotAction::L(l) => Some(&(*l).module), - _ => None, - }; + // let params_clone = Arc::clone(¶ms.parent_act); + // let actlock = params_clone.read().await; + // let act = &(*actlock); + // let parent_module = match act { + // BotAction::C(c) => Some(&(*c).module), + // BotAction::L(l) => Some(&(*l).module), + // _ => None, + // }; + + let parent_module = params.get_parent_module().await; @@ -160,7 +162,7 @@ async fn sayout(params : ExecBodyParams) { ); // return ; - if parent_module.is_some() { + if parent_module.clone().is_some() { botlock @@ -169,7 +171,7 @@ async fn sayout(params : ExecBodyParams) { .say_in_reply_to( ¶ms.msg, format!("Not a Joined Channel : {}",trgchnl), - parent_module.unwrap().clone() + parent_module.clone().unwrap().clone() ).await; } @@ -223,7 +225,7 @@ async fn sayout(params : ExecBodyParams) { }; - if parent_module.is_some() { + if parent_module.clone().is_some() { // uses chat.say_in_reply_to() for the bot controls for messages From 958aeea48e76094f88795068d7b1ccc814dcdf5a Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sun, 24 Mar 2024 18:14:08 -0400 Subject: [PATCH 06/18] execbodyparams passed to chat() --- src/core/bot_actions.rs | 24 +----------- src/core/botinstance.rs | 24 +++++++++++- src/core/botmodules.rs | 50 ++++++++++++------------ src/core/chat.rs | 17 +++++--- src/core/identity.rs | 13 +++--- src/custom/experimental/experiment001.rs | 12 ++++-- src/custom/experimental/experiment002.rs | 11 ++++-- 7 files changed, 82 insertions(+), 69 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index b1ce97f..d2d8d25 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -12,6 +12,7 @@ use super::botmodules::{BotAction, BotModule}; pub type BotAR = Arc>; pub type ActAR = Arc>; +#[derive(Clone)] pub struct ExecBodyParams { pub bot : BotAR, pub msg : PrivmsgMessage, @@ -21,26 +22,8 @@ pub struct ExecBodyParams { impl ExecBodyParams { - // pub async fn get_parent_module(&self) -> Arc> { pub async fn get_parent_module(&self) -> Option { - // let params_clone = Arc::clone(&self.parent_act); - // // let actlock = params_clone.read().await; - // // let act = &(*actlock); - // // let a = Arc::new(&act); - // // let parent_module = match act { - // // let parent_module = match &(*actlock) { - // let parent_module = match &(*(params_clone.read().await)) { - // BotAction::C(c) => Some(&(*c).module), - // BotAction::L(l) => Some(&(*l).module), - // _ => None, - // }; - - // // Some(BotModule("Tester".to_string())) - // let a = Arc::new(parent_module); - // a - - let parent_act = Arc::clone(&self.parent_act); let parent_act_lock = parent_act.read().await; let act = &(*parent_act_lock); @@ -55,12 +38,7 @@ impl ExecBodyParams { }, _ => None }; - - // Arc::new(a) parent_module - // let a = BotModule("hello".to_string()); - // Arc::new(Some(a)) - } diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index c09050a..dc5e70b 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -412,10 +412,20 @@ impl BotInstance { let botlock = bot.read().await; let outstr = format!("sadg Module is disabled : {:?}",a); + + let params = ExecBodyParams { + bot : Arc::clone(&bot), + msg : (*msg).clone(), + parent_act : Arc::clone(&act_clone), + + }; + botlock.botmgrs.chat.say_in_reply_to( msg, outstr, - c.module.clone()).await; + // c.module.clone() + params, + ).await; } return; @@ -454,10 +464,20 @@ impl BotInstance { let botlock = bot.read().await; let outstr = "o7 a Mod. I kneel to serve! pepeKneel ".to_string(); + + + let params = ExecBodyParams { + bot : Arc::clone(&bot), + msg : (*msg).clone(), + parent_act : Arc::clone(&act_clone), + + }; + botlock.botmgrs.chat.say_in_reply_to( msg, outstr, - c.module.clone(), + // c.module.clone(), + params ).await; } } diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index de1a4a5..b173e7b 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -198,8 +198,12 @@ pub async fn init(mgr: Arc) { botlock .botmgrs .chat - .say_in_reply_to(¶ms.msg, outmsg.to_string() , parent_module.unwrap().clone()) - .await; + .say_in_reply_to( + ¶ms.msg, + outmsg.to_string() , + // parent_module.unwrap().clone() + params.clone(), + ).await; } return; @@ -247,8 +251,12 @@ pub async fn init(mgr: Arc) { botlock .botmgrs .chat - .say_in_reply_to(¶ms.msg, outmsg.to_string(),parent_module.unwrap().clone()) - .await; + .say_in_reply_to( + ¶ms.msg, + outmsg.to_string(), + // parent_module.unwrap().clone() + params.clone(), + ).await; } @@ -414,8 +422,12 @@ pub async fn init(mgr: Arc) { botlock .botmgrs .chat - .say_in_reply_to(¶ms.msg, outmsg.to_string(),parent_module.unwrap().clone()) - .await; + .say_in_reply_to( + ¶ms.msg, + outmsg.to_string(), + // ,parent_module.unwrap().clone() + params.clone() + ).await; } @@ -459,24 +471,6 @@ pub async fn init(mgr: Arc) { ChangeResult::Success(a) => format!("YAAY Success : {}",a), }; - - // let actlock = params.parent_act.read().await; - // let act = *actlock; - // let parent_module = match act { - // BotAction::C(c) => Some(c.module), - // BotAction::L(l) => Some(l.module), - // _ => None, - // }; - - - // let params_clone = Arc::clone(¶ms.parent_act); - // let actlock = params_clone.read().await; - // let act = &(*actlock); - // let parent_module = match act { - // BotAction::C(c) => Some(&(*c).module), - // BotAction::L(l) => Some(&(*l).module), - // _ => None, - // }; // Only call Say if there is a parent module passed if parent_module.is_some() { @@ -484,8 +478,12 @@ pub async fn init(mgr: Arc) { botlock .botmgrs .chat - .say_in_reply_to(¶ms.msg, outmsg.to_string(),parent_module.unwrap().clone()) - .await; + .say_in_reply_to( + ¶ms.msg, + outmsg.to_string(), + // parent_module.unwrap().clone() + params.clone(), + ).await; } diff --git a/src/core/chat.rs b/src/core/chat.rs index d379472..8cc2cda 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -21,6 +21,7 @@ use crate::core::botlog; use tokio::time::{sleep, Duration}; +use super::bot_actions::ExecBodyParams; use super::botmodules::BotModule; #[derive(Clone)] @@ -57,7 +58,7 @@ impl Chat { // async fn send_botmsg(&self, msginput: BotMsgType<'_>) { - async fn send_botmsg(&self, msginput: BotMsgType<'_>, _ : BotModule) { + async fn send_botmsg(&self, msginput: BotMsgType<'_>, params : ExecBodyParams) { /* formats message before sending to TwitchIRC @@ -87,6 +88,12 @@ impl Chat { return ; } + /* + [ ] !! => 03.24 - Somewhere around here, we should be validating module for target channel + */ + + + let rl = Arc::clone(&self.ratelimiters); let mut rllock = rl.lock().await; @@ -163,17 +170,17 @@ impl Chat { // pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String) { - pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , parent_module : BotModule) { + pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) { - self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg) , parent_module).await; + self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg) , params).await; } // pub async fn say(&self, channel_login: String, message: String) { - pub async fn say(&self, channel_login: String, message: String , parent_module : BotModule) { + pub async fn say(&self, channel_login: String, message: String , params : ExecBodyParams) { // more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say - self.send_botmsg(BotMsgType::Say(channel_login.to_lowercase(), message), parent_module).await; + self.send_botmsg(BotMsgType::Say(channel_login.to_lowercase(), message), params).await; } async fn _me(&self, _: String, _: String) { diff --git a/src/core/identity.rs b/src/core/identity.rs index 835fb0e..0be4dea 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -241,8 +241,9 @@ pub async fn init(mgr: Arc) { .say_in_reply_to( ¶ms.msg, outmsg.to_string(), - parent_module.unwrap().clone()) - .await; + // parent_module.unwrap().clone() + params.clone(), + ).await; } @@ -467,8 +468,9 @@ pub async fn init(mgr: Arc) { .say_in_reply_to( ¶ms.msg, outmsg.to_string(), - parent_module.unwrap().clone()) - .await; + // parent_module.unwrap().clone() + params.clone() + ).await; } @@ -641,7 +643,8 @@ pub async fn init(mgr: Arc) { botlock.botmgrs.chat.say_in_reply_to( ¶ms.msg, outmsg, - parent_module.unwrap().clone() + // parent_module.unwrap().clone() + params.clone() ).await; } diff --git a/src/custom/experimental/experiment001.rs b/src/custom/experimental/experiment001.rs index 8a93cc6..54e6552 100644 --- a/src/custom/experimental/experiment001.rs +++ b/src/custom/experimental/experiment001.rs @@ -165,7 +165,8 @@ pub async fn init(mgr: Arc) { .say_in_reply_to( ¶ms.msg, String::from("GoodGirl xdd "), - parent_module.unwrap().clone() + // parent_module.unwrap().clone() + params.clone() ).await; } @@ -227,7 +228,8 @@ async fn babygirl(params : ExecBodyParams) { .say_in_reply_to( ¶ms.msg, String::from("16:13 notohh: cafdk"), - parent_module.clone().unwrap().clone() + // parent_module.clone().unwrap().clone() + params.clone() ).await; @@ -239,7 +241,8 @@ async fn babygirl(params : ExecBodyParams) { .say_in_reply_to( ¶ms.msg, String::from("16:13 notohh: have fun eating princess"), - parent_module.clone().unwrap().clone() + // parent_module.clone().unwrap().clone() + params.clone() ).await; @@ -251,7 +254,8 @@ async fn babygirl(params : ExecBodyParams) { .say_in_reply_to( ¶ms.msg, String::from("16:13 notohh: baby girl"), - parent_module.unwrap().clone() + // parent_module.unwrap().clone() + params.clone() ).await; } diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index fe603fd..be53ffa 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -171,7 +171,8 @@ async fn sayout(params : ExecBodyParams) { .say_in_reply_to( ¶ms.msg, format!("Not a Joined Channel : {}",trgchnl), - parent_module.clone().unwrap().clone() + // parent_module.clone().unwrap().clone() + params.clone(), ).await; } @@ -235,8 +236,9 @@ async fn sayout(params : ExecBodyParams) { .say( trgchnl.to_string(), newoutmsg.to_string(), - parent_module.unwrap().clone()) - .await; + // parent_module.unwrap().clone() + params.clone(), + ).await; } @@ -264,7 +266,8 @@ async fn sayout(params : ExecBodyParams) { .say_in_reply_to( ¶ms.msg, String::from("Invalid arguments"), - parent_module.unwrap().clone() + // parent_module.unwrap().clone() + params.clone() ).await; } From 6deac8e6c74699bcf09f4fbe630e1a99ea63ba7e Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sun, 24 Mar 2024 18:50:11 -0400 Subject: [PATCH 07/18] chat.send validates target channel module status --- Cargo.lock | 12 ++++++++++++ Cargo.toml | 2 ++ src/core/chat.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 018b9dc..da35376 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,6 +41,17 @@ dependencies = [ "libc", ] +[[package]] +name = "async-recursion" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30c5ef0ede93efbf733c1a727f3b6b5a1060bbedd5600183e66f6e4be4af0ec5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "async-trait" version = "0.1.77" @@ -194,6 +205,7 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" name = "forcebot_rs" version = "0.1.0" dependencies = [ + "async-recursion", "async-trait", "casual_logger", "chrono", diff --git a/Cargo.toml b/Cargo.toml index f4c7751..f3f7724 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,9 +12,11 @@ twitch-irc = "5.0.1" rand = { version = "0.8.5", features = [] } futures = "0.3" async-trait = "0.1.77" +async-recursion = "1.1.0" casual_logger = "0.6.5" chrono = "0.4.35" + [lib] name = "bot_lib" path = "src/lib.rs" diff --git a/src/core/chat.rs b/src/core/chat.rs index 8cc2cda..a2d5b2b 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -24,6 +24,9 @@ use tokio::time::{sleep, Duration}; use super::bot_actions::ExecBodyParams; use super::botmodules::BotModule; + +use async_recursion::async_recursion; + #[derive(Clone)] pub struct Chat { pub ratelimiters: Arc>>, // used to limit messages sent per channel @@ -92,6 +95,52 @@ impl Chat { [ ] !! => 03.24 - Somewhere around here, we should be validating module for target channel */ + + /* + - Use ModulesManager.modstatus + + modstatus(&self, in_module: BotModule, in_chnl: Channel) -> StatusType + + */ + + let parent_module = params.get_parent_module().await; + // let parent_module = parent_module.clone(); + + let botlock = params.bot.read().await; + let modmgr = Arc::clone(&botlock.botmodules); + let modstatus = (*modmgr).modstatus( + parent_module.clone().expect("ERROR - Expected a module"), + Channel(channel_login.clone()) + ).await; + + match modstatus { + super::botmodules::StatusType::Enabled(_) => (), + super::botmodules::StatusType::Disabled(_) => (), + } + + if let super::botmodules::StatusType::Disabled(lvl) = modstatus { + // Note : At this point, chat was called in a channel where the parent module IS enabled + // - this type of validation is done outside of Chat() + // This though takes into account scenarios where we are targetting a different channel + + if let BotMsgType::SayInReplyTo(a, _) = msginput { + + self.say_in_reply_to( + a, + format!("uuh {:?} is disabled on {} : {:?}", + parent_module.clone().unwrap(), + channel_login.clone(), + lvl + ), + params.clone() + ).await; + + + } + + return + + } let rl = Arc::clone(&self.ratelimiters); @@ -170,6 +219,7 @@ impl Chat { // pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String) { + #[async_recursion] pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) { self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg) , params).await; From afd7b7d38705588b65b2d0af3f16a493e6eff60d Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sun, 24 Mar 2024 21:50:28 -0400 Subject: [PATCH 08/18] writelock_issue --- src/core/bot_actions.rs | 22 +- src/core/botinstance.rs | 11 + src/core/botmodules.rs | 13 + src/core/chat.rs | 301 +++++++++++++++++++++-- src/custom/experimental/experiment002.rs | 12 +- 5 files changed, 332 insertions(+), 27 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index d2d8d25..4b17758 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -6,7 +6,7 @@ use tokio::sync::RwLock; use crate::core::botinstance::BotInstance; -use super::botmodules::{BotAction, BotModule}; +use super::{botmodules::{BotAction, BotModule}, identity::ChatBadge}; pub type BotAR = Arc>; @@ -41,6 +41,26 @@ impl ExecBodyParams { parent_module } + pub fn get_sender(&self) -> String { + self.msg.sender.name.clone() + } + + pub fn get_sender_chatbadge(&self) -> Option { + + let mut requestor_badge_mut: Option = None; + + for b in &self.msg.badges { + if b.name == "moderator" { + requestor_badge_mut = Some(ChatBadge::Mod); + } else if b.name == "broadcaster" { + requestor_badge_mut = Some(ChatBadge::Broadcaster); + } + } + + let requestor_badge = requestor_badge_mut; + + requestor_badge + } } diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index dc5e70b..b202e5b 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -390,6 +390,12 @@ impl BotInstance { Some(msg), ); + botlog::trace( + "ACQUIRING WRITE LOCK : ID", + Some("BotInstance > listener_main_prvmsg()".to_string()), + Some(msg), + ); + const OF_CMD_CHANNEL:Channel = Channel(String::new()); @@ -431,6 +437,11 @@ impl BotInstance { return; }; + botlog::trace( + "ACQUIRING WRITE LOCK : ID", + Some("BotInstance > listener_main_prvmsg()".to_string()), + Some(msg), + ); let eval = { diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index b173e7b..5ae8ceb 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -846,6 +846,12 @@ impl ModulesManager { return ChangeResult::Failed("Module doesn't exist".to_string()); } + botlog::trace( + "ACQUIRING WRITE LOCK : ID", + Some("ModulesManager > Exec_enable".to_string()), + None, + ); + let mut idlock = id.write().await; @@ -1028,6 +1034,13 @@ impl ModulesManager { return ChangeResult::Failed("Module doesn't exist".to_string()); } + botlog::trace( + "ACQUIRING WRITE LOCK : ID", + Some("ModulesManager > Exec_disable".to_string()), + None, + ); + + let mut idlock = id.write().await; diff --git a/src/core/chat.rs b/src/core/chat.rs index a2d5b2b..2df41db 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -12,6 +12,7 @@ use casual_logger::Log; use rand::Rng; +use crate::core::identity::Permissible; use crate::core::ratelimiter; use crate::core::ratelimiter::RateLimiter; @@ -23,6 +24,7 @@ use tokio::time::{sleep, Duration}; use super::bot_actions::ExecBodyParams; use super::botmodules::BotModule; +use super::identity; use async_recursion::async_recursion; @@ -34,7 +36,7 @@ pub struct Chat { } -#[derive(Clone)] +#[derive(Clone,Debug)] enum BotMsgType<'a> { SayInReplyTo(&'a PrivmsgMessage,String), Say(String,String), @@ -71,6 +73,13 @@ impl Chat { */ + + botlog::trace( + format!("send_bot_msg params : {:?}",msginput).as_str(), + Some("chat.rs > send_botmsg ".to_string()), + Some(¶ms.msg), + ); + let (channel_login,mut outmsg) = match msginput.clone() { BotMsgType::SayInReplyTo(msg, outmsg) => { (msg.channel_login.clone(),outmsg) @@ -80,7 +89,26 @@ impl Chat { }, }; - if self.client.get_channel_status(channel_login.clone()).await == (false,false) { + + botlog::trace( + "BEFORE GET_CHANNEL_STATUS", + Some("chat.rs > send_botmsg ".to_string()), + Some(¶ms.msg), + ); + + let rslt = self.client.get_channel_status(channel_login.clone()).await == (false,false); + + botlog::trace( + format!("GET_CHANNEL_STATUS result = {:?}",rslt).as_str(), + Some("chat.rs > send_botmsg ".to_string()), + Some(¶ms.msg), + ); + + Log::flush(); + + + + if rslt { // in the case where the provided channel isn't something we're known to be connected to botlog::warn( @@ -92,7 +120,7 @@ impl Chat { } /* - [ ] !! => 03.24 - Somewhere around here, we should be validating module for target channel + [x] !! => 03.24 - Somewhere around here, we should be validating module for target channel */ @@ -103,37 +131,105 @@ impl Chat { */ + + botlog::trace( + "BEFORE parent_module call", + Some("chat.rs > send_botmsg ".to_string()), + Some(¶ms.msg), + ); + let parent_module = params.get_parent_module().await; // let parent_module = parent_module.clone(); - let botlock = params.bot.read().await; + let params_clone = params.clone(); + let botclone = Arc::clone(¶ms_clone.bot); + let botlock = botclone.read().await; let modmgr = Arc::clone(&botlock.botmodules); let modstatus = (*modmgr).modstatus( parent_module.clone().expect("ERROR - Expected a module"), Channel(channel_login.clone()) ).await; - match modstatus { - super::botmodules::StatusType::Enabled(_) => (), - super::botmodules::StatusType::Disabled(_) => (), - } + // match modstatus { + // super::botmodules::StatusType::Enabled(_) => (), + // super::botmodules::StatusType::Disabled(_) => (), + // } + + + botlog::trace( + format!("BEFORE modstatus check : modstatus = {:?}",modstatus).as_str(), + Some("chat.rs > send_botmsg ".to_string()), + Some(¶ms.msg), + ); + + if let super::botmodules::StatusType::Disabled(lvl) = modstatus { // Note : At this point, chat was called in a channel where the parent module IS enabled // - this type of validation is done outside of Chat() // This though takes into account scenarios where we are targetting a different channel + + botlog::trace( + "BEFORE msginput check", + Some("chat.rs > send_botmsg ".to_string()), + Some(¶ms.msg), + ); + + Log::flush(); + + if let BotMsgType::SayInReplyTo(a, _) = msginput { + + botlog::trace( + "BEFORE potential Async recursion", + Some("chat.rs > send_botmsg ".to_string()), + Some(¶ms.clone().msg), + ); - self.say_in_reply_to( - a, - format!("uuh {:?} is disabled on {} : {:?}", - parent_module.clone().unwrap(), - channel_login.clone(), - lvl - ), - params.clone() - ).await; + Log::flush(); + + + // self.say_in_reply_to( + // a, + // format!("uuh {:?} is disabled on {} : {:?}", + // parent_module.clone().unwrap(), + // channel_login.clone(), + // lvl + // ), + // params.clone() + // ).await; + + let chat_clone = self.clone(); + + // tokio::spawn( async move { + // // for _ in 0..5 { + // // println!(">> Innterroutine triggered!"); + // // sleep(Duration::from_secs_f64(5.0)).await; + // // } + + // chat_clone.say_in_reply_to( + // a, + // format!("uuh {:?} is disabled on {} : {:?}", + // parent_module.clone().unwrap(), + // channel_login.clone(), + // lvl + // ), + // params.clone() + // ).await; + // } + // ); + + + botlog::trace( + "AFTER potential Async recursion", + Some("chat.rs > send_botmsg ".to_string()), + Some(¶ms.msg), + ); + + + Log::flush(); + } @@ -141,6 +237,155 @@ impl Chat { return } + + + /* + + [ ] !! => 03.24 - Would be nice if around here , validate the user has at least some special roles in target channel + - NOTE : If these need to be refined, they can be by the custom module developer at the parent calling function of say() + - This just prevents Chat from being triggered in a channel where the sending chatter does not have any special roles + + */ + + /* + + Use the following + + pub async fn can_user_run( + &mut self, + usr: String, + channelname: Channel, + chat_badge: Option, + cmdreqroles: Vec, // ) -> Result> { + ) -> (Permissible, ChangeResult) { + + */ + + botlog::trace( + "BEFORE Permissibility checks", + Some("chat.rs > send_botmsg ".to_string()), + Some(¶ms.msg), + ); + + Log::flush(); + + + const OF_CMD_CHANNEL:Channel = Channel(String::new()); + + let permissability = Permissible::Allow; + + { + + + // let id = botlock.get_identity(); + // let mut idlock = id.write().await; // <-- [ ] 03.24 - This is definitely locking it + let channel_login_clone = channel_login.clone(); + + + let spawnhandle = tokio::spawn( + async move { + let botclone = Arc::clone(¶ms_clone.bot); + let botlock = botclone.read().await; + let id = botlock.get_identity(); + + + // botlog::trace( + // "ACQUIRING WRITE LOCK : ID", + // Some("Chat > send_botmsg".to_string()), + // Some(¶ms.msg), + // ); + + + // { + // let mut idlock = id.write().await; // <-- [ ] 03.24 - This is definitely locking it + // } + + // botlog::trace( + // "ACQUIRED WRITE LOCK : ID", + // Some("Chat > send_botmsg".to_string()), + // Some(¶ms.msg), + // ); + + // let (permissability, _) = idlock + // .can_user_run( + // params.get_sender(), + // Channel(channel_login_clone), + // params.get_sender_chatbadge(), + // vec![ + // //identity::UserRole::BotAdmin, + // identity::UserRole::Mod(OF_CMD_CHANNEL), + // identity::UserRole::SupMod(OF_CMD_CHANNEL), + // identity::UserRole::Broadcaster, + // ] + // ).await; + // permissability + } + ); + + if let Ok(permissibility) = spawnhandle.await { + botlog::trace( + format!("permisibility check : {:?}",permissability).as_str(), + Some("chat.rs > send_botmsg ".to_string()), + None + ); + + } + + + } + + + + + // let permissability = { + // let id = botlock.get_identity(); + // let mut idlock = id.write().await; // <-- [ ] 03.24 - This is definitely locking it + // let (permissability, _) = idlock + // .can_user_run( + // params.get_sender(), + // Channel(channel_login.clone()), + // params.get_sender_chatbadge(), + // vec![ + // //identity::UserRole::BotAdmin, + // identity::UserRole::Mod(OF_CMD_CHANNEL), + // identity::UserRole::SupMod(OF_CMD_CHANNEL), + // identity::UserRole::Broadcaster, + // ] + // ).await; + // permissability + // }; + + // match permissability { + // Permissible::Allow => (), + // Permissible::Block => (), + // } + + botlog::trace( + format!("permisibility check : {:?}",permissability).as_str(), + Some("chat.rs > send_botmsg ".to_string()), + None, + ); + + Log::flush(); + + if let Permissible::Block = permissability { + + + if let BotMsgType::SayInReplyTo(a, _) = msginput { + + // self.say_in_reply_to( + // a, + // format!("uuh you don't have special privileges in {}", + // channel_login.clone() + // ), + // params.clone() + // ).await; + + } + return + + } + let rl = Arc::clone(&self.ratelimiters); @@ -222,6 +467,28 @@ impl Chat { #[async_recursion] pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) { + let botclone = Arc::clone(¶ms.bot); + let botlock = botclone.read().await; + let id = botlock.get_identity(); + + botlog::trace( + "ACQUIRING WRITE LOCK : ID", + Some("Chat > send_botmsg".to_string()), + Some(¶ms.msg), + ); + + + { + let mut idlock = id.write().await; // <-- [ ] 03.24 - This is definitely locking it + } + + botlog::trace( + "ACQUIRED WRITE LOCK : ID", + Some("Chat > send_botmsg".to_string()), + Some(¶ms.msg), + ); + + self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg) , params).await; } diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index be53ffa..d657c19 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -57,8 +57,11 @@ pub async fn init(mgr: Arc) { // 2. Add the BotAction to ModulesManager botc1.add_to_modmgr(Arc::clone(&mgr)).await; + // If enabling by defauling at instance level mgr.set_instance_enabled(BotModule(String::from("experiments002"))).await; + // [ ] #TODO - FOR SOME REASON, IF DISABLED BY DEFAULT, IT OVERFLOWS at RUNGTIME + } @@ -79,15 +82,6 @@ async fn sayout(params : ExecBodyParams) { [x] Get the parent module */ - // let params_clone = Arc::clone(¶ms.parent_act); - // let actlock = params_clone.read().await; - // let act = &(*actlock); - // let parent_module = match act { - // BotAction::C(c) => Some(&(*c).module), - // BotAction::L(l) => Some(&(*l).module), - // _ => None, - // }; - let parent_module = params.get_parent_module().await; From ab5624c6fa8fe2e6bc4778bd34ac7cbe17f68d75 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sun, 24 Mar 2024 22:55:38 -0400 Subject: [PATCH 09/18] (init) solution --- src/core/chat.rs | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/src/core/chat.rs b/src/core/chat.rs index 2df41db..d596a68 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -464,29 +464,58 @@ impl Chat { // pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String) { - #[async_recursion] + // #[async_recursion] pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) { - let botclone = Arc::clone(¶ms.bot); + let params_clone = params.clone(); + + let botclone = Arc::clone(¶ms_clone.bot); let botlock = botclone.read().await; let id = botlock.get_identity(); + let id = Arc::clone(&id); + + // botlog::trace( + // "ACQUIRING WRITE LOCK : ID", + // Some("Chat > send_botmsg".to_string()), + // Some(¶ms.msg), + // ); + // Log::flush(); botlog::trace( - "ACQUIRING WRITE LOCK : ID", + "ACQUIRING READ LOCK : ID", Some("Chat > send_botmsg".to_string()), Some(¶ms.msg), ); + Log::flush(); - - { - let mut idlock = id.write().await; // <-- [ ] 03.24 - This is definitely locking it - } - + + // let idlock = id.write().await; // <-- [ ] 03.24 - This is definitely locking it + let idlock = id.read().await; // <-- [ ] 03.24 - seems to work + let a = idlock.getspecialuserroles(params.get_sender(), Some(Channel(msg.channel_login.clone()))).await; botlog::trace( - "ACQUIRED WRITE LOCK : ID", + format!("GETSPECIALUSERROLES RESULT : {:?}",a).as_str(), Some("Chat > send_botmsg".to_string()), Some(¶ms.msg), ); + Log::flush(); + + + + // botlog::trace( + // "ACQUIRED WRITE LOCK : ID", + // Some("Chat > send_botmsg".to_string()), + // Some(¶ms.msg), + // ); + // Log::flush(); + + + + botlog::trace( + "ACQUIRED READ LOCK : ID", + Some("Chat > send_botmsg".to_string()), + Some(¶ms.msg), + ); + Log::flush(); self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg) , params).await; From cfadd730962f6372b3f7395d456e32db37eed1b5 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sun, 24 Mar 2024 23:27:21 -0400 Subject: [PATCH 10/18] readlock fix --- src/core/chat.rs | 116 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 83 insertions(+), 33 deletions(-) diff --git a/src/core/chat.rs b/src/core/chat.rs index d596a68..4cfc027 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -247,6 +247,52 @@ impl Chat { */ + + /* + + Use + pub async fn getspecialuserroles( + &self, + chattername: String, + channel: Option, + ) -> Vec { + + */ + + // let params_clone = params.clone(); + + let botclone = Arc::clone(¶ms.bot); + let botlock = botclone.read().await; + let id = botlock.get_identity(); + let id = Arc::clone(&id); + let idlock = id.read().await; // <-- [ ] 03.24 - seems to work + let user_roles = idlock.getspecialuserroles( + params.get_sender(), + Some(Channel(channel_login.clone())) + ).await; + + // [ ] 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 + + 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)) + { + + + self.say_in_reply_to( + ¶ms.msg, + format!("uuh You do not have the right roles to send to {}", + channel_login.clone(), + ), + params.clone() + ).await; + + return; + + } + /* Use the following @@ -261,6 +307,8 @@ impl Chat { */ + /* + botlog::trace( "BEFORE Permissibility checks", Some("chat.rs > send_botmsg ".to_string()), @@ -360,6 +408,7 @@ impl Chat { // Permissible::Block => (), // } + botlog::trace( format!("permisibility check : {:?}",permissability).as_str(), Some("chat.rs > send_botmsg ".to_string()), @@ -387,6 +436,7 @@ impl Chat { } + */ let rl = Arc::clone(&self.ratelimiters); let mut rllock = rl.lock().await; @@ -464,58 +514,58 @@ impl Chat { // pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String) { - // #[async_recursion] + #[async_recursion] pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) { - let params_clone = params.clone(); + // let params_clone = params.clone(); - let botclone = Arc::clone(¶ms_clone.bot); - let botlock = botclone.read().await; - let id = botlock.get_identity(); - let id = Arc::clone(&id); + // let botclone = Arc::clone(¶ms_clone.bot); + // let botlock = botclone.read().await; + // let id = botlock.get_identity(); + // let id = Arc::clone(&id); + + // // botlog::trace( + // // "ACQUIRING WRITE LOCK : ID", + // // Some("Chat > send_botmsg".to_string()), + // // Some(¶ms.msg), + // // ); + // // Log::flush(); // botlog::trace( - // "ACQUIRING WRITE LOCK : ID", + // "ACQUIRING READ LOCK : ID", // Some("Chat > send_botmsg".to_string()), // Some(¶ms.msg), // ); // Log::flush(); - botlog::trace( - "ACQUIRING READ LOCK : ID", - Some("Chat > send_botmsg".to_string()), - Some(¶ms.msg), - ); - Log::flush(); - - // let idlock = id.write().await; // <-- [ ] 03.24 - This is definitely locking it - let idlock = id.read().await; // <-- [ ] 03.24 - seems to work - let a = idlock.getspecialuserroles(params.get_sender(), Some(Channel(msg.channel_login.clone()))).await; - botlog::trace( - format!("GETSPECIALUSERROLES RESULT : {:?}",a).as_str(), - Some("Chat > send_botmsg".to_string()), - Some(¶ms.msg), - ); - Log::flush(); - - - + // // let idlock = id.write().await; // <-- [ ] 03.24 - This is definitely locking it + // let idlock = id.read().await; // <-- [ ] 03.24 - seems to work + // let a = idlock.getspecialuserroles(params.get_sender(), Some(Channel(msg.channel_login.clone()))).await; // botlog::trace( - // "ACQUIRED WRITE LOCK : ID", + // format!("GETSPECIALUSERROLES RESULT : {:?}",a).as_str(), // Some("Chat > send_botmsg".to_string()), // Some(¶ms.msg), // ); // Log::flush(); + + + + // // botlog::trace( + // // "ACQUIRED WRITE LOCK : ID", + // // Some("Chat > send_botmsg".to_string()), + // // Some(¶ms.msg), + // // ); + // // Log::flush(); - botlog::trace( - "ACQUIRED READ LOCK : ID", - Some("Chat > send_botmsg".to_string()), - Some(¶ms.msg), - ); - Log::flush(); + // botlog::trace( + // "ACQUIRED READ LOCK : ID", + // Some("Chat > send_botmsg".to_string()), + // Some(¶ms.msg), + // ); + // Log::flush(); self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg) , params).await; From 8b3395c19a26da918e70e14cfe00fb1d089cfc03 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sun, 24 Mar 2024 23:42:59 -0400 Subject: [PATCH 11/18] smol --- src/core/chat.rs | 156 +++++++++++++++++++++++++++-------------------- 1 file changed, 89 insertions(+), 67 deletions(-) diff --git a/src/core/chat.rs b/src/core/chat.rs index 4cfc027..2a6fc26 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -64,6 +64,9 @@ impl Chat { // async fn send_botmsg(&self, msginput: BotMsgType<'_>) { async fn send_botmsg(&self, msginput: BotMsgType<'_>, params : ExecBodyParams) { + + + /* formats message before sending to TwitchIRC @@ -74,7 +77,7 @@ impl Chat { */ - botlog::trace( + botlog::trace( format!("send_bot_msg params : {:?}",msginput).as_str(), Some("chat.rs > send_botmsg ".to_string()), Some(¶ms.msg), @@ -90,47 +93,7 @@ impl Chat { }; - botlog::trace( - "BEFORE GET_CHANNEL_STATUS", - Some("chat.rs > send_botmsg ".to_string()), - Some(¶ms.msg), - ); - - let rslt = self.client.get_channel_status(channel_login.clone()).await == (false,false); - botlog::trace( - format!("GET_CHANNEL_STATUS result = {:?}",rslt).as_str(), - Some("chat.rs > send_botmsg ".to_string()), - Some(¶ms.msg), - ); - - Log::flush(); - - - - if rslt { - // in the case where the provided channel isn't something we're known to be connected to - - botlog::warn( - &format!("A message attempted to send for a Non-Joined Channel : {}",channel_login.clone()), - Some("Chat > send_botmsg".to_string()), - None, - ); - return ; - } - - /* - [x] !! => 03.24 - Somewhere around here, we should be validating module for target channel - */ - - - /* - - Use ModulesManager.modstatus - - modstatus(&self, in_module: BotModule, in_chnl: Channel) -> StatusType - - */ - botlog::trace( "BEFORE parent_module call", @@ -150,6 +113,65 @@ impl Chat { Channel(channel_login.clone()) ).await; + + // botlog::trace( + // "BEFORE GET_CHANNEL_STATUS", + // Some("chat.rs > send_botmsg ".to_string()), + // Some(¶ms.msg), + // ); + + // let rslt = self.client.get_channel_status(channel_login.clone()).await == (false,false); + + // botlog::trace( + // format!("GET_CHANNEL_STATUS result = {:?}",rslt).as_str(), + // Some("chat.rs > send_botmsg ".to_string()), + // Some(¶ms.msg), + // ); + + // Log::flush(); + + + + // if rslt { + // // in the case where the provided channel isn't something we're known to be connected to + + // botlog::warn( + // &format!("A message attempted to send for a Non-Joined Channel : {}",channel_login.clone()), + // Some("Chat > send_botmsg".to_string()), + // None, + // ); + // return ; + // } + + if !params.bot.read().await.bot_channels.contains(&Channel(channel_login.clone())) { + botlog::warn( + &format!("A message attempted to send for a Non-Joined Channel : {}",channel_login.clone()), + Some("Chat > send_botmsg".to_string()), + None, + ); + + self.say_in_reply_to( + ¶ms.msg, + "uuh Bot can't send to a channel it isn't joined".to_string(), + params.clone() + ).await; + + return ; + } + + /* + [x] !! => 03.24 - Somewhere around here, we should be validating module for target channel + */ + + + /* + - Use ModulesManager.modstatus + + modstatus(&self, in_module: BotModule, in_chnl: Channel) -> StatusType + + */ + + // match modstatus { // super::botmodules::StatusType::Enabled(_) => (), // super::botmodules::StatusType::Disabled(_) => (), @@ -190,35 +212,35 @@ impl Chat { Log::flush(); - // self.say_in_reply_to( - // a, - // format!("uuh {:?} is disabled on {} : {:?}", - // parent_module.clone().unwrap(), - // channel_login.clone(), - // lvl - // ), - // params.clone() - // ).await; + self.say_in_reply_to( + a, + format!("uuh {:?} is disabled on {} : {:?}", + parent_module.clone().unwrap(), + channel_login.clone(), + lvl + ), + params.clone() + ).await; - let chat_clone = self.clone(); + // let chat_clone = self.clone(); - // tokio::spawn( async move { - // // for _ in 0..5 { - // // println!(">> Innterroutine triggered!"); - // // sleep(Duration::from_secs_f64(5.0)).await; - // // } + // // tokio::spawn( async move { + // // // for _ in 0..5 { + // // // println!(">> Innterroutine triggered!"); + // // // sleep(Duration::from_secs_f64(5.0)).await; + // // // } - // chat_clone.say_in_reply_to( - // a, - // format!("uuh {:?} is disabled on {} : {:?}", - // parent_module.clone().unwrap(), - // channel_login.clone(), - // lvl - // ), - // params.clone() - // ).await; - // } - // ); + // // chat_clone.say_in_reply_to( + // // a, + // // format!("uuh {:?} is disabled on {} : {:?}", + // // parent_module.clone().unwrap(), + // // channel_login.clone(), + // // lvl + // // ), + // // params.clone() + // // ).await; + // // } + // // ); botlog::trace( From 246c3d98e677ff70b888ca7ef08d933d5f8c9fa7 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Mon, 25 Mar 2024 09:30:15 -0400 Subject: [PATCH 12/18] smol --- src/core/botinstance.rs | 98 ++++++++++++++++++------ src/core/chat.rs | 72 +++++++++-------- src/custom/experimental/experiment001.rs | 2 +- src/custom/experimental/experiment002.rs | 42 +++++----- 4 files changed, 136 insertions(+), 78 deletions(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index b202e5b..750061c 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -390,40 +390,48 @@ impl BotInstance { Some(msg), ); + + let botclone = Arc::clone(&bot); + let botlock = botclone.read().await; + let id = botlock.get_identity(); + let id = Arc::clone(&id); + let idlock = id.read().await; // <-- [ ] 03.24 - seems to work + let user_roles = idlock.getspecialuserroles( + msg.sender.name.clone(), + Some(Channel(msg.channel_login.clone())) + ).await; + + botlog::trace( - "ACQUIRING WRITE LOCK : ID", + &format!("For Disabled Command Evaluating User Roles {:?}", user_roles), Some("BotInstance > listener_main_prvmsg()".to_string()), Some(msg), ); - - const OF_CMD_CHANNEL:Channel = Channel(String::new()); + // Only respond to those with th ebelow User Roles - let elevated_access = { - let mut idlock = id.write().await; - let (permissability, _) = idlock - .can_user_run_prvmsg(msg, - vec![ - identity::UserRole::BotAdmin, - identity::UserRole::Mod(OF_CMD_CHANNEL), - identity::UserRole::SupMod(OF_CMD_CHANNEL), - identity::UserRole::Broadcaster, - ]) - .await; - - permissability - }; - - if let Permissible::Allow = elevated_access { - let botlock = bot.read().await; + if user_roles.contains(&identity::UserRole::Mod(Channel(msg.channel_login.clone()))) + || user_roles.contains(&identity::UserRole::SupMod(Channel(msg.channel_login.clone()))) + || user_roles.contains(&identity::UserRole::Broadcaster) + || user_roles.contains(&identity::UserRole::BotAdmin) + { + + + // self.say_in_reply_to( + // ¶ms.msg, + // format!("uuh You do not have the right roles to send to {}", + // channel_login.clone(), + // ), + // params.clone() + // ).await; let outstr = format!("sadg Module is disabled : {:?}",a); + let params = ExecBodyParams { bot : Arc::clone(&bot), msg : (*msg).clone(), parent_act : Arc::clone(&act_clone), - }; botlock.botmgrs.chat.say_in_reply_to( @@ -432,7 +440,53 @@ impl BotInstance { // c.module.clone() params, ).await; - } + + } + + + // botlog::trace( + // "ACQUIRING WRITE LOCK : ID", + // Some("BotInstance > listener_main_prvmsg()".to_string()), + // Some(msg), + // ); + + + // const OF_CMD_CHANNEL:Channel = Channel(String::new()); + + // let elevated_access = { + // let mut idlock = id.write().await; + // let (permissability, _) = idlock + // .can_user_run_prvmsg(msg, + // vec![ + // identity::UserRole::BotAdmin, + // identity::UserRole::Mod(OF_CMD_CHANNEL), + // identity::UserRole::SupMod(OF_CMD_CHANNEL), + // identity::UserRole::Broadcaster, + // ]) + // .await; + + // permissability + // }; + + // if let Permissible::Allow = elevated_access { + // let botlock = bot.read().await; + // let outstr = + // format!("sadg Module is disabled : {:?}",a); + + // let params = ExecBodyParams { + // bot : Arc::clone(&bot), + // msg : (*msg).clone(), + // parent_act : Arc::clone(&act_clone), + + // }; + + // botlock.botmgrs.chat.say_in_reply_to( + // msg, + // outstr, + // // c.module.clone() + // params, + // ).await; + // } return; }; diff --git a/src/core/chat.rs b/src/core/chat.rs index 2a6fc26..6fc546a 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -82,6 +82,7 @@ impl Chat { Some("chat.rs > send_botmsg ".to_string()), Some(¶ms.msg), ); + Log::flush(); let (channel_login,mut outmsg) = match msginput.clone() { BotMsgType::SayInReplyTo(msg, outmsg) => { @@ -150,12 +151,20 @@ impl Chat { None, ); - self.say_in_reply_to( - ¶ms.msg, - "uuh Bot can't send to a channel it isn't joined".to_string(), - params.clone() - ).await; + // self.say_in_reply_to( + // ¶ms.msg, + // "uuh Bot can't send to a channel it isn't joined".to_string(), + // params.clone() + // ).await; + if let BotMsgType::SayInReplyTo(a,_) = msginput { + self.say_in_reply_to( + a, + "uuh Bot can't send to a channel it isn't joined".to_string(), + params.clone() + ).await; + + } return ; } @@ -222,26 +231,6 @@ impl Chat { params.clone() ).await; - // let chat_clone = self.clone(); - - // // tokio::spawn( async move { - // // // for _ in 0..5 { - // // // println!(">> Innterroutine triggered!"); - // // // sleep(Duration::from_secs_f64(5.0)).await; - // // // } - - // // chat_clone.say_in_reply_to( - // // a, - // // format!("uuh {:?} is disabled on {} : {:?}", - // // parent_module.clone().unwrap(), - // // channel_login.clone(), - // // lvl - // // ), - // // params.clone() - // // ).await; - // // } - // // ); - botlog::trace( "AFTER potential Async recursion", @@ -269,6 +258,9 @@ impl Chat { */ + + + /* @@ -293,23 +285,35 @@ impl Chat { Some(Channel(channel_login.clone())) ).await; + botlog::trace( + format!("BEFORE user roles check check : userroles = {:?}",user_roles).as_str(), + Some("chat.rs > send_botmsg ".to_string()), + Some(¶ms.msg), + ); + + Log::flush(); + // [ ] 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 + // 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)) 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::SupMod(Channel(channel_login.clone()))) + || user_roles.contains(&identity::UserRole::Broadcaster) + || user_roles.contains(&identity::UserRole::BotAdmin)) { - self.say_in_reply_to( - ¶ms.msg, - format!("uuh You do not have the right roles to send to {}", - channel_login.clone(), - ), - params.clone() - ).await; + // self.say_in_reply_to( + // ¶ms.msg, + // format!("uuh You do not have the right roles to send to {}", + // channel_login.clone(), + // ), + // params.clone() + // ).await; return; diff --git a/src/custom/experimental/experiment001.rs b/src/custom/experimental/experiment001.rs index 54e6552..be0cb8d 100644 --- a/src/custom/experimental/experiment001.rs +++ b/src/custom/experimental/experiment001.rs @@ -142,7 +142,7 @@ pub async fn init(mgr: Arc) { Some(¶ms.msg), ); - let rollwin = rand::thread_rng().gen_ratio(1, 1); + let rollwin = rand::thread_rng().gen_ratio(1, 10); if rollwin { botlog::debug( diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index d657c19..96c92c5 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -145,34 +145,34 @@ async fn sayout(params : ExecBodyParams) { None, ); - // if botlock.botmgrs.chat.client.get_channel_status(trgchnl.to_string().clone()).await == (false,false) { - if !botlock.bot_channels.contains(&Channel(trgchnl.to_lowercase().to_string().clone())) { + // // if botlock.botmgrs.chat.client.get_channel_status(trgchnl.to_string().clone()).await == (false,false) { + // if !botlock.bot_channels.contains(&Channel(trgchnl.to_lowercase().to_string().clone())) { - // in the case where the provided channel isn't something we're known to be connected to - botlog::warn( - &format!("A message attempted to send for a Non-Joined Channel : {}",trgchnl.to_string().clone()), - Some("Chat > send_botmsg".to_string()), - None, - ); - // return ; + // // in the case where the provided channel isn't something we're known to be connected to + // botlog::warn( + // &format!("A message attempted to send for a Non-Joined Channel : {}",trgchnl.to_string().clone()), + // Some("Chat > send_botmsg".to_string()), + // None, + // ); + // // return ; - if parent_module.clone().is_some() { + // if parent_module.clone().is_some() { - botlock - .botmgrs - .chat - .say_in_reply_to( - ¶ms.msg, - format!("Not a Joined Channel : {}",trgchnl), - // parent_module.clone().unwrap().clone() - params.clone(), - ).await; + // botlock + // .botmgrs + // .chat + // .say_in_reply_to( + // ¶ms.msg, + // format!("Not a Joined Channel : {}",trgchnl), + // // parent_module.clone().unwrap().clone() + // params.clone(), + // ).await; - } + // } - } + // } /* 1. If a Reply , From 10d25bf34f9ca66cac3e4c68593f429f0b1609d7 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Mon, 25 Mar 2024 10:07:34 -0400 Subject: [PATCH 13/18] notif BotMsgType --- src/core/chat.rs | 125 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 85 insertions(+), 40 deletions(-) diff --git a/src/core/chat.rs b/src/core/chat.rs index 6fc546a..e82fd0a 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -40,6 +40,7 @@ pub struct Chat { enum BotMsgType<'a> { SayInReplyTo(&'a PrivmsgMessage,String), Say(String,String), + Notif(String), // For Bot Sent Notifications } @@ -63,7 +64,9 @@ impl Chat { // async fn send_botmsg(&self, msginput: BotMsgType<'_>) { - async fn send_botmsg(&self, msginput: BotMsgType<'_>, params : ExecBodyParams) { + #[async_recursion] + // async fn send_botmsg(&self, msginput: BotMsgType<'_>, params : ExecBodyParams) { + async fn send_botmsg(&self, msginput: BotMsgType<'async_recursion>, params : ExecBodyParams) { @@ -91,6 +94,10 @@ impl Chat { BotMsgType::Say(a,b ) => { (a.clone(),b.clone()) }, + BotMsgType::Notif(outmsg) => { + // (msg.channel_login.clone(),outmsg) + (params.msg.channel_login.clone(),outmsg) + } }; @@ -156,15 +163,20 @@ impl Chat { // "uuh Bot can't send to a channel it isn't joined".to_string(), // params.clone() // ).await; - if let BotMsgType::SayInReplyTo(a,_) = msginput { + if let BotMsgType::SayInReplyTo(_prvmsg,_outmsg) = msginput { - self.say_in_reply_to( - a, + // self.say_in_reply_to( + // a, + // "uuh Bot can't send to a channel it isn't joined".to_string(), + // params.clone() + // ).await; + self.send_botmsg(BotMsgType::Notif( "uuh Bot can't send to a channel it isn't joined".to_string(), - params.clone() - ).await; + ), + params).await; } + return ; } @@ -209,43 +221,42 @@ impl Chat { Log::flush(); + match msginput { + BotMsgType::Notif(_) => (), // Do nothing with Notif > We'll validate the user later to handle + BotMsgType::SayInReplyTo(_, _) | BotMsgType::Say(_,_) => { + + botlog::trace( + "BEFORE potential Async recursion", + Some("chat.rs > send_botmsg ".to_string()), + Some(¶ms.clone().msg), + ); + + Log::flush(); - if let BotMsgType::SayInReplyTo(a, _) = msginput { - botlog::trace( - "BEFORE potential Async recursion", + self.send_botmsg(BotMsgType::Notif( + format!("uuh {:?} is disabled on {} : {:?}", + parent_module.clone().unwrap(), + channel_login.clone(), + lvl + ), + ), params.clone() + ).await; + + + botlog::trace( + "AFTER potential Async recursion", Some("chat.rs > send_botmsg ".to_string()), - Some(¶ms.clone().msg), - ); + Some(¶ms.msg), + ); + + + Log::flush(); + + return + }, - Log::flush(); - - - self.say_in_reply_to( - a, - format!("uuh {:?} is disabled on {} : {:?}", - parent_module.clone().unwrap(), - channel_login.clone(), - lvl - ), - params.clone() - ).await; - - - botlog::trace( - "AFTER potential Async recursion", - Some("chat.rs > send_botmsg ".to_string()), - Some(¶ms.msg), - ); - - - Log::flush(); - - - } - - return } @@ -315,10 +326,41 @@ impl Chat { // params.clone() // ).await; - return; + match msginput { + BotMsgType::Notif(_) => { + // If the BotMsg is an Error Notification , and the Sender does not have Specific Roles in the Source Channel Sent (where the Error Notif will be sent) + return // return in this case - the User should not see a notification if this path is reached + }, + BotMsgType::SayInReplyTo(_,_ ) | BotMsgType::Say(_,_) => { + // If the BotMsg a Say/SayInReplyTo (from Developer or Chatter) , and the Sender does not have Specific Roles in the Source Channel Sent + + self.send_botmsg(BotMsgType::Notif( + format!("uuh You do not have the right roles to send to {}", + channel_login.clone(), + ), + ), params.clone() + ).await; + + return; + + }, + }; + + } + + /* + At this stage from the above Validations : + msginput would be : + a. BotMsgType::SayInReplyTo | BotMsgType::Say that is + - Towards a Destination Channel that the Sender has Elevated User Roles to Send to + b. BotMsgType::Notif that is + - Going to be sent to the Source Channel (rather than the original say/sayinreplyto was towards) + - A Sender that has Elevated User Roles in Source Channel will see a message ; otherwise, they will not + */ + /* Use the following @@ -499,6 +541,9 @@ impl Chat { BotMsgType::Say(a, _) => { self.client.say(a, outmsg).await.unwrap(); } + BotMsgType::Notif(outmsg) => { + self.client.say_in_reply_to(¶ms.msg, outmsg).await.unwrap(); + } } contextratelimiter.increment_counter(); @@ -540,7 +585,7 @@ impl Chat { // pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String) { - #[async_recursion] + // #[async_recursion] pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) { // let params_clone = params.clone(); From c0603739c91ab03a0fe8ce9aa310c70d172ddc89 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Mon, 25 Mar 2024 11:55:16 -0400 Subject: [PATCH 14/18] Notifs only sent for BotAdmins --- src/core/chat.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/chat.rs b/src/core/chat.rs index e82fd0a..c36fcf7 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -311,10 +311,15 @@ impl Chat { // 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)) + // 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::BotAdmin)) + 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::BotAdmin)) + ) { @@ -328,8 +333,10 @@ impl Chat { match msginput { BotMsgType::Notif(_) => { - // If the BotMsg is an Error Notification , and the Sender does not have Specific Roles in the Source Channel Sent (where the Error Notif will be sent) - return // return in this case - the User should not see a notification if this path is reached + // If Sender is Not a BotAdmin, don't do anything about the notification and return + if !user_roles.contains(&identity::UserRole::BotAdmin) { + return; + } }, BotMsgType::SayInReplyTo(_,_ ) | BotMsgType::Say(_,_) => { // If the BotMsg a Say/SayInReplyTo (from Developer or Chatter) , and the Sender does not have Specific Roles in the Source Channel Sent From 628db3c229ff3faa897fd7bb59b14e564c4a837d Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Mon, 25 Mar 2024 14:11:21 -0400 Subject: [PATCH 15/18] refactor core to use Notif msg --- src/core/botinstance.rs | 71 ++++++++++++------- src/core/botmodules.rs | 148 ++++++++++++++++++++++++++-------------- src/core/chat.rs | 4 +- src/core/identity.rs | 63 ++++++++++------- 4 files changed, 184 insertions(+), 102 deletions(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 750061c..ce55ff9 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -410,38 +410,57 @@ impl BotInstance { // Only respond to those with th ebelow User Roles - if user_roles.contains(&identity::UserRole::Mod(Channel(msg.channel_login.clone()))) - || user_roles.contains(&identity::UserRole::SupMod(Channel(msg.channel_login.clone()))) - || user_roles.contains(&identity::UserRole::Broadcaster) - || user_roles.contains(&identity::UserRole::BotAdmin) - { + let outstr = + format!("sadg Module is disabled : {:?}",a); + + + let params = ExecBodyParams { + bot : Arc::clone(&bot), + msg : (*msg).clone(), + parent_act : Arc::clone(&act_clone), + }; + + // When sending a BotMsgTypeNotif, send_botmsg does Roles related validation as required + + botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif( + outstr + ), + params, + ).await; + + + // if user_roles.contains(&identity::UserRole::Mod(Channel(msg.channel_login.clone()))) + // || user_roles.contains(&identity::UserRole::SupMod(Channel(msg.channel_login.clone()))) + // || user_roles.contains(&identity::UserRole::Broadcaster) + // || user_roles.contains(&identity::UserRole::BotAdmin) + // { - // self.say_in_reply_to( - // ¶ms.msg, - // format!("uuh You do not have the right roles to send to {}", - // channel_login.clone(), - // ), - // params.clone() - // ).await; - let outstr = - format!("sadg Module is disabled : {:?}",a); + // // self.say_in_reply_to( + // // ¶ms.msg, + // // format!("uuh You do not have the right roles to send to {}", + // // channel_login.clone(), + // // ), + // // params.clone() + // // ).await; + // let outstr = + // format!("sadg Module is disabled : {:?}",a); - let params = ExecBodyParams { - bot : Arc::clone(&bot), - msg : (*msg).clone(), - parent_act : Arc::clone(&act_clone), - }; + // let params = ExecBodyParams { + // bot : Arc::clone(&bot), + // msg : (*msg).clone(), + // parent_act : Arc::clone(&act_clone), + // }; - botlock.botmgrs.chat.say_in_reply_to( - msg, - outstr, - // c.module.clone() - params, - ).await; + // botlock.botmgrs.chat.say_in_reply_to( + // msg, + // outstr, + // // c.module.clone() + // params, + // ).await; - } + // } // botlog::trace( diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 5ae8ceb..6fded1b 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -117,9 +117,9 @@ pub async fn init(mgr: Arc) { // BotAction::C(c) => Some(&(*c).module), // BotAction::L(l) => Some(&(*l).module), // _ => None, - // }; + // // }; - let parent_module = params.get_parent_module().await; + // let parent_module = params.get_parent_module().await; @@ -191,20 +191,42 @@ pub async fn init(mgr: Arc) { Some(¶ms.msg), ); - // Only call Say if there is a parent module passed - if parent_module.is_some() { + // We should call a notification around here + + let bot = params.clone().bot; + + let botclone = Arc::clone(&bot); + let botlock = botclone.read().await; + let id = botlock.get_identity(); + let id = Arc::clone(&id); + let idlock = id.read().await; // <-- [ ] 03.24 - seems to work + let user_roles = idlock.getspecialuserroles( + params.msg.sender.name.clone(), + Some(Channel(params.msg.channel_login.clone())) + ).await; + + botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif( + outmsg.to_string() + ), + params.clone(), + ).await; + + + + // // Only call Say if there is a parent module passed + // if parent_module.is_some() { - botlock - .botmgrs - .chat - .say_in_reply_to( - ¶ms.msg, - outmsg.to_string() , - // parent_module.unwrap().clone() - params.clone(), - ).await; - } + // botlock + // .botmgrs + // .chat + // .say_in_reply_to( + // ¶ms.msg, + // outmsg.to_string() , + // // parent_module.unwrap().clone() + // params.clone(), + // ).await; + // } return; @@ -236,6 +258,9 @@ pub async fn init(mgr: Arc) { trg_level, id).await; + + // We should call a notification around here + let outmsg = match rslt.clone() { ChangeResult::Failed(a) => format!("Stare Failed : {}",a), @@ -243,22 +268,30 @@ pub async fn init(mgr: Arc) { ChangeResult::Success(a) => format!("YAAY Success : {}",a), }; + botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif( + outmsg.to_string() + ), + params.clone(), + ).await; + - // Only call Say if there is a parent module passed - if parent_module.is_some() { + + + // // Only call Say if there is a parent module passed + // if parent_module.is_some() { - botlock - .botmgrs - .chat - .say_in_reply_to( - ¶ms.msg, - outmsg.to_string(), - // parent_module.unwrap().clone() - params.clone(), - ).await; + // botlock + // .botmgrs + // .chat + // .say_in_reply_to( + // ¶ms.msg, + // outmsg.to_string(), + // // parent_module.unwrap().clone() + // params.clone(), + // ).await; - } + // } @@ -414,22 +447,29 @@ pub async fn init(mgr: Arc) { // _ => None, // }; + // We should call a notification around here + + botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif( + outmsg.to_string() + ), + params.clone(), + ).await; - // Only call Say if there is a parent module passed - if parent_module.is_some() { + // // Only call Say if there is a parent module passed + // if parent_module.is_some() { - botlock - .botmgrs - .chat - .say_in_reply_to( - ¶ms.msg, - outmsg.to_string(), - // ,parent_module.unwrap().clone() - params.clone() - ).await; + // botlock + // .botmgrs + // .chat + // .say_in_reply_to( + // ¶ms.msg, + // outmsg.to_string(), + // // ,parent_module.unwrap().clone() + // params.clone() + // ).await; - } + // } return; @@ -471,21 +511,29 @@ pub async fn init(mgr: Arc) { ChangeResult::Success(a) => format!("YAAY Success : {}",a), }; + // We should call a notification around here - // Only call Say if there is a parent module passed - if parent_module.is_some() { + botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif( + outmsg.to_string() + ), + params.clone(), + ).await; - botlock - .botmgrs - .chat - .say_in_reply_to( - ¶ms.msg, - outmsg.to_string(), - // parent_module.unwrap().clone() - params.clone(), - ).await; - } + // // Only call Say if there is a parent module passed + // if parent_module.is_some() { + + // botlock + // .botmgrs + // .chat + // .say_in_reply_to( + // ¶ms.msg, + // outmsg.to_string(), + // // parent_module.unwrap().clone() + // params.clone(), + // ).await; + + // } diff --git a/src/core/chat.rs b/src/core/chat.rs index c36fcf7..f07eb55 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -37,7 +37,7 @@ pub struct Chat { #[derive(Clone,Debug)] -enum BotMsgType<'a> { +pub enum BotMsgType<'a> { SayInReplyTo(&'a PrivmsgMessage,String), Say(String,String), Notif(String), // For Bot Sent Notifications @@ -66,7 +66,7 @@ impl Chat { // async fn send_botmsg(&self, msginput: BotMsgType<'_>) { #[async_recursion] // async fn send_botmsg(&self, msginput: BotMsgType<'_>, params : ExecBodyParams) { - async fn send_botmsg(&self, msginput: BotMsgType<'async_recursion>, params : ExecBodyParams) { + pub async fn send_botmsg(&self, msginput: BotMsgType<'async_recursion>, params : ExecBodyParams) { diff --git a/src/core/identity.rs b/src/core/identity.rs index 0be4dea..b9223bf 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -231,21 +231,30 @@ pub async fn init(mgr: Arc) { Some(¶ms.msg), ); - // Only call Say if there is a parent module passed - if parent_module.is_some() { + // We should call a notification around here + + botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif( + outmsg.to_string() + ), + params.clone(), + ).await; - botlock - .botmgrs - .chat - .say_in_reply_to( - ¶ms.msg, - outmsg.to_string(), - // parent_module.unwrap().clone() - params.clone(), - ).await; + // // Only call Say if there is a parent module passed + // if parent_module.is_some() { - } + + // botlock + // .botmgrs + // .chat + // .say_in_reply_to( + // ¶ms.msg, + // outmsg.to_string(), + // // parent_module.unwrap().clone() + // params.clone(), + // ).await; + + // } botlog::trace( // &format!("End of cmd_promote()"), @@ -458,21 +467,27 @@ pub async fn init(mgr: Arc) { Some(¶ms.msg), ); + botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif( + outmsg.to_string() + ), + params.clone(), + ).await; - // Only call Say if there is a parent module passed - if parent_module.is_some() { - botlock - .botmgrs - .chat - .say_in_reply_to( - ¶ms.msg, - outmsg.to_string(), - // parent_module.unwrap().clone() - params.clone() - ).await; + // // Only call Say if there is a parent module passed + // if parent_module.is_some() { - } + // botlock + // .botmgrs + // .chat + // .say_in_reply_to( + // ¶ms.msg, + // outmsg.to_string(), + // // parent_module.unwrap().clone() + // params.clone() + // ).await; + + // } From d746d0d073c82f7776aa6eaef46848f5c945a921 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Mon, 25 Mar 2024 14:15:14 -0400 Subject: [PATCH 16/18] custom does not req parent_module validation before say --- src/core/identity.rs | 22 ++-- src/custom/experimental/experiment001.rs | 131 ++++++++++++++++------- src/custom/experimental/experiment002.rs | 35 +++--- 3 files changed, 127 insertions(+), 61 deletions(-) diff --git a/src/core/identity.rs b/src/core/identity.rs index b9223bf..756a50d 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -653,16 +653,22 @@ pub async fn init(mgr: Arc) { Some(¶ms.msg), ); - if parent_module.is_some() { + botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif( + outmsg.to_string() + ), + params.clone(), + ).await; - botlock.botmgrs.chat.say_in_reply_to( - ¶ms.msg, - outmsg, - // parent_module.unwrap().clone() - params.clone() - ).await; + // if parent_module.is_some() { - } + // botlock.botmgrs.chat.say_in_reply_to( + // ¶ms.msg, + // outmsg, + // // parent_module.unwrap().clone() + // params.clone() + // ).await; + + // } // [ ] NOTE : After the above, I should receive only the roles in the context of the current channel I received this ideally and maybe BotAdmin ; not outside diff --git a/src/custom/experimental/experiment001.rs b/src/custom/experimental/experiment001.rs index be0cb8d..aa9575a 100644 --- a/src/custom/experimental/experiment001.rs +++ b/src/custom/experimental/experiment001.rs @@ -126,7 +126,7 @@ pub async fn init(mgr: Arc) { // }; - let parent_module = params.get_parent_module().await; + // let parent_module = params.get_parent_module().await; // [ ] Uses gen_ratio() to output bool based on a ratio probability . // - For example gen_ratio(2,3) is 2 out of 3 or 0.67% (numerator,denomitator) @@ -153,23 +153,34 @@ pub async fn init(mgr: Arc) { let bot = Arc::clone(¶ms.bot); + let botlock = bot.read().await; + // uses chat.say_in_reply_to() for the bot controls for messages + botlock + .botmgrs + .chat + .say_in_reply_to( + ¶ms.msg, + String::from("GoodGirl xdd "), + // parent_module.unwrap().clone() + params.clone() + ).await; - if parent_module.is_some() { + // if parent_module.is_some() { - // uses chat.say_in_reply_to() for the bot controls for messages - botlock - .botmgrs - .chat - .say_in_reply_to( - ¶ms.msg, - String::from("GoodGirl xdd "), - // parent_module.unwrap().clone() - params.clone() - ).await; + // // uses chat.say_in_reply_to() for the bot controls for messages + // botlock + // .botmgrs + // .chat + // .say_in_reply_to( + // ¶ms.msg, + // String::from("GoodGirl xdd "), + // // parent_module.unwrap().clone() + // params.clone() + // ).await; - } + // } } } @@ -219,46 +230,84 @@ async fn babygirl(params : ExecBodyParams) { let botlock = bot.read().await; - if parent_module.is_some() { - - // uses chat.say_in_reply_to() for the bot controls for messages - botlock - .botmgrs - .chat - .say_in_reply_to( - ¶ms.msg, - String::from("16:13 notohh: cafdk"), - // parent_module.clone().unwrap().clone() - params.clone() - ).await; - sleep(Duration::from_secs_f64(0.5)).await; - - botlock + // uses chat.say_in_reply_to() for the bot controls for messages + botlock .botmgrs .chat .say_in_reply_to( ¶ms.msg, - String::from("16:13 notohh: have fun eating princess"), - // parent_module.clone().unwrap().clone() + String::from("16:13 notohh: cafdk"), params.clone() ).await; - sleep(Duration::from_secs_f64(2.0)).await; + sleep(Duration::from_secs_f64(0.5)).await; - botlock - .botmgrs - .chat - .say_in_reply_to( - ¶ms.msg, - String::from("16:13 notohh: baby girl"), - // parent_module.unwrap().clone() - params.clone() - ).await; + botlock + .botmgrs + .chat + .say_in_reply_to( + ¶ms.msg, + String::from("16:13 notohh: have fun eating princess"), + params.clone() + ).await; - } + + sleep(Duration::from_secs_f64(2.0)).await; + + botlock + .botmgrs + .chat + .say_in_reply_to( + ¶ms.msg, + String::from("16:13 notohh: baby girl"), + params.clone() + ).await; + + + + // if parent_module.is_some() { + + // // uses chat.say_in_reply_to() for the bot controls for messages + // botlock + // .botmgrs + // .chat + // .say_in_reply_to( + // ¶ms.msg, + // String::from("16:13 notohh: cafdk"), + // // parent_module.clone().unwrap().clone() + // params.clone() + // ).await; + + + // sleep(Duration::from_secs_f64(0.5)).await; + + // botlock + // .botmgrs + // .chat + // .say_in_reply_to( + // ¶ms.msg, + // String::from("16:13 notohh: have fun eating princess"), + // // parent_module.clone().unwrap().clone() + // params.clone() + // ).await; + + + // sleep(Duration::from_secs_f64(2.0)).await; + + // botlock + // .botmgrs + // .chat + // .say_in_reply_to( + // ¶ms.msg, + // String::from("16:13 notohh: baby girl"), + // // parent_module.unwrap().clone() + // params.clone() + // ).await; + + // } } diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index 96c92c5..fa4a6ce 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -250,21 +250,32 @@ async fn sayout(params : ExecBodyParams) { let botlock = bot.read().await; + // uses chat.say_in_reply_to() for the bot controls for messages + botlock + .botmgrs + .chat + .say_in_reply_to( + ¶ms.msg, + String::from("Invalid arguments"), + // parent_module.unwrap().clone() + params.clone() + ).await; - if parent_module.is_some() { + + // if parent_module.is_some() { - // uses chat.say_in_reply_to() for the bot controls for messages - botlock - .botmgrs - .chat - .say_in_reply_to( - ¶ms.msg, - String::from("Invalid arguments"), - // parent_module.unwrap().clone() - params.clone() - ).await; + // // uses chat.say_in_reply_to() for the bot controls for messages + // botlock + // .botmgrs + // .chat + // .say_in_reply_to( + // ¶ms.msg, + // String::from("Invalid arguments"), + // // parent_module.unwrap().clone() + // params.clone() + // ).await; - } + // } }, From f582c36f97d6c4f728ac0d665ee1c68cb5c288d1 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Mon, 25 Mar 2024 15:46:37 -0400 Subject: [PATCH 17/18] clippy --- src/core/bot_actions.rs | 22 +++++++++++++++++----- src/core/botinstance.rs | 4 ++-- src/core/botmodules.rs | 22 +++++++++++----------- src/core/chat.rs | 4 ++-- src/core/identity.rs | 10 +++++----- src/custom/experimental/experiment001.rs | 8 ++++---- src/custom/experimental/experiment002.rs | 6 +++--- 7 files changed, 44 insertions(+), 32 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index 4b17758..ac04077 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -27,7 +27,19 @@ impl ExecBodyParams { let parent_act = Arc::clone(&self.parent_act); let parent_act_lock = parent_act.read().await; let act = &(*parent_act_lock); - let parent_module = match act { + // let parent_module = match act { + // BotAction::C(c) => { + // let temp = c.module.clone(); + // Some(temp) + // }, + // BotAction::L(l) => { + // let temp = l.module.clone(); + // Some(temp) + // }, + // _ => None + // }; + // parent_module + match act { BotAction::C(c) => { let temp = c.module.clone(); Some(temp) @@ -37,8 +49,7 @@ impl ExecBodyParams { Some(temp) }, _ => None - }; - parent_module + } } pub fn get_sender(&self) -> String { @@ -57,9 +68,10 @@ impl ExecBodyParams { } } - let requestor_badge = requestor_badge_mut; + // let requestor_badge = requestor_badge_mut; - requestor_badge + // requestor_badge + requestor_badge_mut } diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index ce55ff9..ee52c2f 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -20,7 +20,7 @@ use crate::core::ratelimiter::RateLimiter; // use crate::core::bot_actions::actions_util::BotAR; use crate::core::bot_actions::BotAR; use crate::core::botmodules::ModulesManager; -use crate::core::identity::{IdentityManager, Permissible,self}; +use crate::core::identity::{IdentityManager, Permissible}; use crate::core::botlog; use crate::core::chat::Chat; @@ -47,7 +47,7 @@ pub enum ChangeResult { pub struct Channel(pub String); use super::bot_actions::ExecBodyParams; -use super::botmodules::{BotAction, StatusType}; +use super::botmodules::StatusType; #[derive(Clone)] pub struct BotManagers { diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 6fded1b..a0cfc45 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -24,7 +24,7 @@ use core::panic; use std::collections::HashMap; use std::sync::Arc; -use twitch_irc::message::PrivmsgMessage; +// use twitch_irc::message::PrivmsgMessage; use casual_logger::Log; @@ -33,7 +33,7 @@ use tokio::sync::RwLock; use async_trait::async_trait; // use self::bot_actions::actions_util::BotAR; -use crate::core::bot_actions::BotAR; +// use crate::core::bot_actions::BotAR; use crate::core::bot_actions::actions_util; use crate::core::bot_actions::ExecBodyParams; use crate::core::botinstance::{BotInstance, Channel,ChangeResult}; @@ -181,7 +181,7 @@ pub async fn init(mgr: Arc) { // if let None = trg_module { if trg_module.is_none() { - let botlock = params.bot.read().await; + // let botlock = params.bot.read().await; let outmsg = "uuh You need to pass a module"; @@ -197,13 +197,13 @@ pub async fn init(mgr: Arc) { let botclone = Arc::clone(&bot); let botlock = botclone.read().await; - let id = botlock.get_identity(); - let id = Arc::clone(&id); - let idlock = id.read().await; // <-- [ ] 03.24 - seems to work - let user_roles = idlock.getspecialuserroles( - params.msg.sender.name.clone(), - Some(Channel(params.msg.channel_login.clone())) - ).await; + // let id = botlock.get_identity(); + // let id = Arc::clone(&id); + // let idlock = id.read().await; // <-- [ ] 03.24 - seems to work + // let user_roles = idlock.getspecialuserroles( + // params.msg.sender.name.clone(), + // Some(Channel(params.msg.channel_login.clone())) + // ).await; botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif( outmsg.to_string() @@ -367,7 +367,7 @@ pub async fn init(mgr: Arc) { // _ => None, // }; - let parent_module = params.get_parent_module().await; + // let parent_module = params.get_parent_module().await; // [x] Unwraps arguments from message diff --git a/src/core/chat.rs b/src/core/chat.rs index f07eb55..9c365f6 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -12,7 +12,7 @@ use casual_logger::Log; use rand::Rng; -use crate::core::identity::Permissible; +// use crate::core::identity::Permissible; use crate::core::ratelimiter; use crate::core::ratelimiter::RateLimiter; @@ -23,7 +23,7 @@ use crate::core::botlog; use tokio::time::{sleep, Duration}; use super::bot_actions::ExecBodyParams; -use super::botmodules::BotModule; +// use super::botmodules::BotModule; use super::identity; diff --git a/src/core/identity.rs b/src/core/identity.rs index 756a50d..fa3a3e2 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -8,11 +8,11 @@ use twitch_irc::message::PrivmsgMessage; use casual_logger::Log; use crate::core::bot_actions::actions_util; -use crate::core::bot_actions::BotAR; +// use crate::core::bot_actions::BotAR; use crate::core::bot_actions::ExecBodyParams; use crate::core::botinstance::{Channel,ChangeResult}; use crate::core::botlog; -use crate::core::botmodules::BotAction; +// use crate::core::botmodules::BotAction; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager}; use dotenv::dotenv; @@ -121,7 +121,7 @@ pub async fn init(mgr: Arc) { // _ => None, // }; - let parent_module = params.get_parent_module().await; + // let parent_module = params.get_parent_module().await; // println!("{}",params.msg.message_text); botlog::trace( @@ -331,7 +331,7 @@ pub async fn init(mgr: Arc) { // _ => None, // }; - let parent_module = params.get_parent_module().await; + // let parent_module = params.get_parent_module().await; // [x] Unwraps arguments from message @@ -540,7 +540,7 @@ pub async fn init(mgr: Arc) { // _ => None, // }; - let parent_module = params.get_parent_module().await; + // let parent_module = params.get_parent_module().await; let mut argv = params.msg.message_text.split(' '); diff --git a/src/custom/experimental/experiment001.rs b/src/custom/experimental/experiment001.rs index aa9575a..f1f880f 100644 --- a/src/custom/experimental/experiment001.rs +++ b/src/custom/experimental/experiment001.rs @@ -13,7 +13,7 @@ use rand::Rng; use std::sync::Arc; -use twitch_irc::message::PrivmsgMessage; +// use twitch_irc::message::PrivmsgMessage; use crate::core::bot_actions::ExecBodyParams; // use crate::core::botinstance::ChType::Channel; @@ -21,8 +21,8 @@ use crate::core::botinstance::Channel; use crate::core::botlog; use crate::core::bot_actions::actions_util; -use crate::core::bot_actions::BotAR; -use crate::core::botmodules::BotAction; +// use crate::core::bot_actions::BotAR; +// use crate::core::botmodules::BotAction; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager}; use crate::core::identity::UserRole::*; @@ -215,7 +215,7 @@ async fn babygirl(params : ExecBodyParams) { - let parent_module = params.get_parent_module().await; + // let parent_module = params.get_parent_module().await; println!("babygirl triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index fa4a6ce..f45e056 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -15,19 +15,19 @@ use std::sync::Arc; use chrono::{TimeZone,Local}; -use twitch_irc::message::PrivmsgMessage; +// use twitch_irc::message::PrivmsgMessage; use crate::core::bot_actions::ExecBodyParams; // use crate::core::botinstance::ChType::Channel; use crate::core::botinstance::Channel; // use ChType::Channel; use crate::core::botlog; -use crate::core::botmodules::BotAction; +// use crate::core::botmodules::BotAction; use casual_logger::Log; use crate::core::bot_actions::actions_util; -use crate::core::bot_actions::BotAR; +// use crate::core::bot_actions::BotAR; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager}; use crate::core::identity::UserRole::*; From 6912708cfbeb9ff6ffad47e9a6c78188af79a7d9 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:08:24 -0400 Subject: [PATCH 18/18] comments cleanup --- src/core/bot_actions.rs | 22 --- src/core/botinstance.rs | 99 ----------- src/core/botmodules.rs | 144 +-------------- src/core/chat.rs | 213 +---------------------- src/core/identity.rs | 130 -------------- src/custom/experimental/experiment001.rs | 115 +----------- src/custom/experimental/experiment002.rs | 115 ++---------- 7 files changed, 17 insertions(+), 821 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index ac04077..8941654 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -1,7 +1,6 @@ use twitch_irc::message::PrivmsgMessage; use std::sync::Arc; -// use tokio::sync::{Mutex, RwLock}; use tokio::sync::RwLock; use crate::core::botinstance::BotInstance; @@ -27,18 +26,6 @@ impl ExecBodyParams { let parent_act = Arc::clone(&self.parent_act); let parent_act_lock = parent_act.read().await; let act = &(*parent_act_lock); - // let parent_module = match act { - // BotAction::C(c) => { - // let temp = c.module.clone(); - // Some(temp) - // }, - // BotAction::L(l) => { - // let temp = l.module.clone(); - // Some(temp) - // }, - // _ => None - // }; - // parent_module match act { BotAction::C(c) => { let temp = c.module.clone(); @@ -67,10 +54,6 @@ impl ExecBodyParams { requestor_badge_mut = Some(ChatBadge::Broadcaster); } } - - // let requestor_badge = requestor_badge_mut; - - // requestor_badge requestor_badge_mut } @@ -87,15 +70,10 @@ pub mod actions_util { use std::future::Future; use std::pin::Pin; - - // pub type BotAM = Arc>; - pub type ExecBody = Box< - // dyn Fn(BotAR, PrivmsgMessage) -> Pin + Send>> + Send + Sync, dyn Fn(ExecBodyParams) -> Pin + Send>> + Send + Sync, >; - // pub fn asyncbox(f: fn(BotAR, PrivmsgMessage) -> T) -> ExecBody pub fn asyncbox(f: fn(ExecBodyParams) -> T) -> ExecBody where T: Future + Send + 'static, diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index ee52c2f..4bcb352 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -17,7 +17,6 @@ use casual_logger::Log; use crate::core::ratelimiter::RateLimiter; -// use crate::core::bot_actions::actions_util::BotAR; use crate::core::bot_actions::BotAR; use crate::core::botmodules::ModulesManager; use crate::core::identity::{IdentityManager, Permissible}; @@ -34,16 +33,8 @@ pub enum ChangeResult { } - #[derive(Debug, PartialEq, Eq, Hash, Clone)] -// pub enum ChType { -// Channel(String), -// } -// -// pub use ChType::Channel; -// -//simplifying from enum to struct pub struct Channel(pub String); use super::bot_actions::ExecBodyParams; @@ -316,12 +307,8 @@ impl BotInstance { for a in acts { - // let act_ar = Arc::new(RwLock::new(a)); - // let act_ar_clone = Arc::clone(&act_ar); let act_clone = Arc::clone(a); - // match a { - // match &(*act_ar_clone.read().await) { match &(*act_clone.read().await) { crate::core::botmodules::BotAction::C(c) => { /* @@ -428,85 +415,6 @@ impl BotInstance { params, ).await; - - // if user_roles.contains(&identity::UserRole::Mod(Channel(msg.channel_login.clone()))) - // || user_roles.contains(&identity::UserRole::SupMod(Channel(msg.channel_login.clone()))) - // || user_roles.contains(&identity::UserRole::Broadcaster) - // || user_roles.contains(&identity::UserRole::BotAdmin) - // { - - - // // self.say_in_reply_to( - // // ¶ms.msg, - // // format!("uuh You do not have the right roles to send to {}", - // // channel_login.clone(), - // // ), - // // params.clone() - // // ).await; - // let outstr = - // format!("sadg Module is disabled : {:?}",a); - - - // let params = ExecBodyParams { - // bot : Arc::clone(&bot), - // msg : (*msg).clone(), - // parent_act : Arc::clone(&act_clone), - // }; - - // botlock.botmgrs.chat.say_in_reply_to( - // msg, - // outstr, - // // c.module.clone() - // params, - // ).await; - - // } - - - // botlog::trace( - // "ACQUIRING WRITE LOCK : ID", - // Some("BotInstance > listener_main_prvmsg()".to_string()), - // Some(msg), - // ); - - - // const OF_CMD_CHANNEL:Channel = Channel(String::new()); - - // let elevated_access = { - // let mut idlock = id.write().await; - // let (permissability, _) = idlock - // .can_user_run_prvmsg(msg, - // vec![ - // identity::UserRole::BotAdmin, - // identity::UserRole::Mod(OF_CMD_CHANNEL), - // identity::UserRole::SupMod(OF_CMD_CHANNEL), - // identity::UserRole::Broadcaster, - // ]) - // .await; - - // permissability - // }; - - // if let Permissible::Allow = elevated_access { - // let botlock = bot.read().await; - // let outstr = - // format!("sadg Module is disabled : {:?}",a); - - // let params = ExecBodyParams { - // bot : Arc::clone(&bot), - // msg : (*msg).clone(), - // parent_act : Arc::clone(&act_clone), - - // }; - - // botlock.botmgrs.chat.say_in_reply_to( - // msg, - // outstr, - // // c.module.clone() - // params, - // ).await; - // } - return; }; @@ -575,19 +483,15 @@ impl BotInstance { ); let a = Arc::clone(&bot); - // c.execute(a, msg.clone()).await; - // c.execute(ExecBodyParams { bot : a, msg : msg.clone() }).await; c.execute(ExecBodyParams { bot : a, msg : msg.clone() , - // parent_act : BotAction::C(c) , parent_act : Arc::clone(&act_clone), }).await; botlog::trace( "exit out of execution", Some("BotInstance > listener_main_prvmsg()".to_string()), - // Some(&msg), Some(msg), ); } @@ -606,7 +510,6 @@ impl BotInstance { crate::core::botmodules::BotAction::L(l) => { let botlock = bot.read().await; - // let id = botlock.get_identity(); // [x] Check first if the Module for that Given Command is Enabled or Disabled on the given Channel let modmgr = Arc::clone(&botlock.botmodules); @@ -628,11 +531,9 @@ impl BotInstance { } else { let a = Arc::clone(&bot); - // l.execute(a, msg.clone()).await; l.execute(ExecBodyParams { bot : a, msg : msg.clone() , - // parent_act : BotAction::L(l) , parent_act : Arc::clone(&act_clone), } ).await; } diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index a0cfc45..25206df 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -24,16 +24,12 @@ use core::panic; use std::collections::HashMap; use std::sync::Arc; -// use twitch_irc::message::PrivmsgMessage; - use casual_logger::Log; use tokio::sync::RwLock; use async_trait::async_trait; -// use self::bot_actions::actions_util::BotAR; -// use crate::core::bot_actions::BotAR; use crate::core::bot_actions::actions_util; use crate::core::bot_actions::ExecBodyParams; use crate::core::botinstance::{BotInstance, Channel,ChangeResult}; @@ -104,25 +100,6 @@ pub async fn init(mgr: Arc) { */ - /* - - Get parent module - - */ - - // let params_clone = Arc::clone(¶ms.parent_act); - // let actlock = params_clone.read().await; - // let act = &(*actlock); - // let parent_module = match act { - // BotAction::C(c) => Some(&(*c).module), - // BotAction::L(l) => Some(&(*l).module), - // _ => None, - // // }; - - // let parent_module = params.get_parent_module().await; - - - // [x] Unwraps arguments from message @@ -197,13 +174,6 @@ pub async fn init(mgr: Arc) { let botclone = Arc::clone(&bot); let botlock = botclone.read().await; - // let id = botlock.get_identity(); - // let id = Arc::clone(&id); - // let idlock = id.read().await; // <-- [ ] 03.24 - seems to work - // let user_roles = idlock.getspecialuserroles( - // params.msg.sender.name.clone(), - // Some(Channel(params.msg.channel_login.clone())) - // ).await; botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif( outmsg.to_string() @@ -211,23 +181,6 @@ pub async fn init(mgr: Arc) { params.clone(), ).await; - - - // // Only call Say if there is a parent module passed - // if parent_module.is_some() { - - - // botlock - // .botmgrs - // .chat - // .say_in_reply_to( - // ¶ms.msg, - // outmsg.to_string() , - // // parent_module.unwrap().clone() - // params.clone(), - // ).await; - // } - return; } @@ -239,7 +192,6 @@ 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(Channel(currchnl)) } ; @@ -249,8 +201,6 @@ pub async fn init(mgr: Arc) { let modmgr = Arc::clone(&botlock.botmodules); let id = botlock.get_identity(); - - // modmgr.exec_enable(requestor, requestor_badge, trg_module, trg_level, id) let rslt = modmgr.exec_enable( requestor, requestor_badge, @@ -274,26 +224,7 @@ pub async fn init(mgr: Arc) { params.clone(), ).await; - - - - // // Only call Say if there is a parent module passed - // if parent_module.is_some() { - - - // botlock - // .botmgrs - // .chat - // .say_in_reply_to( - // ¶ms.msg, - // outmsg.to_string(), - // // parent_module.unwrap().clone() - // params.clone(), - // ).await; - - // } - - + } @@ -354,22 +285,8 @@ pub async fn init(mgr: Arc) { 3c. , and is -f (forced) , return a Success */ - /* - [x] Get the parent module - */ - // let params_clone = Arc::clone(¶ms.parent_act); - // let actlock = params_clone.read().await; - // let act = &(*actlock); - // let parent_module = match act { - // BotAction::C(c) => Some(&(*c).module), - // BotAction::L(l) => Some(&(*l).module), - // _ => None, - // }; - - // let parent_module = params.get_parent_module().await; - - // [x] Unwraps arguments from message + // [x] Unwraps arguments from message let (arg1, arg2) = { @@ -424,7 +341,6 @@ pub async fn init(mgr: Arc) { let trg_module = if (arg1 == Some("-i")) || (arg1 == Some("-f")) { arg2 } else { arg1 }; // if no trg_module was passed - // if let None = trg_module { if trg_module.is_none() { let botlock = params.bot.read().await; @@ -437,16 +353,6 @@ pub async fn init(mgr: Arc) { Some(¶ms.msg), ); - - // let params_clone = Arc::clone(¶ms.parent_act); - // let actlock = params_clone.read().await; - // let act = &(*actlock); - // let parent_module = match act { - // BotAction::C(c) => Some(&(*c).module), - // BotAction::L(l) => Some(&(*l).module), - // _ => None, - // }; - // We should call a notification around here botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif( @@ -455,22 +361,6 @@ pub async fn init(mgr: Arc) { params.clone(), ).await; - - // // Only call Say if there is a parent module passed - // if parent_module.is_some() { - - // botlock - // .botmgrs - // .chat - // .say_in_reply_to( - // ¶ms.msg, - // outmsg.to_string(), - // // ,parent_module.unwrap().clone() - // params.clone() - // ).await; - - // } - return; } @@ -495,7 +385,6 @@ pub async fn init(mgr: Arc) { let force = arg1 == Some("-f"); - // modmgr.exec_enable(requestor, requestor_badge, trg_module, trg_level, id) let rslt = modmgr.exec_disable( requestor, requestor_badge, @@ -519,24 +408,6 @@ pub async fn init(mgr: Arc) { params.clone(), ).await; - - // // Only call Say if there is a parent module passed - // if parent_module.is_some() { - - // botlock - // .botmgrs - // .chat - // .say_in_reply_to( - // ¶ms.msg, - // outmsg.to_string(), - // // parent_module.unwrap().clone() - // params.clone(), - // ).await; - - // } - - - } @@ -558,8 +429,6 @@ impl Eq for BotModule {} impl Hash for BotModule{ fn hash(&self, state: &mut H) { - // self.id.hash(state); - // self.phone.hash(state); let BotModule(name) = self.clone(); name.to_lowercase().hash(state); } @@ -591,7 +460,6 @@ pub enum BotAction { } impl BotAction { - // pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) { pub async fn execute(&self, params : ExecBodyParams) { match self { BotAction::L(a) => a.execute(params).await, @@ -619,7 +487,6 @@ pub struct BotCommand { } impl BotCommand { - // pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) { pub async fn execute(&self, params : ExecBodyParams) { (*self.exec_body)(params).await; } @@ -656,7 +523,6 @@ pub struct Listener { } impl Listener { - // pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) { pub async fn execute(&self, params : ExecBodyParams) { (self.exec_body)(params).await; } @@ -782,7 +648,6 @@ impl ModulesManager { let dbt = self.statusdb.read().await; - // let a = dbt.entry(in_module.clone()).; let (mgrp,statusvector) = dbt.get(&in_module).unwrap(); match mgrp { @@ -1261,7 +1126,6 @@ impl ModulesManager { }, } - // (StatusType::Disabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string())) } pub async fn force_disable(&self, in_module: BotModule) -> (StatusType,ChangeResult) { @@ -1305,7 +1169,6 @@ impl ModulesManager { }, } - // (StatusType::Disabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string())) } pub async fn set_instance_enabled(&self, in_module: BotModule) -> (StatusType,ChangeResult) { @@ -1340,7 +1203,6 @@ impl ModulesManager { }, } - // (StatusType::Enabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string())) } pub async fn set_ch_disabled(&self, in_module: BotModule , in_chnl: Channel) -> (StatusType,ChangeResult) { @@ -1378,7 +1240,6 @@ impl ModulesManager { }, } - // (StatusType::Disabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string())) } pub async fn set_ch_enabled(&self, in_module: BotModule , in_chnl: Channel) -> (StatusType,ChangeResult) { @@ -1416,7 +1277,6 @@ impl ModulesManager { } - // (StatusType::Enabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string())) } diff --git a/src/core/chat.rs b/src/core/chat.rs index 9c365f6..27d36e3 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -12,7 +12,6 @@ use casual_logger::Log; use rand::Rng; -// use crate::core::identity::Permissible; use crate::core::ratelimiter; use crate::core::ratelimiter::RateLimiter; @@ -23,7 +22,6 @@ use crate::core::botlog; use tokio::time::{sleep, Duration}; use super::bot_actions::ExecBodyParams; -// use super::botmodules::BotModule; use super::identity; @@ -60,17 +58,12 @@ impl Chat { self.ratelimiters.lock().await.insert(chnl, n); } - - - - // async fn send_botmsg(&self, msginput: BotMsgType<'_>) { #[async_recursion] - // async fn send_botmsg(&self, msginput: BotMsgType<'_>, params : ExecBodyParams) { pub async fn send_botmsg(&self, msginput: BotMsgType<'async_recursion>, params : ExecBodyParams) { - /* + /* formats message before sending to TwitchIRC - [x] Custom String Formatting (e.g., adding random black spaces) @@ -95,7 +88,6 @@ impl Chat { (a.clone(),b.clone()) }, BotMsgType::Notif(outmsg) => { - // (msg.channel_login.clone(),outmsg) (params.msg.channel_login.clone(),outmsg) } }; @@ -110,7 +102,6 @@ impl Chat { ); let parent_module = params.get_parent_module().await; - // let parent_module = parent_module.clone(); let params_clone = params.clone(); let botclone = Arc::clone(¶ms_clone.bot); @@ -121,36 +112,6 @@ impl Chat { Channel(channel_login.clone()) ).await; - - // botlog::trace( - // "BEFORE GET_CHANNEL_STATUS", - // Some("chat.rs > send_botmsg ".to_string()), - // Some(¶ms.msg), - // ); - - // let rslt = self.client.get_channel_status(channel_login.clone()).await == (false,false); - - // botlog::trace( - // format!("GET_CHANNEL_STATUS result = {:?}",rslt).as_str(), - // Some("chat.rs > send_botmsg ".to_string()), - // Some(¶ms.msg), - // ); - - // Log::flush(); - - - - // if rslt { - // // in the case where the provided channel isn't something we're known to be connected to - - // botlog::warn( - // &format!("A message attempted to send for a Non-Joined Channel : {}",channel_login.clone()), - // Some("Chat > send_botmsg".to_string()), - // None, - // ); - // return ; - // } - if !params.bot.read().await.bot_channels.contains(&Channel(channel_login.clone())) { botlog::warn( &format!("A message attempted to send for a Non-Joined Channel : {}",channel_login.clone()), @@ -158,18 +119,8 @@ impl Chat { None, ); - // self.say_in_reply_to( - // ¶ms.msg, - // "uuh Bot can't send to a channel it isn't joined".to_string(), - // params.clone() - // ).await; if let BotMsgType::SayInReplyTo(_prvmsg,_outmsg) = msginput { - // self.say_in_reply_to( - // a, - // "uuh Bot can't send to a channel it isn't joined".to_string(), - // params.clone() - // ).await; self.send_botmsg(BotMsgType::Notif( "uuh Bot can't send to a channel it isn't joined".to_string(), ), @@ -192,13 +143,6 @@ impl Chat { */ - - // match modstatus { - // super::botmodules::StatusType::Enabled(_) => (), - // super::botmodules::StatusType::Disabled(_) => (), - // } - - botlog::trace( format!("BEFORE modstatus check : modstatus = {:?}",modstatus).as_str(), Some("chat.rs > send_botmsg ".to_string()), @@ -263,7 +207,7 @@ impl Chat { /* - [ ] !! => 03.24 - Would be nice if around here , validate the user has at least some special roles in target channel + [x] !! => 03.24 - Would be nice if around here , validate the user has at least some special roles in target channel - NOTE : If these need to be refined, they can be by the custom module developer at the parent calling function of say() - This just prevents Chat from being triggered in a channel where the sending chatter does not have any special roles @@ -271,8 +215,6 @@ impl Chat { - - /* Use @@ -290,7 +232,7 @@ impl Chat { let botlock = botclone.read().await; let id = botlock.get_identity(); let id = Arc::clone(&id); - let idlock = id.read().await; // <-- [ ] 03.24 - seems to work + let idlock = id.read().await; // <-- [x] 03.24 - seems to work let user_roles = idlock.getspecialuserroles( params.get_sender(), Some(Channel(channel_login.clone())) @@ -304,18 +246,10 @@ impl Chat { Log::flush(); - // [ ] 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 // - NOTE : For now, I've removed BotAdmin just for curiosity - BotAdmins can always elevate themselves if they want - // 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)) - // 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::BotAdmin)) - 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) @@ -323,14 +257,6 @@ impl Chat { { - // self.say_in_reply_to( - // ¶ms.msg, - // format!("uuh You do not have the right roles to send to {}", - // channel_login.clone(), - // ), - // params.clone() - // ).await; - match msginput { BotMsgType::Notif(_) => { // If Sender is Not a BotAdmin, don't do anything about the notification and return @@ -382,137 +308,6 @@ impl Chat { */ - /* - - botlog::trace( - "BEFORE Permissibility checks", - Some("chat.rs > send_botmsg ".to_string()), - Some(¶ms.msg), - ); - - Log::flush(); - - - const OF_CMD_CHANNEL:Channel = Channel(String::new()); - - let permissability = Permissible::Allow; - - { - - - // let id = botlock.get_identity(); - // let mut idlock = id.write().await; // <-- [ ] 03.24 - This is definitely locking it - let channel_login_clone = channel_login.clone(); - - - let spawnhandle = tokio::spawn( - async move { - let botclone = Arc::clone(¶ms_clone.bot); - let botlock = botclone.read().await; - let id = botlock.get_identity(); - - - // botlog::trace( - // "ACQUIRING WRITE LOCK : ID", - // Some("Chat > send_botmsg".to_string()), - // Some(¶ms.msg), - // ); - - - // { - // let mut idlock = id.write().await; // <-- [ ] 03.24 - This is definitely locking it - // } - - // botlog::trace( - // "ACQUIRED WRITE LOCK : ID", - // Some("Chat > send_botmsg".to_string()), - // Some(¶ms.msg), - // ); - - // let (permissability, _) = idlock - // .can_user_run( - // params.get_sender(), - // Channel(channel_login_clone), - // params.get_sender_chatbadge(), - // vec![ - // //identity::UserRole::BotAdmin, - // identity::UserRole::Mod(OF_CMD_CHANNEL), - // identity::UserRole::SupMod(OF_CMD_CHANNEL), - // identity::UserRole::Broadcaster, - // ] - // ).await; - // permissability - } - ); - - if let Ok(permissibility) = spawnhandle.await { - botlog::trace( - format!("permisibility check : {:?}",permissability).as_str(), - Some("chat.rs > send_botmsg ".to_string()), - None - ); - - } - - - } - - - - - // let permissability = { - // let id = botlock.get_identity(); - // let mut idlock = id.write().await; // <-- [ ] 03.24 - This is definitely locking it - // let (permissability, _) = idlock - // .can_user_run( - // params.get_sender(), - // Channel(channel_login.clone()), - // params.get_sender_chatbadge(), - // vec![ - // //identity::UserRole::BotAdmin, - // identity::UserRole::Mod(OF_CMD_CHANNEL), - // identity::UserRole::SupMod(OF_CMD_CHANNEL), - // identity::UserRole::Broadcaster, - // ] - // ).await; - // permissability - // }; - - // match permissability { - // Permissible::Allow => (), - // Permissible::Block => (), - // } - - - botlog::trace( - format!("permisibility check : {:?}",permissability).as_str(), - Some("chat.rs > send_botmsg ".to_string()), - None, - ); - - Log::flush(); - - if let Permissible::Block = permissability { - - - if let BotMsgType::SayInReplyTo(a, _) = msginput { - - // self.say_in_reply_to( - // a, - // format!("uuh you don't have special privileges in {}", - // channel_login.clone() - // ), - // params.clone() - // ).await; - - } - return - - } - - - */ - let rl = Arc::clone(&self.ratelimiters); let mut rllock = rl.lock().await; diff --git a/src/core/identity.rs b/src/core/identity.rs index fa3a3e2..2fbf56e 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -8,11 +8,9 @@ use twitch_irc::message::PrivmsgMessage; use casual_logger::Log; use crate::core::bot_actions::actions_util; -// use crate::core::bot_actions::BotAR; use crate::core::bot_actions::ExecBodyParams; use crate::core::botinstance::{Channel,ChangeResult}; use crate::core::botlog; -// use crate::core::botmodules::BotAction; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager}; use dotenv::dotenv; @@ -70,10 +68,8 @@ pub async fn init(mgr: Arc) { ], }; - // tempb.add_to_modmgr(Arc::clone(&mgr)).await; tempb.add_core_to_modmgr(Arc::clone(&mgr)).await; - // async fn cmd_promote(bot: BotAR, msg: PrivmsgMessage) { async fn cmd_promote(params : ExecBodyParams) { botlog::trace( "Called cmd promote", @@ -107,22 +103,6 @@ pub async fn init(mgr: Arc) { */ - - /* - [x] Get the parent module - */ - - // let params_clone = Arc::clone(¶ms.parent_act); - // let actlock = params_clone.read().await; - // let act = &(*actlock); - // let parent_module = match act { - // BotAction::C(c) => Some(&(*c).module), - // BotAction::L(l) => Some(&(*l).module), - // _ => None, - // }; - - // let parent_module = params.get_parent_module().await; - // println!("{}",params.msg.message_text); botlog::trace( format!("Twich Message > {}", params.msg.message_text).as_str(), @@ -200,7 +180,6 @@ pub async fn init(mgr: Arc) { None => { botlog::debug( - // &format!("No Targer User argument"), "No Targer User argument", Some("identity.rs > cmd_demote()".to_string()), None, @@ -240,24 +219,7 @@ pub async fn init(mgr: Arc) { ).await; - // // Only call Say if there is a parent module passed - // if parent_module.is_some() { - - - // botlock - // .botmgrs - // .chat - // .say_in_reply_to( - // ¶ms.msg, - // outmsg.to_string(), - // // parent_module.unwrap().clone() - // params.clone(), - // ).await; - - // } - botlog::trace( - // &format!("End of cmd_promote()"), "End of cmd_promote()", Some("identity.rs > cmd_prommote()".to_string()), None, @@ -278,11 +240,8 @@ pub async fn init(mgr: Arc) { ], }; - // tempb.add_to_modmgr(Arc::clone(&mgr)).await; - // add_core_to_modmgr tempb.add_core_to_modmgr(Arc::clone(&mgr)).await; - // async fn cmd_demote(bot: BotAR, msg: PrivmsgMessage) { async fn cmd_demote(params : ExecBodyParams) { botlog::debug( "Called cmd demote", @@ -317,23 +276,6 @@ pub async fn init(mgr: Arc) { */ - - /* - [x] Get the parent module - */ - - // let params_clone = Arc::clone(¶ms.parent_act); - // let actlock = params_clone.read().await; - // let act = &(*actlock); - // let parent_module = match act { - // BotAction::C(c) => Some(&(*c).module), - // BotAction::L(l) => Some(&(*l).module), - // _ => None, - // }; - - // let parent_module = params.get_parent_module().await; - - // [x] Unwraps arguments from message let (arg1, _arg2) = { @@ -413,7 +355,6 @@ pub async fn init(mgr: Arc) { let rslt = match targetusr { Some(targetusr) => { botlog::debug( - // &format!("running demote()"), "running demote()", Some("identity.rs > cmd_demote()".to_string()), None, @@ -432,7 +373,6 @@ pub async fn init(mgr: Arc) { None => { botlog::debug( - // &format!("No Targer User argument"), "No Targer User argument", Some("identity.rs > cmd_demote()".to_string()), None, @@ -474,23 +414,6 @@ pub async fn init(mgr: Arc) { ).await; - // // Only call Say if there is a parent module passed - // if parent_module.is_some() { - - // botlock - // .botmgrs - // .chat - // .say_in_reply_to( - // ¶ms.msg, - // outmsg.to_string(), - // // parent_module.unwrap().clone() - // params.clone() - // ).await; - - // } - - - } let tempcomm = BotCommand { @@ -507,11 +430,8 @@ pub async fn init(mgr: Arc) { ], }; - // tempcomm.add_to_modmgr(Arc::clone(&mgr)).await; - // add_core_to_modmgr tempcomm.add_core_to_modmgr(Arc::clone(&mgr)).await; - // async fn getroles(bot: BotAR, msg: PrivmsgMessage) { async fn getroles(params : ExecBodyParams) { botlog::debug( "Called cmd getroles", @@ -527,20 +447,6 @@ pub async fn init(mgr: Arc) { */ - /* - [x] Get the parent module - */ - - // let params_clone = Arc::clone(¶ms.parent_act); - // let actlock = params_clone.read().await; - // let act = &(*actlock); - // let parent_module = match act { - // BotAction::C(c) => Some(&(*c).module), - // BotAction::L(l) => Some(&(*l).module), - // _ => None, - // }; - - // let parent_module = params.get_parent_module().await; let mut argv = params.msg.message_text.split(' '); @@ -613,7 +519,6 @@ pub async fn init(mgr: Arc) { ); botlog::trace( - // &format!("Evaluating special roles"), "Evaluating special roles", Some("identity.rs > init > getroles()".to_string()), Some(¶ms.msg), @@ -659,17 +564,6 @@ pub async fn init(mgr: Arc) { params.clone(), ).await; - // if parent_module.is_some() { - - // botlock.botmgrs.chat.say_in_reply_to( - // ¶ms.msg, - // outmsg, - // // parent_module.unwrap().clone() - // params.clone() - // ).await; - - // } - // [ ] NOTE : After the above, I should receive only the roles in the context of the current channel I received this ideally and maybe BotAdmin ; not outside } @@ -716,13 +610,6 @@ pub enum ChatBadge { Mod, } -// #[derive(Debug, PartialEq, Eq)] -// pub enum ChangeResult { -// Success(String), -// Failed(String), -// NoChange(String), -// } - impl IdentityManager { pub fn init() -> IdentityManager { let mut a = HashMap::new(); @@ -790,7 +677,6 @@ impl IdentityManager { botlog::trace( "Checking within PRVMSG", Some("identity.rs > can_user_run_PRVMSG()".to_string()), - // Some(&msg), Some(msg), ); @@ -806,7 +692,6 @@ impl IdentityManager { self.can_user_run( msg.sender.name.to_owned(), - // Channel::construct(msg.channel_login.to_owned()), Channel(msg.channel_login.to_owned()), sender_badge, cmdreqroles, @@ -822,7 +707,6 @@ impl IdentityManager { chat_badge: Option, cmdreqroles: Vec, // ) -> Result> { ) -> (Permissible, ChangeResult) { - // println!{"Checking within can_user_run()"}; botlog::debug( &format!( "Checking within can_user_run() : @@ -869,8 +753,6 @@ impl IdentityManager { // [x] If cmdreqroles is empty vector , automatically assume Ok(Permissible::Allow) - // let idar = Arc::new(RwLock::new(self)); - let usr = usr.to_lowercase(); @@ -891,9 +773,7 @@ impl IdentityManager { ); } - // if cmdreqroles.len() == 0 { if cmdreqroles.is_empty() { - // return Ok(Permissible::Allow) return ( Permissible::Allow, ChangeResult::NoChange("Command has no required cmdreqroles".to_string()), @@ -907,10 +787,6 @@ impl IdentityManager { // [x] and cmdreqroles includes UserRole::Broadcaster , Ok(Permissible::Allow) // [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::construct(String::new()))) - // || cmdreqroles.contains(&UserRole::SupMod(Channel::construct(String::new()))) - // { if cmdreqroles.contains(&UserRole::Broadcaster) || cmdreqroles.contains(&UserRole::Mod(Channel(String::new()))) || cmdreqroles.contains(&UserRole::SupMod(Channel(String::new()))) @@ -982,7 +858,6 @@ impl IdentityManager { None, ); - // if cmdreqroles.contains(&UserRole::Mod(Channel::construct(String::new()))) { if cmdreqroles.contains(&UserRole::Mod(Channel(String::new()))) { botlog::trace( "Command requires Mod Role", @@ -1019,7 +894,6 @@ 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(Channel::construct(String::new()))) { if cmdreqroles.contains(&UserRole::SupMod(Channel(String::new()))) { if let Some(a) = self .special_roles_users @@ -1564,7 +1438,6 @@ mod core_identity { let test_id_mgr = IdentityManager::init(); // [x] Broadcaster Promotes Chatter to SupMod - // let channel = Some(Channel::construct("broadcasterer".to_string())); let channel = Some(Channel("broadcasterer".to_string())); let trgchatter = "regularChatter".to_string(); let authorizer_badge = &Some(ChatBadge::Broadcaster); @@ -1644,7 +1517,6 @@ mod core_identity { let broadcaster = "broadcasterer".to_string(); let broadcaster_badge = &Some(ChatBadge::Broadcaster); - // let channel = Some(ChType::Channel(broadcaster.clone())); let channel = Channel(broadcaster.clone()); let supchatter = "superModerator".to_string(); let trg_role = None; @@ -1687,7 +1559,6 @@ mod core_identity { // [x] SupMod Attempts to Promote Chatter to SupMod - // let broadcaster = "broadcasterer".to_string(); let authorizer = supchatter; let authorizer_badge = &Some(ChatBadge::Broadcaster); let channel = Some(Channel(broadcaster.clone())); @@ -1758,7 +1629,6 @@ mod core_identity { // [x] SupMod Attempts to Promote Chatter to SupMod - // let broadcaster = "broadcasterer".to_string(); let authorizer = botadmin; let authorizer_badge = botadmin_badge; let channel = Some(Channel("somechannel".to_string())); diff --git a/src/custom/experimental/experiment001.rs b/src/custom/experimental/experiment001.rs index f1f880f..58d0c59 100644 --- a/src/custom/experimental/experiment001.rs +++ b/src/custom/experimental/experiment001.rs @@ -13,16 +13,11 @@ use rand::Rng; use std::sync::Arc; -// use twitch_irc::message::PrivmsgMessage; - use crate::core::bot_actions::ExecBodyParams; -// use crate::core::botinstance::ChType::Channel; use crate::core::botinstance::Channel; use crate::core::botlog; use crate::core::bot_actions::actions_util; -// use crate::core::bot_actions::BotAR; -// use crate::core::botmodules::BotAction; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager}; use crate::core::identity::UserRole::*; @@ -62,18 +57,6 @@ pub async fn init(mgr: Arc) { // 2. Add the BotAction to ModulesManager list1.add_to_modmgr(Arc::clone(&mgr)).await; - - // // 1. Define the BotAction - // let list1 = Listener { - // module: BotModule(String::from("experiments001")), - // name: String::from("babygirl Listener"), - // exec_body: actions_util::asyncbox(babygirl), - // help: String::from(""), - // }; - - // // 2. Add the BotAction to ModulesManager - // list1.add_to_modmgr(Arc::clone(&mgr)).await; - // 1. Define the BotAction let botc1 = BotCommand { module: BotModule(String::from("experiments001")), @@ -112,21 +95,7 @@ pub async fn init(mgr: Arc) { } -// async fn good_girl(bot: BotAR, msg: PrivmsgMessage) { - async fn good_girl(params : ExecBodyParams) { - - - // let params_clone = Arc::clone(¶ms.parent_act); - // let actlock = params_clone.read().await; - // let act = &(*actlock); - // let parent_module = match act { - // BotAction::C(c) => Some(&(*c).module), - // BotAction::L(l) => Some(&(*l).module), - // _ => None, - // }; - - - // let parent_module = params.get_parent_module().await; +async fn good_girl(params : ExecBodyParams) { // [ ] Uses gen_ratio() to output bool based on a ratio probability . // - For example gen_ratio(2,3) is 2 out of 3 or 0.67% (numerator,denomitator) @@ -134,7 +103,6 @@ pub async fn init(mgr: Arc) { if params.msg.sender.name.to_lowercase() == "ModulatingForce".to_lowercase() || params.msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase() - // if params.msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase() { botlog::debug( "Good Girl Detected > Pausechamp", @@ -163,30 +131,14 @@ pub async fn init(mgr: Arc) { .say_in_reply_to( ¶ms.msg, String::from("GoodGirl xdd "), - // parent_module.unwrap().clone() params.clone() ).await; - // if parent_module.is_some() { - - // // uses chat.say_in_reply_to() for the bot controls for messages - // botlock - // .botmgrs - // .chat - // .say_in_reply_to( - // ¶ms.msg, - // String::from("GoodGirl xdd "), - // // parent_module.unwrap().clone() - // params.clone() - // ).await; - - // } } } } -// async fn testy(mut _chat: BotAR, msg: PrivmsgMessage) { async fn testy(params : ExecBodyParams) { println!("testy triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call botlog::debug( @@ -197,26 +149,8 @@ async fn testy(params : ExecBodyParams) { } -// async fn babygirl(bot: BotAR, msg: PrivmsgMessage) { async fn babygirl(params : ExecBodyParams) { - /* - [x] Get the parent module - */ - - // let params_clone = Arc::clone(¶ms.parent_act); - // let actlock = params_clone.read().await; - // let act = &(*actlock); - // let parent_module = match act { - // BotAction::C(c) => Some(&(*c).module), - // BotAction::L(l) => Some(&(*l).module), - // _ => None, - // }; - - - - // let parent_module = params.get_parent_module().await; - println!("babygirl triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call botlog::debug( @@ -231,8 +165,6 @@ async fn babygirl(params : ExecBodyParams) { let botlock = bot.read().await; - - // uses chat.say_in_reply_to() for the bot controls for messages botlock .botmgrs .chat @@ -268,54 +200,9 @@ async fn babygirl(params : ExecBodyParams) { - // if parent_module.is_some() { - - // // uses chat.say_in_reply_to() for the bot controls for messages - // botlock - // .botmgrs - // .chat - // .say_in_reply_to( - // ¶ms.msg, - // String::from("16:13 notohh: cafdk"), - // // parent_module.clone().unwrap().clone() - // params.clone() - // ).await; - - - // sleep(Duration::from_secs_f64(0.5)).await; - - // botlock - // .botmgrs - // .chat - // .say_in_reply_to( - // ¶ms.msg, - // String::from("16:13 notohh: have fun eating princess"), - // // parent_module.clone().unwrap().clone() - // params.clone() - // ).await; - - - // sleep(Duration::from_secs_f64(2.0)).await; - - // botlock - // .botmgrs - // .chat - // .say_in_reply_to( - // ¶ms.msg, - // String::from("16:13 notohh: baby girl"), - // // parent_module.unwrap().clone() - // params.clone() - // ).await; - - // } - - } - - -// async fn routinelike(_bot: BotAR, msg: PrivmsgMessage) { async fn routinelike(params : ExecBodyParams) { println!("routinelike triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call botlog::debug( diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index f45e056..3be88ac 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -10,30 +10,22 @@ */ -// use rand::Rng; use std::sync::Arc; use chrono::{TimeZone,Local}; -// use twitch_irc::message::PrivmsgMessage; use crate::core::bot_actions::ExecBodyParams; -// use crate::core::botinstance::ChType::Channel; use crate::core::botinstance::Channel; -// use ChType::Channel; use crate::core::botlog; -// use crate::core::botmodules::BotAction; use casual_logger::Log; use crate::core::bot_actions::actions_util; -// use crate::core::bot_actions::BotAR; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager}; use crate::core::identity::UserRole::*; -// use tokio::time::{sleep, Duration}; - pub async fn init(mgr: Arc) { const OF_CMD_CHANNEL:Channel = Channel(String::new()); @@ -57,16 +49,13 @@ pub async fn init(mgr: Arc) { // 2. Add the BotAction to ModulesManager botc1.add_to_modmgr(Arc::clone(&mgr)).await; - // If enabling by defauling at instance level - mgr.set_instance_enabled(BotModule(String::from("experiments002"))).await; - - // [ ] #TODO - FOR SOME REASON, IF DISABLED BY DEFAULT, IT OVERFLOWS at RUNGTIME + // If enabling by defauling at instance level , uncomment the following + // mgr.set_instance_enabled(BotModule(String::from("experiments002"))).await; } -// async fn sayout(bot: BotAR, msg: PrivmsgMessage) { async fn sayout(params : ExecBodyParams) { @@ -77,32 +66,16 @@ async fn sayout(params : ExecBodyParams) { - - /* - [x] Get the parent module - */ - - let parent_module = params.get_parent_module().await; - - - let reply_parent = if let Some(Some(reply)) = params.msg.source.tags.0.get("reply-parent-msg-body") { Some(reply) } else { None } ; - // let reply_parent_usr = if let Some(Some(reply)) = msg.source.tags.0.get("reply-thread-parent-user-login") { - // Some(reply) - // } else { None } - // ; - let reply_parent_ts = if let Some(Some(replyts)) = params.msg.source.tags.0.get("tmi-sent-ts") { let a: i64 = replyts.parse().unwrap(); let b = Local.timestamp_millis_opt(a).unwrap(); - // println!("Output : {}",b.to_string()); - // println!("Formatted : {}",b.format("%m-%d %H:%M") ); Some(b.format("%m-%d %H:%M")) } else { None } ; @@ -145,35 +118,6 @@ async fn sayout(params : ExecBodyParams) { None, ); - // // if botlock.botmgrs.chat.client.get_channel_status(trgchnl.to_string().clone()).await == (false,false) { - // if !botlock.bot_channels.contains(&Channel(trgchnl.to_lowercase().to_string().clone())) { - - // // in the case where the provided channel isn't something we're known to be connected to - // botlog::warn( - // &format!("A message attempted to send for a Non-Joined Channel : {}",trgchnl.to_string().clone()), - // Some("Chat > send_botmsg".to_string()), - // None, - // ); - // // return ; - - // if parent_module.clone().is_some() { - - - // botlock - // .botmgrs - // .chat - // .say_in_reply_to( - // ¶ms.msg, - // format!("Not a Joined Channel : {}",trgchnl), - // // parent_module.clone().unwrap().clone() - // params.clone(), - // ).await; - - // } - - - // } - /* 1. If a Reply , [ ] Get Parent Content message - reply_parent @@ -194,48 +138,26 @@ async fn sayout(params : ExecBodyParams) { let newoutmsg = if let Some(srcmsg) = reply_parent { - // format!("{} from #{} says {} . Replying to: {} : {}", - // msg.sender.name,msg.channel_login,outmsg, reply_parent_usr.unwrap(),srcmsg) - // format!("{} from #{} says {} @ {} {} : {}", - // msg.sender.name, - // msg.channel_login, - // outmsg, - // reply_parent_ts.unwrap(), - // reply_parent_usr.unwrap(), - // srcmsg) format!("{} {} @ {} : {}", reply_parent_ts.unwrap(), params.msg.sender.name, params.msg.channel_login, srcmsg) } else { - // format!("{} from #{} says : {}", - // msg.sender.name, - // msg.channel_login, - // outmsg) format!("in {} - {} : {}", params.msg.channel_login, params.msg.sender.name, outmsg) }; - - if parent_module.clone().is_some() { - - - // uses chat.say_in_reply_to() for the bot controls for messages - botlock - .botmgrs - .chat - .say( - trgchnl.to_string(), - newoutmsg.to_string(), - // parent_module.unwrap().clone() - params.clone(), - ).await; - - } - + botlock + .botmgrs + .chat + .say( + trgchnl.to_string(), + newoutmsg.to_string(), + params.clone(), + ).await; }, @@ -257,30 +179,13 @@ async fn sayout(params : ExecBodyParams) { .say_in_reply_to( ¶ms.msg, String::from("Invalid arguments"), - // parent_module.unwrap().clone() params.clone() ).await; - // if parent_module.is_some() { - - // // uses chat.say_in_reply_to() for the bot controls for messages - // botlock - // .botmgrs - // .chat - // .say_in_reply_to( - // ¶ms.msg, - // String::from("Invalid arguments"), - // // parent_module.unwrap().clone() - // params.clone() - // ).await; - - // } - }, } - Log::flush(); } \ No newline at end of file