readlock fix

This commit is contained in:
ModulatingForce 2024-03-24 23:27:21 -04:00
parent ab5624c6fa
commit cfadd73096

View file

@ -247,6 +247,52 @@ impl Chat {
*/
/*
Use
pub async fn getspecialuserroles(
&self,
chattername: String,
channel: Option<Channel>,
) -> Vec<UserRole> {
*/
// let params_clone = params.clone();
let botclone = Arc::clone(&params.bot);
let botlock = botclone.read().await;
let id = botlock.get_identity();
let id = Arc::clone(&id);
let idlock = id.read().await; // <-- [ ] 03.24 - seems to work
let user_roles = idlock.getspecialuserroles(
params.get_sender(),
Some(Channel(channel_login.clone()))
).await;
// [ ] If user has any of the following target roles, they will be allowed - otherwise, they will not be allowed to send
// - Otherwise if not (checked here) , this will not run
// - NOTE : For now, I've removed BotAdmin just for curiosity - BotAdmins can always elevate themselves if they want
if !(user_roles.contains(&identity::UserRole::Mod(Channel(channel_login.clone())))
|| user_roles.contains(&identity::UserRole::SupMod(Channel(channel_login.clone())))
|| user_roles.contains(&identity::UserRole::Broadcaster))
{
self.say_in_reply_to(
&params.msg,
format!("uuh You do not have the right roles to send to {}",
channel_login.clone(),
),
params.clone()
).await;
return;
}
/*
Use the following
@ -261,6 +307,8 @@ impl Chat {
*/
/*
botlog::trace(
"BEFORE Permissibility checks",
Some("chat.rs > send_botmsg ".to_string()),
@ -360,6 +408,7 @@ impl Chat {
// Permissible::Block => (),
// }
botlog::trace(
format!("permisibility check : {:?}",permissability).as_str(),
Some("chat.rs > send_botmsg ".to_string()),
@ -387,6 +436,7 @@ impl Chat {
}
*/
let rl = Arc::clone(&self.ratelimiters);
let mut rllock = rl.lock().await;
@ -464,58 +514,58 @@ impl Chat {
// pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String) {
// #[async_recursion]
#[async_recursion]
pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) {
let params_clone = params.clone();
// let params_clone = params.clone();
let botclone = Arc::clone(&params_clone.bot);
let botlock = botclone.read().await;
let id = botlock.get_identity();
let id = Arc::clone(&id);
// let botclone = Arc::clone(&params_clone.bot);
// let botlock = botclone.read().await;
// let id = botlock.get_identity();
// let id = Arc::clone(&id);
// // botlog::trace(
// // "ACQUIRING WRITE LOCK : ID",
// // Some("Chat > send_botmsg".to_string()),
// // Some(&params.msg),
// // );
// // Log::flush();
// botlog::trace(
// "ACQUIRING WRITE LOCK : ID",
// "ACQUIRING READ LOCK : ID",
// Some("Chat > send_botmsg".to_string()),
// Some(&params.msg),
// );
// Log::flush();
botlog::trace(
"ACQUIRING READ LOCK : ID",
Some("Chat > send_botmsg".to_string()),
Some(&params.msg),
);
Log::flush();
// let idlock = id.write().await; // <-- [ ] 03.24 - This is definitely locking it
let idlock = id.read().await; // <-- [ ] 03.24 - seems to work
let a = idlock.getspecialuserroles(params.get_sender(), Some(Channel(msg.channel_login.clone()))).await;
botlog::trace(
format!("GETSPECIALUSERROLES RESULT : {:?}",a).as_str(),
Some("Chat > send_botmsg".to_string()),
Some(&params.msg),
);
Log::flush();
// // let idlock = id.write().await; // <-- [ ] 03.24 - This is definitely locking it
// let idlock = id.read().await; // <-- [ ] 03.24 - seems to work
// let a = idlock.getspecialuserroles(params.get_sender(), Some(Channel(msg.channel_login.clone()))).await;
// botlog::trace(
// "ACQUIRED WRITE LOCK : ID",
// format!("GETSPECIALUSERROLES RESULT : {:?}",a).as_str(),
// Some("Chat > send_botmsg".to_string()),
// Some(&params.msg),
// );
// Log::flush();
// // botlog::trace(
// // "ACQUIRED WRITE LOCK : ID",
// // Some("Chat > send_botmsg".to_string()),
// // Some(&params.msg),
// // );
// // Log::flush();
botlog::trace(
"ACQUIRED READ LOCK : ID",
Some("Chat > send_botmsg".to_string()),
Some(&params.msg),
);
Log::flush();
// botlog::trace(
// "ACQUIRED READ LOCK : ID",
// Some("Chat > send_botmsg".to_string()),
// Some(&params.msg),
// );
// Log::flush();
self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg) , params).await;