2024.01.31 - Latest Borrow Compile Err

This commit is contained in:
ModulatingForce 2024-01-31 09:31:14 -05:00
parent 8a93ef0469
commit be2e967e40
2 changed files with 26 additions and 11 deletions

View file

@ -154,6 +154,9 @@ impl BotManagers {
identity : IdentityManager::init(), identity : IdentityManager::init(),
chat : Chat::init(ratelimiters,client), chat : Chat::init(ratelimiters,client),
} }
} }
} }
@ -249,7 +252,7 @@ impl BotInstance
let join_handle = tokio::spawn(async move { 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 // Below can be used to debug if I want to capture all messages
// println!("Received message: {:?}", message); // println!("Received message: {:?}", message);
@ -258,7 +261,7 @@ impl BotInstance
// if let Some(chnl) = msg.channel_login { // if let Some(chnl) = msg.channel_login {
// println!("NOTICE : (#{}) {}", chnl, msg.message_text); // println!("NOTICE : (#{}) {}", chnl, msg.message_text);
// } // }
match msg.channel_login { match &msg.channel_login {
Some(chnl) => println!("NOTICE : (#{}) {}", chnl, msg.message_text), Some(chnl) => println!("NOTICE : (#{}) {}", chnl, msg.message_text),
None => println!("NOTICE : {}", msg.message_text), None => println!("NOTICE : {}", msg.message_text),
} }
@ -269,7 +272,7 @@ impl BotInstance
println!("Privmsg section"); println!("Privmsg section");
// b.listener_main_prvmsg(&msg); // 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 // - 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(&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); // 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) => (), // Ok(Permissible::Allow) => (),
Permissible::Allow => { Permissible::Allow => {
println!("Executed as permissible"); println!("Executed as permissible");

View file

@ -101,9 +101,11 @@ pub enum Permissible {
Block Block
} }
#[derive(Clone)] //#[derive(Clone)]
pub struct IdentityManager { 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 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>>,
} }
pub enum ChatBadge { pub enum ChatBadge {
@ -122,13 +124,14 @@ impl IdentityManager {
IdentityManager { IdentityManager {
special_roles_users : a, 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 // [ ] 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<UserRole>) -> Result<Permissible,Box<dyn Error>> // pub fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Result<Permissible,Box<dyn Error>>
pub fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Permissible pub fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> &Permissible
{ {
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); // println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
@ -149,7 +152,7 @@ impl IdentityManager {
// } // }
if let Some(sender_badge) = sender_badge { 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()), ChType::Channel(msg.channel_login.to_owned()),
sender_badge, sender_badge,
cmdreqroles cmdreqroles
@ -159,7 +162,7 @@ impl IdentityManager {
// [ ] Call can_user_run() // [ ] Call can_user_run()
Permissible::Block &Permissible::Block
} }
pub fn can_user_run(mut self, pub fn can_user_run(mut self,
@ -241,7 +244,8 @@ impl IdentityManager {
// println!("debug usr : {}",&usr.to_lowercase()); // println!("debug usr : {}",&usr.to_lowercase());
// let Some((k,v)) = self.special_roles_users.get_key_value(usr); // 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) => { Some(usrroles) => {
// println!("contains mod : {}", usrroles.contains(&UserRole::Mod(channelname.clone()))); // println!("contains mod : {}", usrroles.contains(&UserRole::Mod(channelname.clone())));
// println!("contains supmod : {}", usrroles.contains(&UserRole::SupMod(channelname.clone()))); // println!("contains supmod : {}", usrroles.contains(&UserRole::SupMod(channelname.clone())));
@ -250,7 +254,13 @@ impl IdentityManager {
// Do nothing - this is expected // Do nothing - this is expected
} else { } else {
// in this case, they have a ChatBadge::Mod but should have this for the channel // 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); // println!("debug special roles : {:?}",self.special_roles_users);
} }
}, },