From f2893791b9de1813b1e5d2e9ee7ea075f93d5c67 Mon Sep 17 00:00:00 2001 From: mzntori Date: Sat, 30 Mar 2024 01:42:06 +0100 Subject: [PATCH 1/8] add reply parent functionality --- src/core/bot_actions.rs | 58 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index 8941654..cf7557f 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -57,9 +57,67 @@ impl ExecBodyParams { requestor_badge_mut } + /// Returns some information about the message that was replied to by the `PrivmsgMessage` contained + /// in the `msg` field of this struct. + /// + /// If that message replied to message return that information in form of `Some`. + /// Otherwise, return `None`. + pub fn get_parent_reply(&self) -> Option { + let map = &self.msg.source.tags.0; + let tags = [ + "reply-parent-user-id", + "reply-parent-user-login", + "reply-parent-display-name", + "reply-parent-msg-id", + "reply-parent-msg-body" + ]; + // filter out all tags that do not have content. + let tag_contents: Vec = tags.iter().filter_map(|tag| { + if let Some(&Some(ref t)) = map.get(*tag) { + Some(t.clone()) + } else { + None + } + }).collect(); + + // if no tags got filtered out return the struct. + // else return `None`. + return if tag_contents.len() == 5 { + Some(ReplyParent { + sender: TwitchUserBasics { + id: tag_contents[0].clone(), + login: tag_contents[1].clone(), + name: tag_contents[2].clone(), + }, + message_id: tag_contents[3].clone(), + message_text: tag_contents[4].clone(), + channel_login: self.msg.channel_login.clone(), + channel_id: self.msg.channel_id.clone(), + }) + } else { + None + } + } } +/// Represents the message a `PrivmsgMessage` replies to. +/// Similar to a less detailed `PrivmsgMessage`. +/// +/// This should not be constructed manually but only from calling `get_parent_reply()` on +/// `ExecBodyParams`. +/// +/// Fields that will be the same as the `PrivmsgMessage` this was generated from: +/// - `channel_login` +/// - `channel_id` +#[derive(Debug, Clone, PartialEq)] +pub struct ReplyParent { + pub sender: TwitchUserBasics, + pub message_id: String, + pub message_text: String, + pub channel_login: String, + pub channel_id: String, +} pub mod actions_util { From a048003e93e7f1175ea38341439e4cec7ae7f8b3 Mon Sep 17 00:00:00 2001 From: mzntori Date: Sat, 30 Mar 2024 01:47:32 +0100 Subject: [PATCH 2/8] oops forgot to add the use statement --- src/core/bot_actions.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index cf7557f..f5c8a66 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -1,5 +1,4 @@ - -use twitch_irc::message::PrivmsgMessage; +use twitch_irc::message::{PrivmsgMessage, TwitchUserBasics}; use std::sync::Arc; use tokio::sync::RwLock; From 345cf97922b3cf7729f1501bd04dabc9b4869d4a Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Wed, 3 Apr 2024 13:47:59 -0400 Subject: [PATCH 3/8] enh chat.say_in_reply --- src/core/chat.rs | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/src/core/chat.rs b/src/core/chat.rs index bb938cc..a3db701 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use tokio::sync::Mutex; use twitch_irc::login::StaticLoginCredentials; -use twitch_irc::message::PrivmsgMessage; +use twitch_irc::message::{PrivmsgMessage, ReplyToMessage}; use twitch_irc::transport::tcp::{TCPTransport, TLS}; use twitch_irc::TwitchIRCClient; @@ -34,9 +34,14 @@ pub struct Chat { } -#[derive(Clone,Debug)] -pub enum BotMsgType<'a> { - SayInReplyTo(&'a PrivmsgMessage,String), +// #[derive(Clone,Debug)] // <-- [ ] 04.03 - was having issues using this +#[derive(Clone)] +// pub enum BotMsgType<'a> { +pub enum BotMsgType { + // SayInReplyTo(&'a PrivmsgMessage,String), + // SayInReplyTo(Arc>,String), + // SayInReplyTo(&'a dyn ReplyToMessage,String), // [ ] 04.03 - Having issues defining it this way? + SayInReplyTo((String,String),String), // ( Destination Channel , Message ID to reply to ) , OutMessage // https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say_in_reply_to Say(String,String), Notif(String), // For Bot Sent Notifications } @@ -59,7 +64,8 @@ impl Chat { } #[async_recursion] - pub async fn send_botmsg(&self, msginput: BotMsgType<'async_recursion>, params : ExecBodyParams) { + // pub async fn send_botmsg(&self, msginput: BotMsgType<'async_recursion>, params : ExecBodyParams) { + pub async fn send_botmsg(&self, msginput: BotMsgType, params : ExecBodyParams) { @@ -72,17 +78,21 @@ impl Chat { */ - - botlog::trace( + /* // [ ] 04.03 - Was having issues withh this + botlog::trace( format!("send_bot_msg params : {:?}",msginput).as_str(), Some("chat.rs > send_botmsg ".to_string()), Some(¶ms.msg), ); Log::flush(); + */ let (channel_login,mut outmsg) = match msginput.clone() { BotMsgType::SayInReplyTo(msg, outmsg) => { - (msg.channel_login.clone(),outmsg) + // (msg.channel_login.clone(),outmsg) + // (msg.clone().channel_login().to_string(),outmsg) + (msg.0, // Desintation Channel + outmsg) }, BotMsgType::Say(a,b ) => { (a.clone(),b.clone()) @@ -340,7 +350,12 @@ impl Chat { match msginput.clone() { BotMsgType::SayInReplyTo(msg, _) => { - self.client.say_in_reply_to(msg, outmsg).await.unwrap(); + + dbg!(msg.clone().channel_login(),msg.message_id(),outmsg.clone()); + self.client.say_in_reply_to(&( + msg.clone().channel_login().to_string(), + msg.message_id().to_string()), + outmsg).await.unwrap(); }, BotMsgType::Say(a, _) => { self.client.say(a, outmsg).await.unwrap(); @@ -357,11 +372,12 @@ impl Chat { channel_login.clone(), "rate limit counter increase", contextratelimiter ); - if let BotMsgType::SayInReplyTo(msg,_ ) = msginput { + if let BotMsgType::SayInReplyTo(_,_ ) = msginput { botlog::trace( logstr.as_str(), Some("Chat > send_botmsg".to_string()), - Some(msg), + // Some(msg), + None, ); } else { botlog::trace( @@ -390,7 +406,9 @@ 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) { + // pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) { + // pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) { + pub async fn say_in_reply_to(&self, msg: &impl ReplyToMessage, outmsg: String , params : ExecBodyParams) { // let params_clone = params.clone(); @@ -443,7 +461,10 @@ impl Chat { // Log::flush(); - self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg) , params).await; + self.send_botmsg(BotMsgType::SayInReplyTo( + (msg.channel_login().to_string(), + msg.message_id().to_string()), + outmsg) , params).await; } From 71997037667362d3bcde0810f0138e607893d1ae Mon Sep 17 00:00:00 2001 From: haruyuumei Date: Wed, 3 Apr 2024 15:26:04 -0300 Subject: [PATCH 4/8] reply-to-parent working --- src/custom/experimental/experiment001.rs | 57 ++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/custom/experimental/experiment001.rs b/src/custom/experimental/experiment001.rs index dd3cba4..65bae8b 100644 --- a/src/custom/experimental/experiment001.rs +++ b/src/custom/experimental/experiment001.rs @@ -95,8 +95,65 @@ pub async fn init(mgr: Arc) { // 2. Add the BotAction to ModulesManager botc1.add_to_modmgr(Arc::clone(&mgr)).await; + let bc1 = BotCommand { + module: BotModule(String::from("experiments001")), + command: String::from("rp1"), // command call name + alias: vec![ + String::from("rp2"), + String::from("rp3")], // String of alternative names + exec_body: actions_util::asyncbox(rp), + help: String::from("Test Command tester"), + required_roles: vec![ + BotAdmin, + Mod(OF_CMD_CHANNEL), + ], + }; + bc1.add_core_to_modmgr(Arc::clone(&mgr)).await; } +async fn rp(params : ExecBodyParams) +{ + //triggers if the message is a reply + if params.get_parent_reply().is_some(){ + + //getting the channel id where the message was sent + let channel_id = params.get_parent_reply().unwrap().channel_login; + + //getting the first message id that was sent + let message_id = params.get_parent_reply().unwrap().message_id; + + //just for testing purposes + //print!("{} , {}",channel_id, message_id); + + //creating a tuple with the channel id and message id + let answear = + ( + channel_id.clone(), + message_id.clone() + ); + + 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( + //using the tuple as param to the message being replied + &answear, + String::from("hey there"), + params.clone() + ).await; + } + + else + { + println!("no reply") + } +} + + + async fn good_girl(params : ExecBodyParams) { // [ ] Uses gen_ratio() to output bool based on a ratio probability . From 6867cc7af8aee0d82baa24f1302a29005f92546a Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Wed, 3 Apr 2024 18:33:15 -0400 Subject: [PATCH 5/8] adj sayinreply to use channel & msgid --- src/core/chat.rs | 52 +++++++++++++++++------- src/custom/experimental/experiment001.rs | 16 +++++--- src/custom/experimental/experiment002.rs | 4 +- 3 files changed, 51 insertions(+), 21 deletions(-) diff --git a/src/core/chat.rs b/src/core/chat.rs index a3db701..003c617 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -41,7 +41,8 @@ pub enum BotMsgType { // SayInReplyTo(&'a PrivmsgMessage,String), // SayInReplyTo(Arc>,String), // SayInReplyTo(&'a dyn ReplyToMessage,String), // [ ] 04.03 - Having issues defining it this way? - SayInReplyTo((String,String),String), // ( Destination Channel , Message ID to reply to ) , OutMessage // https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say_in_reply_to + // SayInReplyTo((String,String),String), // ( Destination Channel , Message ID to reply to ) , OutMessage // https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say_in_reply_to + SayInReplyTo(Channel,String,String), // ( Destination Channel , Message ID to reply to , OutMessage ) // https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say_in_reply_to Say(String,String), Notif(String), // For Bot Sent Notifications } @@ -88,10 +89,11 @@ impl Chat { */ let (channel_login,mut outmsg) = match msginput.clone() { - BotMsgType::SayInReplyTo(msg, outmsg) => { + // BotMsgType::SayInReplyTo(msg, outmsg) => { + BotMsgType::SayInReplyTo(chnl, _, outmsg) => { // (msg.channel_login.clone(),outmsg) // (msg.clone().channel_login().to_string(),outmsg) - (msg.0, // Desintation Channel + (chnl.0.to_lowercase(), // Desintation Channel outmsg) }, BotMsgType::Say(a,b ) => { @@ -123,13 +125,16 @@ impl Chat { ).await; if !params.bot.read().await.bot_channels.contains(&Channel(channel_login.clone())) { + + dbg!("ISSUE : NONJOINED CHANNEL",¶ms.bot.read().await.bot_channels,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, ); - if let BotMsgType::SayInReplyTo(_prvmsg,_outmsg) = msginput { + // if let BotMsgType::SayInReplyTo(_prvmsg,_outmsg) = msginput { + if let BotMsgType::SayInReplyTo(_chnl,_msgid, _outmsg) = msginput { self.send_botmsg(BotMsgType::Notif( "uuh Bot can't send to a channel it isn't joined".to_string(), @@ -177,7 +182,8 @@ impl Chat { match msginput { BotMsgType::Notif(_) => (), // Do nothing with Notif > We'll validate the user later to handle - BotMsgType::SayInReplyTo(_, _) | BotMsgType::Say(_,_) => { + // BotMsgType::SayInReplyTo(_, _) | BotMsgType::Say(_,_) => { + BotMsgType::SayInReplyTo(_, _, _) | BotMsgType::Say(_,_) => { botlog::trace( "BEFORE potential Async recursion", @@ -276,7 +282,8 @@ impl Chat { return; } }, - BotMsgType::SayInReplyTo(_,_ ) | BotMsgType::Say(_,_) => { + // BotMsgType::SayInReplyTo(_,_ ) | BotMsgType::Say(_,_) => { + 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( @@ -349,18 +356,25 @@ impl Chat { } match msginput.clone() { - BotMsgType::SayInReplyTo(msg, _) => { + // BotMsgType::SayInReplyTo(msg, _) => { + // BotMsgType::SayInReplyTo(msg, _, _) => { + BotMsgType::SayInReplyTo(chnl,msgid, _) => { + + // dbg!(msg.clone().channel_login(),msg.message_id(),outmsg.clone()); + dbg!(chnl.clone(),msgid.clone(),outmsg.clone()); - dbg!(msg.clone().channel_login(),msg.message_id(),outmsg.clone()); self.client.say_in_reply_to(&( - msg.clone().channel_login().to_string(), - msg.message_id().to_string()), + chnl.0, + msgid), outmsg).await.unwrap(); }, BotMsgType::Say(a, _) => { self.client.say(a, outmsg).await.unwrap(); } BotMsgType::Notif(outmsg) => { + + // dbg!(chnl.clone(),msgid.clone(),outmsg.clone()); + dbg!(params.msg.channel_login(),params.msg.message_id()); self.client.say_in_reply_to(¶ms.msg, outmsg).await.unwrap(); } } @@ -372,7 +386,8 @@ impl Chat { channel_login.clone(), "rate limit counter increase", contextratelimiter ); - if let BotMsgType::SayInReplyTo(_,_ ) = msginput { + // if let BotMsgType::SayInReplyTo(_,_ ) = msginput { + if let BotMsgType::SayInReplyTo(_,_,_ ) = msginput { botlog::trace( logstr.as_str(), Some("Chat > send_botmsg".to_string()), @@ -408,7 +423,14 @@ impl Chat { // #[async_recursion] // pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) { // pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) { - pub async fn say_in_reply_to(&self, msg: &impl ReplyToMessage, outmsg: String , params : ExecBodyParams) { + // pub async fn say_in_reply_to(&self, msg: &impl ReplyToMessage, outmsg: String , params : ExecBodyParams) { + pub async fn say_in_reply_to( + &self, + destination_channel : Channel , + reply_message_id : String , + outmsg: String , + params : ExecBodyParams) + { // let params_clone = params.clone(); @@ -462,9 +484,9 @@ impl Chat { self.send_botmsg(BotMsgType::SayInReplyTo( - (msg.channel_login().to_string(), - msg.message_id().to_string()), - outmsg) , params).await; + destination_channel, + reply_message_id, + outmsg) , params).await; } diff --git a/src/custom/experimental/experiment001.rs b/src/custom/experimental/experiment001.rs index 65bae8b..e774055 100644 --- a/src/custom/experimental/experiment001.rs +++ b/src/custom/experimental/experiment001.rs @@ -15,6 +15,7 @@ const OF_CMD_CHANNEL:Channel = Channel(String::new()); use rand::Rng; +use twitch_irc::message::ReplyToMessage; use std::sync::Arc; use crate::core::bot_actions::ExecBodyParams; @@ -140,7 +141,8 @@ async fn rp(params : ExecBodyParams) .chat .say_in_reply_to( //using the tuple as param to the message being replied - &answear, + Channel(answear.0), + answear.1, String::from("hey there"), params.clone() ).await; @@ -188,7 +190,8 @@ async fn good_girl(params : ExecBodyParams) { .botmgrs .chat .say_in_reply_to( - ¶ms.msg, + Channel(params.clone().msg.channel_login().to_string()), + params.clone().msg.message_id().to_string(), String::from("GoodGirl xdd "), params.clone() ).await; @@ -228,7 +231,8 @@ async fn babygirl(params : ExecBodyParams) { .botmgrs .chat .say_in_reply_to( - ¶ms.msg, + Channel(params.clone().msg.channel_login().to_string()), + params.clone().msg.message_id().to_string(), String::from("16:13 notohh: cafdk"), params.clone() ).await; @@ -240,7 +244,8 @@ async fn babygirl(params : ExecBodyParams) { .botmgrs .chat .say_in_reply_to( - ¶ms.msg, + Channel(params.clone().msg.channel_login().to_string()), + params.clone().msg.message_id().to_string(), String::from("16:13 notohh: have fun eating princess"), params.clone() ).await; @@ -252,7 +257,8 @@ async fn babygirl(params : ExecBodyParams) { .botmgrs .chat .say_in_reply_to( - ¶ms.msg, + Channel(params.clone().msg.channel_login().to_string()), + params.clone().msg.message_id().to_string(), String::from("16:13 notohh: baby girl"), params.clone() ).await; diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs index a4ecb25..a7d1610 100644 --- a/src/custom/experimental/experiment002.rs +++ b/src/custom/experimental/experiment002.rs @@ -17,6 +17,7 @@ const OF_CMD_CHANNEL:Channel = Channel(String::new()); use std::sync::Arc; use chrono::{TimeZone,Local}; +use twitch_irc::message::ReplyToMessage; use crate::core::bot_actions::ExecBodyParams; @@ -180,7 +181,8 @@ async fn sayout(params : ExecBodyParams) { .botmgrs .chat .say_in_reply_to( - ¶ms.msg, + Channel(params.clone().msg.channel_login().to_string()), + params.clone().msg.message_id().to_string(), String::from("Invalid arguments"), params.clone() ).await; From 62b6399e69eb8cc6aba21d759d50f85ed4974ca3 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Wed, 3 Apr 2024 19:04:21 -0400 Subject: [PATCH 6/8] chat.say_in_reply --- src/core/chat.rs | 22 ++++++++++++++++++++++ src/custom/experimental/experiment001.rs | 20 ++++++++++++++------ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/core/chat.rs b/src/core/chat.rs index 003c617..82bc3f6 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -418,6 +418,21 @@ impl Chat { } + pub async fn say_in_reply( + &self, + destination_channel : Channel , + outmsg: String , + params : ExecBodyParams) + { + + self.send_botmsg(BotMsgType::SayInReplyTo( + destination_channel, + params.msg.message_id().to_string(), + outmsg) , params).await; + + + } + // pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String) { // #[async_recursion] @@ -490,6 +505,9 @@ impl Chat { } + + + // pub async fn say(&self, channel_login: String, message: String) { 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 @@ -497,6 +515,10 @@ impl Chat { self.send_botmsg(BotMsgType::Say(channel_login.to_lowercase(), message), params).await; } + + + + async fn _me(&self, _: String, _: String) { // more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say diff --git a/src/custom/experimental/experiment001.rs b/src/custom/experimental/experiment001.rs index e774055..cb75ad2 100644 --- a/src/custom/experimental/experiment001.rs +++ b/src/custom/experimental/experiment001.rs @@ -230,9 +230,8 @@ async fn babygirl(params : ExecBodyParams) { botlock .botmgrs .chat - .say_in_reply_to( + .say_in_reply( Channel(params.clone().msg.channel_login().to_string()), - params.clone().msg.message_id().to_string(), String::from("16:13 notohh: cafdk"), params.clone() ).await; @@ -243,9 +242,8 @@ async fn babygirl(params : ExecBodyParams) { botlock .botmgrs .chat - .say_in_reply_to( + .say_in_reply( Channel(params.clone().msg.channel_login().to_string()), - params.clone().msg.message_id().to_string(), String::from("16:13 notohh: have fun eating princess"), params.clone() ).await; @@ -253,12 +251,22 @@ async fn babygirl(params : ExecBodyParams) { sleep(Duration::from_secs_f64(2.0)).await; + // botlock + // .botmgrs + // .chat + // .say_in_reply_to( + // Channel(params.clone().msg.channel_login().to_string()), + // params.clone().msg.message_id().to_string(), + // String::from("16:13 notohh: baby girl"), + // params.clone() + // ).await; + + botlock .botmgrs .chat - .say_in_reply_to( + .say_in_reply( Channel(params.clone().msg.channel_login().to_string()), - params.clone().msg.message_id().to_string(), String::from("16:13 notohh: baby girl"), params.clone() ).await; From 8adab21761cd3c9bc6837518006140fbcc82f4f4 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Wed, 3 Apr 2024 19:40:18 -0400 Subject: [PATCH 7/8] comments cleanup --- src/core/botlog.rs | 21 ++---- src/core/botmodules.rs | 1 - src/core/chat.rs | 85 +----------------------- src/core/identity.rs | 4 -- src/custom/experimental/experiment001.rs | 11 --- 5 files changed, 10 insertions(+), 112 deletions(-) diff --git a/src/core/botlog.rs b/src/core/botlog.rs index 27272d2..48ae783 100644 --- a/src/core/botlog.rs +++ b/src/core/botlog.rs @@ -24,11 +24,10 @@ debug = "Checking bot actions", pub fn trace(in_msg: &str, in_module: Option, in_prvmsg: Option<&PrivmsgMessage>) { let (chnl, chatter) = match in_prvmsg { Some(prvmsg) => { - //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text)); ( Some(prvmsg.channel_login.clone()), Some(prvmsg.sender.name.clone()), - ) // <-- Clone fine atm while we're just working with Strings + ) } None => (None, None), }; @@ -45,11 +44,10 @@ pub fn trace(in_msg: &str, in_module: Option, in_prvmsg: Option<&Privmsg pub fn debug(in_msg: &str, in_module: Option, in_prvmsg: Option<&PrivmsgMessage>) { let (chnl, chatter) = match in_prvmsg { Some(prvmsg) => { - //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text)); ( Some(prvmsg.channel_login.clone()), Some(prvmsg.sender.name.clone()), - ) // <-- Clone fine atm while we're just working with Strings + ) } None => (None, None), }; @@ -66,11 +64,10 @@ pub fn debug(in_msg: &str, in_module: Option, in_prvmsg: Option<&Privmsg pub fn info(in_msg: &str, in_module: Option, in_prvmsg: Option<&PrivmsgMessage>) { let (chnl, chatter) = match in_prvmsg { Some(prvmsg) => { - //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text)); ( Some(prvmsg.channel_login.clone()), Some(prvmsg.sender.name.clone()), - ) // <-- Clone fine atm while we're just working with Strings + ) } None => (None, None), }; @@ -87,11 +84,10 @@ pub fn info(in_msg: &str, in_module: Option, in_prvmsg: Option<&PrivmsgM pub fn notice(in_msg: &str, in_module: Option, in_prvmsg: Option<&PrivmsgMessage>) { let (chnl, chatter) = match in_prvmsg { Some(prvmsg) => { - //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text)); ( Some(prvmsg.channel_login.clone()), Some(prvmsg.sender.name.clone()), - ) // <-- Clone fine atm while we're just working with Strings + ) } None => (None, None), }; @@ -108,11 +104,10 @@ pub fn notice(in_msg: &str, in_module: Option, in_prvmsg: Option<&Privms pub fn warn(in_msg: &str, in_module: Option, in_prvmsg: Option<&PrivmsgMessage>) { let (chnl, chatter) = match in_prvmsg { Some(prvmsg) => { - //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text)); ( Some(prvmsg.channel_login.clone()), Some(prvmsg.sender.name.clone()), - ) // <-- Clone fine atm while we're just working with Strings + ) } None => (None, None), }; @@ -129,11 +124,10 @@ pub fn warn(in_msg: &str, in_module: Option, in_prvmsg: Option<&PrivmsgM pub fn error(in_msg: &str, in_module: Option, in_prvmsg: Option<&PrivmsgMessage>) { let (chnl, chatter) = match in_prvmsg { Some(prvmsg) => { - //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text)); ( Some(prvmsg.channel_login.clone()), Some(prvmsg.sender.name.clone()), - ) // <-- Clone fine atm while we're just working with Strings + ) } None => (None, None), }; @@ -154,11 +148,10 @@ pub fn fatal<'a>( ) -> &'a str { let (chnl, chatter) = match in_prvmsg { Some(prvmsg) => { - //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text)); ( Some(prvmsg.channel_login.clone()), Some(prvmsg.sender.name.clone()), - ) // <-- Clone fine atm while we're just working with Strings + ) } None => (None, None), }; diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index c104fdd..408b2d5 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -253,7 +253,6 @@ 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(params : ExecBodyParams) { /* There should be additional validation checks diff --git a/src/core/chat.rs b/src/core/chat.rs index 82bc3f6..3ed28ce 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -34,14 +34,8 @@ pub struct Chat { } -// #[derive(Clone,Debug)] // <-- [ ] 04.03 - was having issues using this -#[derive(Clone)] -// pub enum BotMsgType<'a> { +#[derive(Clone,Debug)] pub enum BotMsgType { - // SayInReplyTo(&'a PrivmsgMessage,String), - // SayInReplyTo(Arc>,String), - // SayInReplyTo(&'a dyn ReplyToMessage,String), // [ ] 04.03 - Having issues defining it this way? - // SayInReplyTo((String,String),String), // ( Destination Channel , Message ID to reply to ) , OutMessage // https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say_in_reply_to SayInReplyTo(Channel,String,String), // ( Destination Channel , Message ID to reply to , OutMessage ) // https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say_in_reply_to Say(String,String), Notif(String), // For Bot Sent Notifications @@ -65,7 +59,6 @@ impl Chat { } #[async_recursion] - // pub async fn send_botmsg(&self, msginput: BotMsgType<'async_recursion>, params : ExecBodyParams) { pub async fn send_botmsg(&self, msginput: BotMsgType, params : ExecBodyParams) { @@ -79,20 +72,16 @@ impl Chat { */ - /* // [ ] 04.03 - Was having issues withh this botlog::trace( format!("send_bot_msg params : {:?}",msginput).as_str(), Some("chat.rs > send_botmsg ".to_string()), Some(¶ms.msg), ); Log::flush(); - */ + let (channel_login,mut outmsg) = match msginput.clone() { - // BotMsgType::SayInReplyTo(msg, outmsg) => { BotMsgType::SayInReplyTo(chnl, _, outmsg) => { - // (msg.channel_login.clone(),outmsg) - // (msg.clone().channel_login().to_string(),outmsg) (chnl.0.to_lowercase(), // Desintation Channel outmsg) }, @@ -133,7 +122,6 @@ impl Chat { None, ); - // if let BotMsgType::SayInReplyTo(_prvmsg,_outmsg) = msginput { if let BotMsgType::SayInReplyTo(_chnl,_msgid, _outmsg) = msginput { self.send_botmsg(BotMsgType::Notif( @@ -182,7 +170,6 @@ impl Chat { match msginput { BotMsgType::Notif(_) => (), // Do nothing with Notif > We'll validate the user later to handle - // BotMsgType::SayInReplyTo(_, _) | BotMsgType::Say(_,_) => { BotMsgType::SayInReplyTo(_, _, _) | BotMsgType::Say(_,_) => { botlog::trace( @@ -248,7 +235,7 @@ impl Chat { let botlock = botclone.read().await; let id = botlock.get_identity(); let id = Arc::clone(&id); - let idlock = id.read().await; // <-- [x] 03.24 - seems to work + let idlock = id.read().await; let user_roles = idlock.getspecialuserroles( params.get_sender(), Some(Channel(channel_login.clone())) @@ -282,7 +269,6 @@ impl Chat { return; } }, - // BotMsgType::SayInReplyTo(_,_ ) | BotMsgType::Say(_,_) => { 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 @@ -337,7 +323,6 @@ impl Chat { ); let contextratelimiter = rllock - // .get_mut() .get_mut(&Channel(channel_login.to_lowercase().clone())) .expect("ERROR: Issue with Rate limiters"); @@ -356,11 +341,8 @@ impl Chat { } match msginput.clone() { - // BotMsgType::SayInReplyTo(msg, _) => { - // BotMsgType::SayInReplyTo(msg, _, _) => { BotMsgType::SayInReplyTo(chnl,msgid, _) => { - // dbg!(msg.clone().channel_login(),msg.message_id(),outmsg.clone()); dbg!(chnl.clone(),msgid.clone(),outmsg.clone()); self.client.say_in_reply_to(&( @@ -373,7 +355,6 @@ impl Chat { } BotMsgType::Notif(outmsg) => { - // dbg!(chnl.clone(),msgid.clone(),outmsg.clone()); dbg!(params.msg.channel_login(),params.msg.message_id()); self.client.say_in_reply_to(¶ms.msg, outmsg).await.unwrap(); } @@ -386,12 +367,10 @@ impl Chat { channel_login.clone(), "rate limit counter increase", contextratelimiter ); - // if let BotMsgType::SayInReplyTo(_,_ ) = msginput { if let BotMsgType::SayInReplyTo(_,_,_ ) = msginput { botlog::trace( logstr.as_str(), Some("Chat > send_botmsg".to_string()), - // Some(msg), None, ); } else { @@ -433,12 +412,6 @@ 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) { - // pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) { - // pub async fn say_in_reply_to(&self, msg: &impl ReplyToMessage, outmsg: String , params : ExecBodyParams) { pub async fn say_in_reply_to( &self, destination_channel : Channel , @@ -447,57 +420,6 @@ impl Chat { params : ExecBodyParams) { - // 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 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(); - - - - // // 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( destination_channel, reply_message_id, @@ -508,7 +430,6 @@ impl Chat { - // pub async fn say(&self, channel_login: String, message: String) { 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 diff --git a/src/core/identity.rs b/src/core/identity.rs index dc2da72..726bbdf 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -23,13 +23,10 @@ use std::env; fn adminvector() -> Vec { vec![String::from("ModulatingForce")] - //vec![] } pub fn otherbots_vector() -> Vec { - // vec![String::from("ModulatingForce")] - // //vec![] dotenv().ok(); let mut other_bots = Vec::new(); @@ -1467,7 +1464,6 @@ impl IdentityManager { return ChangeResult::NoChange("Already does not have VIP role".to_string()); } else { - // self.affirm_chatter_in_db(trgchatter.clone()).await; self.remove_role(trgchatter.clone(), UserRole::VIP(channel.clone())).await; diff --git a/src/custom/experimental/experiment001.rs b/src/custom/experimental/experiment001.rs index cb75ad2..897384d 100644 --- a/src/custom/experimental/experiment001.rs +++ b/src/custom/experimental/experiment001.rs @@ -251,17 +251,6 @@ async fn babygirl(params : ExecBodyParams) { sleep(Duration::from_secs_f64(2.0)).await; - // botlock - // .botmgrs - // .chat - // .say_in_reply_to( - // Channel(params.clone().msg.channel_login().to_string()), - // params.clone().msg.message_id().to_string(), - // String::from("16:13 notohh: baby girl"), - // params.clone() - // ).await; - - botlock .botmgrs .chat From fde96ac8956d35c884f51afb01140a3faeb92b80 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Wed, 3 Apr 2024 19:45:18 -0400 Subject: [PATCH 8/8] clippy cleanup --- src/core/bot_actions.rs | 5 +++-- src/core/chat.rs | 2 +- src/custom/experimental/experiment001.rs | 1 - 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index f5c8a66..7ab34a0 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -73,7 +73,8 @@ impl ExecBodyParams { // filter out all tags that do not have content. let tag_contents: Vec = tags.iter().filter_map(|tag| { - if let Some(&Some(ref t)) = map.get(*tag) { + // if let Some(&Some(ref t)) = map.get(*tag) { + if let Some(Some(t)) = map.get(*tag) { Some(t.clone()) } else { None @@ -82,7 +83,7 @@ impl ExecBodyParams { // if no tags got filtered out return the struct. // else return `None`. - return if tag_contents.len() == 5 { + if tag_contents.len() == 5 { Some(ReplyParent { sender: TwitchUserBasics { id: tag_contents[0].clone(), diff --git a/src/core/chat.rs b/src/core/chat.rs index 3ed28ce..43984bc 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use tokio::sync::Mutex; use twitch_irc::login::StaticLoginCredentials; -use twitch_irc::message::{PrivmsgMessage, ReplyToMessage}; +use twitch_irc::message::ReplyToMessage; use twitch_irc::transport::tcp::{TCPTransport, TLS}; use twitch_irc::TwitchIRCClient; diff --git a/src/custom/experimental/experiment001.rs b/src/custom/experimental/experiment001.rs index 897384d..18d7aaa 100644 --- a/src/custom/experimental/experiment001.rs +++ b/src/custom/experimental/experiment001.rs @@ -147,7 +147,6 @@ async fn rp(params : ExecBodyParams) params.clone() ).await; } - else { println!("no reply")