From 618c7284fdb8b89f7a64cd95da85178b832adca9 Mon Sep 17 00:00:00 2001
From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com>
Date: Wed, 31 Jan 2024 21:30:08 -0500
Subject: [PATCH] added identity > getroles

---
 src/core/botinstance.rs    |   8 ++
 src/core/identity.rs       | 159 +++++++++++++++++++++++++++++++++++--
 src/modules/experiments.rs |   2 +-
 3 files changed, 163 insertions(+), 6 deletions(-)

diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs
index 23f4a82..568d4e6 100644
--- a/src/core/botinstance.rs
+++ b/src/core/botinstance.rs
@@ -326,7 +326,15 @@ impl BotInstance
                                                         _cmdreqroles:Vec<UserRole>)
                         */
 
+                        // for v in msg.message_text.split(" ") {
+                        //     println!("args : {v}");
+                        // }
+
                         let inpt = msg.message_text.split("\n").next().expect("ERROR during BotCommand");
+                        let inpt = msg.message_text.split(" ").next().expect("ERROR during BotCommand");
+
+
+
 
                         // [x] Check if a bot command based on ...
                         //    [x] prefix + command
diff --git a/src/core/identity.rs b/src/core/identity.rs
index 3424e14..8eae489 100644
--- a/src/core/identity.rs
+++ b/src/core/identity.rs
@@ -32,11 +32,12 @@ pub fn init(mgr:&mut ModulesManager)
             ],
     }.add_to_modmgr(mgr);
 
-    async fn cmd_promote(mut _chat:botinstance::BotManagers,_msg:PrivmsgMessage) {
+    async fn cmd_promote(bot:botinstance::BotManagers,_msg:PrivmsgMessage) {
         //println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
         println!("Called cmd promote");
 
-        // -- If the BotCommand.command was called (e.g., promote), this is the current function body to execute
+        // -- If the BotCommand.command was called (e.g., promote) & required roles were validated OUTSIDE of this call
+        // , this is the current function body to execute
 
         /*
         - `promote` / `demote`
@@ -51,7 +52,18 @@ pub fn init(mgr:&mut ModulesManager)
          */
 
 
-        // [ ] Split message based on arguments
+        /*
+        Usage : 
+
+            promote <user> <channel>
+
+            demote <user> <channel>
+
+            promote admin <user>
+            
+         */
+
+
 
 
 
@@ -77,6 +89,95 @@ pub fn init(mgr:&mut ModulesManager)
     }
 
 
+
+    BotCommand {
+        module : BotModule(String::from("identity")),
+        command : String::from("getroles"), // command call name
+        alias : vec![], // String of alternative names
+        exec_body : actions_util::asyncbox(getroles) ,
+        help : String::from("getroles"),
+        required_roles : vec![
+            UserRole::Mod(ChType::Channel(String::new())),
+            UserRole::SupMod(ChType::Channel(String::new())),
+            UserRole::Broadcaster,
+            UserRole::BotAdmin,
+            ],
+    }.add_to_modmgr(mgr);
+
+
+    async fn getroles(bot:botinstance::BotManagers,msg:PrivmsgMessage) {
+        println!("Called cmd getroles");
+
+        /*
+        Usage
+
+        getroles <user> <Channel>
+        - If channel is provided, provide roles for that channel specifically 
+
+         */
+
+        // IN other code areas , I see this 
+        // ServerMessage::Privmsg(msg) => {
+        //     println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
+
+        println!("{}",msg.message_text);
+        let mut argv = msg.message_text.split(" ");
+
+        // for v in argv {
+        //     println!("args : {v}");
+        // }
+
+
+        let arg = argv.next(); // Skip the command name
+
+        let arg1 = argv.next();
+
+        // if arg == None {
+        //     return ; // Do nothing if no arguments
+        // }
+
+
+        let targetuser = match arg1 {
+            None => return , // exit if no arguments
+            Some(arg) => arg,
+        };
+
+        // match String::from(arg1) {
+        //     a if a == String::from("admin") => (),
+        //     _ => (),
+        // }
+
+
+        // match argv[1] {
+        //     String::from("admin") => (),
+
+        // }
+
+        let arg2 = argv.next();
+
+        let targetchnl = arg2; 
+
+        match targetchnl {
+            None => {
+                let a = bot.identity.getspecialuserroles(String::from(targetuser),None);
+                println!("Retrieved User Roles >> {:?}",a);
+            },
+            Some(targetchnl) => {
+                let a = bot.identity.getspecialuserroles(String::from(targetuser), Some(ChType::Channel(String::from(targetchnl))));
+                 println!("Retrieved User Roles >> {:?}",a);
+            }, 
+        }
+
+
+        // let a = bot.identity.getuserroles(String::from("ModulatingForce"), Some(ChType::Channel(String::from("ModulatingForcebot"))));
+        // println!("{:?}",a);
+
+    }
+
+
+    
+
+
 }
 
 
@@ -105,7 +206,7 @@ pub enum Permissible {
 pub struct IdentityManager {
     special_roles_users : HashMap<String,Vec<UserRole>>, // # <-- (!) This must be String instead of ChType because we're checking a User not a Channel
     // parent_mgr : Box<crate::core::botinstance::BotManagers>,
-    parent_mgr : Option<Box<crate::core::botinstance::BotManagers>>,
+    //parent_mgr : Option<Box<crate::core::botinstance::BotManagers>>,
 } 
 
 pub enum ChatBadge {
@@ -114,6 +215,13 @@ pub enum ChatBadge {
 }
 
 
+enum ChangeResult {
+    Success(String),
+    Failed(String),
+    NoChange(String),
+}
+
+
 impl IdentityManager {
 
     pub fn init() -> IdentityManager {
@@ -124,7 +232,7 @@ impl IdentityManager {
 
         IdentityManager {
             special_roles_users : a,
-            parent_mgr : None,
+            //parent_mgr : None,
         }
     }
 
@@ -327,4 +435,45 @@ impl IdentityManager {
 
             Permissible::Block
         }
+
+    pub fn promote(self,trgchatter:String,channel:ChType) -> ChangeResult {
+
+        ChangeResult::Success(String::from("Promotion Successful"))
+    } 
+
+    pub fn demote(self,trgchatter:String,channel:ChType) -> ChangeResult {
+
+        ChangeResult::Success(String::from("Promotion Successful"))
+    }
+
+    pub fn getspecialuserroles(&self,chattername:String,channel:Option<ChType>) -> Option<&Vec<UserRole>> {
+        
+        // let a = chattername.to_lowercase();
+
+        // self.special_roles_users.get(&a)
+
+
+
+        // for k in self.special_roles_users.keys() {
+        //     println!("Special Roles Keys {k}");
+        //     for v in
+        // }
+
+        // for (k,v) in &self.special_roles_users {
+        //     println!("User {k}");
+        //     println!("> Roles : {:?}",v);
+        // }
+
+        let a = chattername.to_lowercase();
+
+        // println!("{a}");
+
+        self.special_roles_users.get(&a)
+
+
+
+        // Some(vec![UserRole::Mod(ChType::Channel(String::from("modulatingforcebot")))])
+    }
+
+
 }
diff --git a/src/modules/experiments.rs b/src/modules/experiments.rs
index 86e2a38..0c3709b 100644
--- a/src/modules/experiments.rs
+++ b/src/modules/experiments.rs
@@ -71,7 +71,7 @@ pub fn init(mgr:&mut ModulesManager)
 
 async fn good_girl(mut bot:botinstance::BotManagers,msg:PrivmsgMessage)
 {
-    println!("In GoodGirl()");
+    println!("In GoodGirl() Listener");
     //println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
 
     // [ ] Uses gen_ratio() to output bool based on a ratio probability .