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] 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(&params.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(&params.clone().msg),
-                );
+                    Some(&params.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(&params.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(&params.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();