From f2893791b9de1813b1e5d2e9ee7ea075f93d5c67 Mon Sep 17 00:00:00 2001 From: mzntori Date: Sat, 30 Mar 2024 01:42:06 +0100 Subject: [PATCH 1/2] 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/2] 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;