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] 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; }