(init) botlog module
This commit is contained in:
parent
b78a2cd2b9
commit
eb6c5ec58c
8 changed files with 382 additions and 68 deletions
src/core
|
@ -385,7 +385,7 @@ pub enum ChatBadge {
|
|||
}
|
||||
|
||||
|
||||
enum ChangeResult {
|
||||
pub enum ChangeResult {
|
||||
Success(String),
|
||||
Failed(String),
|
||||
NoChange(String),
|
||||
|
@ -411,7 +411,7 @@ impl IdentityManager {
|
|||
// 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 async fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Permissible
|
||||
pub async fn can_user_run_PRVMSG(&mut self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Permissible
|
||||
pub async fn can_user_run_PRVMSG(&mut self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> (Permissible,ChangeResult)
|
||||
{
|
||||
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
||||
|
||||
|
@ -454,6 +454,15 @@ impl IdentityManager {
|
|||
// cmdreqroles
|
||||
// ) ;
|
||||
// return a;
|
||||
// return self.can_user_run(msg.sender.name.to_owned(),
|
||||
// ChType::Channel(msg.channel_login.to_owned()),
|
||||
// sender_badge,
|
||||
// cmdreqroles
|
||||
// ).await
|
||||
|
||||
|
||||
// * NOTE : We're preferring to pass the ChangeResult up , where we have access to Chat via BotInstance
|
||||
// that have more strained chatting rules
|
||||
return self.can_user_run(msg.sender.name.to_owned(),
|
||||
ChType::Channel(msg.channel_login.to_owned()),
|
||||
sender_badge,
|
||||
|
@ -465,7 +474,7 @@ impl IdentityManager {
|
|||
|
||||
// [ ] Call can_user_run()
|
||||
// (self,Permissible::Block)
|
||||
Permissible::Block
|
||||
(Permissible::Block,ChangeResult::NoChange("".to_string()))
|
||||
}
|
||||
|
||||
|
||||
|
@ -475,7 +484,8 @@ impl IdentityManager {
|
|||
chat_badge:ChatBadge,
|
||||
cmdreqroles:Vec<UserRole>
|
||||
// ) -> Result<Permissible,Box<dyn Error>> {
|
||||
) -> Permissible {
|
||||
) -> (Permissible,ChangeResult) {
|
||||
|
||||
println!{"Checking within can_user_run()"};
|
||||
/*
|
||||
canUserRun -
|
||||
|
@ -519,10 +529,12 @@ impl IdentityManager {
|
|||
|
||||
if cmdreqroles.len() == 0 {
|
||||
// return Ok(Permissible::Allow)
|
||||
return Permissible::Allow
|
||||
return (Permissible::Allow , ChangeResult::NoChange("Command has no required cmdreqroles".to_string()))
|
||||
}
|
||||
|
||||
|
||||
let mut modrolechange = ChangeResult::NoChange("".to_string());
|
||||
|
||||
|
||||
match chat_badge {
|
||||
|
||||
|
@ -535,7 +547,7 @@ impl IdentityManager {
|
|||
cmdreqroles.contains(&UserRole::Mod(ChType::Channel(String::new()))) ||
|
||||
cmdreqroles.contains(&UserRole::SupMod(ChType::Channel(String::new()))) {
|
||||
// return Ok(Permissible::Allow)
|
||||
return Permissible::Allow
|
||||
return (Permissible::Allow , ChangeResult::NoChange("Broadcaster Role".to_string()))
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -563,30 +575,29 @@ impl IdentityManager {
|
|||
usrroles.read().await.contains(&UserRole::SupMod(channelname.clone())) => { // <-- working got to this point
|
||||
// println!("contains mod : {}", usrroles.read().await.contains(&UserRole::Mod(channelname.clone())));
|
||||
// println!("contains supmod : {}", usrroles.read().await.contains(&UserRole::SupMod(channelname.clone())));
|
||||
// if usrroles.read().await.contains(&UserRole::Mod(channelname.clone())) ||
|
||||
// usrroles.read().await.contains(&UserRole::SupMod(channelname.clone())) {
|
||||
// Do nothing - this is expected
|
||||
|
||||
// Do nothing when theh have a mod badge and have either a supmod or mod badge for the channel
|
||||
println!("Already a mod in roles");
|
||||
// let a = &*self;
|
||||
// let mut lock = a.special_roles_users.write().await;
|
||||
// println!("lock created > adding with a mod role o7");
|
||||
// roleslock.get_mut(&usr.to_lowercase())
|
||||
// // .expect("ERROR")
|
||||
// .unwrap()
|
||||
// .write().await
|
||||
// // .get_mut()
|
||||
// .push(UserRole::Mod(channelname.clone()));
|
||||
// println!("debug special roles : {:?}",self.special_roles_users);
|
||||
|
||||
}
|
||||
_ => {
|
||||
// In the event they have a mod badge , are running a bot command, but don't have a channel mod role yet...
|
||||
println!("lock created > adding with a mod role o7");
|
||||
roleslock.get_mut(&usr.to_lowercase())
|
||||
// .expect("ERROR")
|
||||
.unwrap()
|
||||
.write().await
|
||||
// .get_mut()
|
||||
.push(UserRole::Mod(channelname.clone()));
|
||||
let mut roleslock = roleslock;
|
||||
let mut a = roleslock.get_mut(&usr.to_lowercase()).unwrap();
|
||||
let mut alock = a.write().await;
|
||||
|
||||
alock.push(UserRole::Mod(channelname.clone()));
|
||||
|
||||
modrolechange = ChangeResult::Success("Auto Promoted Mod".to_string());
|
||||
|
||||
// alock.get_mut(&usr.to_lowercase())
|
||||
// .get_or_insert_with(|| UserRole::Mod(channelname.clone()))
|
||||
// // .expect("ERROR")
|
||||
// .unwrap()
|
||||
// .write().await
|
||||
// // .get_mut()
|
||||
// .push(UserRole::Mod(channelname.clone()));
|
||||
} // <-- I'm assuming problem got to here
|
||||
}
|
||||
|
||||
|
@ -612,7 +623,7 @@ impl IdentityManager {
|
|||
if a.read().await.contains(&UserRole::Mod(channelname.clone())) || a.read().await.contains(&UserRole::SupMod(channelname.clone())){
|
||||
// return Ok(Permissible::Allow);
|
||||
println!("Special roles found for user : A mod idenfified ");
|
||||
return Permissible::Allow
|
||||
return (Permissible::Allow , modrolechange)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -625,7 +636,7 @@ impl IdentityManager {
|
|||
if let Some(a) = (&*self).special_roles_users.read().await.get(&usr.to_lowercase()) {
|
||||
if a.read().await.contains(&UserRole::SupMod(channelname.clone())) {
|
||||
// return Ok(Permissible::Allow);
|
||||
return Permissible::Allow
|
||||
return (Permissible::Allow,modrolechange)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -641,12 +652,12 @@ impl IdentityManager {
|
|||
println!("special roles contains BotAdmin: {}",a.read().await.contains(&UserRole::BotAdmin));
|
||||
if a.read().await.contains(&UserRole::BotAdmin) {
|
||||
// return Ok(Permissible::Allow);
|
||||
return Permissible::Allow
|
||||
return (Permissible::Allow,modrolechange)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Permissible::Block
|
||||
(Permissible::Block , ChangeResult::NoChange("Not any permissiable condition".to_string()))
|
||||
}
|
||||
|
||||
// pub async fn promote(&mut self,trgchatter:String,channel:Option<ChType>,trg_role:Option<UserRole>) -> ChangeResult {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue