fmt & clippy

This commit is contained in:
ModulatingForce 2024-03-01 23:36:37 -05:00
commit d998e2f290
8 changed files with 228 additions and 161 deletions
src/core

View file

@ -1,25 +1,28 @@
use std::borrow::Borrow;
// use std::borrow::Borrow;
use std::collections::HashMap;
use std::error::Error;
// use std::error::Error;
use crate::core::botmodules::bot_actions::actions_util;
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager};
// use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager};
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager};
use crate::core::botinstance::{self, botlog, BotInstance, ChType};
use futures::lock::Mutex;
use twitch_irc::message::{Badge, PrivmsgMessage};
// use crate::core::botinstance::{self, botlog, BotInstance, ChType};
use crate::core::botinstance::{self, ChType};
// use futures::lock::Mutex;
// use twitch_irc::message::{Badge, PrivmsgMessage};
use twitch_irc::message::PrivmsgMessage;
// use crate::core::botmodules::ChType;
use crate::core::botinstance::ArcBox;
// use crate::core::botinstance::ArcBox;
use std::cell::RefCell;
use std::rc::Rc;
// use std::cell::RefCell;
// use std::rc::Rc;
use std::sync::Arc;
use tokio::sync::RwLock;
use casual_logger::{Level, Log};
use casual_logger::Log;
use super::botmodules::bot_actions::actions_util::BotAR;
@ -55,7 +58,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
tempb.add_to_modmgr(Arc::clone(&mgr)).await;
async fn cmd_promote(bot: BotAR, msg: PrivmsgMessage) -> () {
async fn cmd_promote(bot: BotAR, msg: PrivmsgMessage) {
//println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
// println!("Called cmd promote");
botinstance::botlog::trace(
@ -99,7 +102,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let sendername = msg.clone().sender.name;
let mut argv = msg.message_text.split(" ");
let mut argv = msg.message_text.split(' ');
argv.next(); // Skip the command name
@ -142,7 +145,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let rslt = match targetusr {
Some(targetusr) => {
botinstance::botlog::debug(
&format!("running promote()"),
// &format!("running promote()"),
"running promote()",
Some("identity.rs > cmd_promote()".to_string()),
None,
);
@ -167,7 +171,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
None => {
botinstance::botlog::debug(
&format!("No Targer User argument"),
// &format!("No Targer User argument"),
"No Targer User argument",
Some("identity.rs > cmd_demote()".to_string()),
None,
);
@ -482,7 +487,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
*/
botinstance::botlog::trace(
&format!("End of cmd_promote()"),
// &format!("End of cmd_promote()"),
"End of cmd_promote()",
Some("identity.rs > cmd_prommote()".to_string()),
None,
);
@ -519,7 +525,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
tempb.add_to_modmgr(Arc::clone(&mgr)).await;
// async fn cmd_demote(mut _chat:Arc<Mutex<BotInstance>>,_msg:PrivmsgMessage) {
async fn cmd_demote(mut bot: BotAR, msg: PrivmsgMessage) {
async fn cmd_demote(bot: BotAR, msg: PrivmsgMessage) {
// println!("Called cmd demote");
botinstance::botlog::debug(
"Called cmd demote",
@ -566,8 +572,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// let arg2 = argv.next();
let (arg1, arg2) = {
let mut argv = msg.message_text.split(" ");
let (arg1, _arg2) = {
let mut argv = msg.message_text.split(' ');
argv.next(); // Skip the command name
@ -664,7 +670,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let rslt = match targetusr {
Some(targetusr) => {
botinstance::botlog::debug(
&format!("running demote()"),
// &format!("running demote()"),
"running demote()",
Some("identity.rs > cmd_demote()".to_string()),
None,
);
@ -682,7 +689,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
None => {
botinstance::botlog::debug(
&format!("No Targer User argument"),
// &format!("No Targer User argument"),
"No Targer User argument",
Some("identity.rs > cmd_demote()".to_string()),
None,
);
@ -824,7 +832,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
// println!("{}",msg.message_text);
let mut argv = msg.message_text.split(" ");
let mut argv = msg.message_text.split(' ');
// for v in argv {
// println!("args : {v}");
@ -971,7 +979,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
targetchnl.to_lowercase().to_string(),
))) || callersproles.contains(&UserRole::SupMod(ChType::Channel(
targetchnl.to_lowercase().to_string(),
))) || callersproles.contains(&&UserRole::Broadcaster)
))) || callersproles.contains(&UserRole::Broadcaster)
{
idlock
.getspecialuserroles(
@ -1004,7 +1012,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// # I believe at this stage I still have botlock active
botinstance::botlog::debug(
&format!("Evaluating special roles"),
// &format!("Evaluating special roles"),
"Evaluating special roles",
Some("identity.rs > init > getroles()".to_string()),
Some(&msg),
);
@ -1019,7 +1028,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|| (arg2.is_some() && arg2.unwrap() == targetuser.to_lowercase())
{
// First evaluates if they're broadcaster
let mut outmsg = format!("FeelsWowMan they're the broadcaster. ");
// let mut outmsg = format!("FeelsWowMan they're the broadcaster. ");
let mut outmsg = "FeelsWowMan they're the broadcaster. ".to_string();
if sproles.contains(&UserRole::Mod(ChType::Channel(
msg.channel_login.to_lowercase(),
))) || sproles.contains(&UserRole::SupMod(ChType::Channel(
@ -1037,7 +1047,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
{
format!("Target chatter's user roles are : {:?}", sproles)
} else {
format!("Target chatter has no special roles LULE ")
// format!("Target chatter has no special roles LULE ")
"Target chatter has no special roles LULE ".to_string()
};
// if sproles.contains(&UserRole::Mod(msg.channel_login.to_lowercase())) {
@ -1119,12 +1130,15 @@ pub enum Permissible {
Block,
}
type UserRolesDB = HashMap<String, Arc<RwLock<Vec<UserRole>>>>;
#[derive(Clone)]
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 : Arc<Mutex<HashMap<String,Vec<UserRole>>>>, // # <-- (!) This must be String instead of ChType because we're checking a User not a Channel
// special_roles_users : Arc<RwLock<HashMap<String,Vec<UserRole>>>>,
special_roles_users: Arc<RwLock<HashMap<String, Arc<RwLock<Vec<UserRole>>>>>>,
// special_roles_users: Arc<RwLock<HashMap<String, Arc<RwLock<Vec<UserRole>>>>>>,
special_roles_users: Arc<RwLock<UserRolesDB>>,
// parent_mgr : Box<crate::core::botinstance::BotManagers>,
//parent_mgr : Option<Box<crate::core::botinstance::BotManagers>>,
}
@ -1217,7 +1231,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(
pub async fn can_user_run_prvmsg(
&mut self,
msg: &PrivmsgMessage,
cmdreqroles: Vec<UserRole>,
@ -1229,7 +1243,8 @@ impl IdentityManager {
botinstance::botlog::debug(
"Checking within PRVMSG",
Some("identity.rs > can_user_run_PRVMSG()".to_string()),
Some(&msg),
// Some(&msg),
Some(msg),
);
let mut sender_badge: Option<ChatBadge> = None;
@ -1362,7 +1377,8 @@ impl IdentityManager {
let usr = usr.to_lowercase();
if cmdreqroles.len() == 0 {
// if cmdreqroles.len() == 0 {
if cmdreqroles.is_empty() {
// return Ok(Permissible::Allow)
return (
Permissible::Allow,
@ -1413,7 +1429,8 @@ impl IdentityManager {
None,
);
let roleslock = Arc::clone(&(*self).special_roles_users);
// let roleslock = Arc::clone(&(*self).special_roles_users);
let roleslock = Arc::clone(&self.special_roles_users);
// println!("Read lock on : Special_Roles_User"); // <-- after this is slightly different between working and problem
botinstance::botlog::trace(
@ -1433,7 +1450,7 @@ impl IdentityManager {
// }
self.affirm_chatter_in_db(usr.clone()).await;
let mut roleslock = roleslock.write().await;
let roleslock = roleslock.write().await;
match (*roleslock).get(&usr.to_lowercase()) {
Some(usrroles)
if usrroles
@ -1470,7 +1487,7 @@ impl IdentityManager {
// Some("identity.rs > can_user_run()".to_string()), None);
let mut roleslock = roleslock;
let mut a = roleslock.get_mut(&usr.to_lowercase()).unwrap();
let a = roleslock.get_mut(&usr.to_lowercase()).unwrap();
let mut alock = a.write().await;
alock.push(UserRole::Mod(channelname.clone()));
@ -1513,7 +1530,12 @@ impl IdentityManager {
None,
);
if let Some(a) = (&*self)
// if let Some(a) = (&*self)
// .special_roles_users
// .read()
// .await
// .get(&usr.to_lowercase())
if let Some(a) = self
.special_roles_users
.read()
.await
@ -1546,7 +1568,12 @@ impl IdentityManager {
// [x] If cmdreqroles includes UserRole::SupMod("") , checks if chatter has UserRole::SupMod(channelname::ChType) to determine if Ok(Permissible::Allow)
if cmdreqroles.contains(&UserRole::SupMod(ChType::Channel(String::new()))) {
if let Some(a) = (&*self)
// if let Some(a) = (&*self)
// .special_roles_users
// .read()
// .await
// .get(&usr.to_lowercase())
if let Some(a) = self
.special_roles_users
.read()
.await
@ -1579,8 +1606,12 @@ impl IdentityManager {
botinstance::botlog::trace(
&format!(
"special roles get : {:?}",
(&*self)
.special_roles_users
// (&*self)
// .special_roles_users
// .read()
// .await
// .get(&usr.to_lowercase())
self.special_roles_users
.read()
.await
.get(&usr.to_lowercase())
@ -1589,7 +1620,8 @@ impl IdentityManager {
None,
);
if let Some(a) = (&*self)
// if let Some(a) = (&*self)
if let Some(a) = (self)
.special_roles_users
.read()
.await
@ -1701,7 +1733,7 @@ impl IdentityManager {
(authusrroles, trgusrroles)
} else {
let mut authusrroles = self
let authusrroles = self
.getspecialuserroles(authorizer.to_lowercase().clone(), None)
.await;
let trgusrroles = self
@ -1810,10 +1842,9 @@ impl IdentityManager {
.await;
return ChangeResult::Success(String::from("Promotion Successful"));
}
// Other else conditions would be mostly spcecial responses like ChangeResult::NoChange or ChangeResult::Fail
// related to authusrroles
else {
} else {
// Other else conditions would be mostly spcecial responses like ChangeResult::NoChange or ChangeResult::Fail
// related to authusrroles
return ChangeResult::Failed(String::from("You're not permitted to do that"));
}
} else if !trgusrroles.contains(&UserRole::Broadcaster)
@ -1893,8 +1924,13 @@ impl IdentityManager {
// At the moment, without any new roles, this should not be reached
// botinstance::botlog::warn(
// &format!("Code Warning : add handing for other trgusrroles"),
// Some("identity.rs > promote()".to_string()),
// None,
// );
botinstance::botlog::warn(
&format!("Code Warning : add handing for other trgusrroles"),
"Code Warning : add handing for other trgusrroles",
Some("identity.rs > promote()".to_string()),
None,
);
@ -2224,8 +2260,13 @@ impl IdentityManager {
// },
// _ => (),
// }
// botinstance::botlog::warn(
// &format!("Runtime reached undeveloped code"),
// Some("identity.rs > promote()".to_string()),
// None,
// );
botinstance::botlog::warn(
&format!("Runtime reached undeveloped code"),
"Runtime reached undeveloped code",
Some("identity.rs > promote()".to_string()),
None,
);
@ -2360,8 +2401,10 @@ impl IdentityManager {
}
}
botinstance::botlog::warn(&format!("Potential Unhandled Demotion Condition : Consider explicitely adding in for better handling"),
Some("identity.rs > demote()".to_string()), None);
// botinstance::botlog::warn(&format!("Potential Unhandled Demotion Condition : Consider explicitely adding in for better handling"),
// Some("identity.rs > demote()".to_string()), None);
botinstance::botlog::warn("Potential Unhandled Demotion Condition : Consider explicitely adding in for better handling",
Some("identity.rs > demote()".to_string()), None);
Log::flush();
ChangeResult::Failed(String::from("Did not meet criteria to demote succesfully"))
}
@ -2477,7 +2520,8 @@ impl IdentityManager {
None,
);
return evalsproles;
// return evalsproles;
evalsproles
}
}