From 16575245b026ba1b1dd936b69dc8ace9e62c2499 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Wed, 31 Jan 2024 09:31:14 -0500 Subject: [PATCH] 2024.01.31 - Latest Borrow Compile Err --- src/core/botinstance.rs | 15 ++++++++++----- src/core/identity.rs | 22 ++++++++++++++++------ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 5e94c56..850d262 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -154,6 +154,9 @@ impl BotManagers { identity : IdentityManager::init(), chat : Chat::init(ratelimiters,client), } + + + } } @@ -249,7 +252,7 @@ impl BotInstance let join_handle = tokio::spawn(async move { - while let Some(message) = self.incoming_messages.recv().await { + while let Some(message) = &self.incoming_messages.recv().await { // Below can be used to debug if I want to capture all messages // println!("Received message: {:?}", message); @@ -258,7 +261,7 @@ impl BotInstance // if let Some(chnl) = msg.channel_login { // println!("NOTICE : (#{}) {}", chnl, msg.message_text); // } - match msg.channel_login { + match &msg.channel_login { Some(chnl) => println!("NOTICE : (#{}) {}", chnl, msg.message_text), None => println!("NOTICE : {}", msg.message_text), } @@ -269,7 +272,7 @@ impl BotInstance println!("Privmsg section"); // b.listener_main_prvmsg(&msg); - self.listener_main_prvmsg(msg).await; + self.listener_main_prvmsg(&msg).await; // - BotCommand listener should likely need to be called within the above @@ -301,7 +304,7 @@ impl BotInstance // async fn listener_main_prvmsg(&mut self,msg:PrivmsgMessage) -> () { - async fn listener_main_prvmsg(&self,msg:PrivmsgMessage) -> () { + async fn listener_main_prvmsg(self,msg:&PrivmsgMessage) -> () { // println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); @@ -351,7 +354,9 @@ impl BotInstance // _ => (), // } - match self.botmgrs.identity.to_owned().can_user_run_PRVMSG(&msg, c.required_roles.clone()) { + // match self.botmgrs.identity.to_owned().can_user_run_PRVMSG(&msg, c.required_roles.clone()) { + // match self.botmgrs.identity.can_user_run_PRVMSG(&msg, c.required_roles.clone()) { + match self.botmgrs.identity.can_user_run_PRVMSG(&msg, c.required_roles.clone()) { // Ok(Permissible::Allow) => (), Permissible::Allow => { println!("Executed as permissible"); diff --git a/src/core/identity.rs b/src/core/identity.rs index f7aed5d..d1278b1 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -101,9 +101,11 @@ pub enum Permissible { Block } -#[derive(Clone)] +//#[derive(Clone)] pub struct IdentityManager { special_roles_users : HashMap>, // # <-- (!) This must be String instead of ChType because we're checking a User not a Channel + // parent_mgr : Box, + parent_mgr : Option>, } pub enum ChatBadge { @@ -122,13 +124,14 @@ impl IdentityManager { IdentityManager { special_roles_users : a, + parent_mgr : None, } } // [ ] Maybe I should create a can_user_run version that simply takes PrvMsg, but then calls can_user_run directly // pub fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec) -> Result> - pub fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec) -> Permissible + pub fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec) -> &Permissible { // println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); @@ -149,7 +152,7 @@ impl IdentityManager { // } if let Some(sender_badge) = sender_badge { - return self.can_user_run(msg.sender.name.to_owned(), + return &self.can_user_run(msg.sender.name.to_owned(), ChType::Channel(msg.channel_login.to_owned()), sender_badge, cmdreqroles @@ -159,7 +162,7 @@ impl IdentityManager { // [ ] Call can_user_run() - Permissible::Block + &Permissible::Block } pub fn can_user_run(mut self, @@ -241,7 +244,8 @@ impl IdentityManager { // println!("debug usr : {}",&usr.to_lowercase()); // let Some((k,v)) = self.special_roles_users.get_key_value(usr); - match self.special_roles_users.get_mut(&usr.to_lowercase()) { + // match self.special_roles_users.get_mut(&usr.to_lowercase()) { + match self.special_roles_users.get(&usr.to_lowercase()) { Some(usrroles) => { // println!("contains mod : {}", usrroles.contains(&UserRole::Mod(channelname.clone()))); // println!("contains supmod : {}", usrroles.contains(&UserRole::SupMod(channelname.clone()))); @@ -250,7 +254,13 @@ impl IdentityManager { // Do nothing - this is expected } else { // in this case, they have a ChatBadge::Mod but should have this for the channel - usrroles.push(UserRole::Mod(channelname.clone())); + // let mut a = usrroles; + // usrroles.push(UserRole::Mod(channelname.clone())); + // a.push(UserRole::Mod(channelname.clone())); + self.special_roles_users + .get_mut(&usr.to_lowercase()) + .expect("ERROR") + .push(UserRole::Mod(channelname.clone())); // println!("debug special roles : {:?}",self.special_roles_users); } },