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