notif BotMsgType
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful

This commit is contained in:
ModulatingForce 2024-03-25 10:07:34 -04:00
parent 246c3d98e6
commit 10d25bf34f

View file

@ -40,6 +40,7 @@ pub struct Chat {
enum BotMsgType<'a> {
SayInReplyTo(&'a PrivmsgMessage,String),
Say(String,String),
Notif(String), // For Bot Sent Notifications
}
@ -63,7 +64,9 @@ impl Chat {
// async fn send_botmsg(&self, msginput: BotMsgType<'_>) {
async fn send_botmsg(&self, msginput: BotMsgType<'_>, params : ExecBodyParams) {
#[async_recursion]
// async fn send_botmsg(&self, msginput: BotMsgType<'_>, params : ExecBodyParams) {
async fn send_botmsg(&self, msginput: BotMsgType<'async_recursion>, params : ExecBodyParams) {
@ -91,6 +94,10 @@ impl Chat {
BotMsgType::Say(a,b ) => {
(a.clone(),b.clone())
},
BotMsgType::Notif(outmsg) => {
// (msg.channel_login.clone(),outmsg)
(params.msg.channel_login.clone(),outmsg)
}
};
@ -156,15 +163,20 @@ impl Chat {
// "uuh Bot can't send to a channel it isn't joined".to_string(),
// params.clone()
// ).await;
if let BotMsgType::SayInReplyTo(a,_) = msginput {
if let BotMsgType::SayInReplyTo(_prvmsg,_outmsg) = msginput {
self.say_in_reply_to(
a,
// self.say_in_reply_to(
// a,
// "uuh Bot can't send to a channel it isn't joined".to_string(),
// params.clone()
// ).await;
self.send_botmsg(BotMsgType::Notif(
"uuh Bot can't send to a channel it isn't joined".to_string(),
params.clone()
).await;
),
params).await;
}
return ;
}
@ -209,43 +221,42 @@ impl Chat {
Log::flush();
match msginput {
BotMsgType::Notif(_) => (), // Do nothing with Notif > We'll validate the user later to handle
BotMsgType::SayInReplyTo(_, _) | BotMsgType::Say(_,_) => {
botlog::trace(
"BEFORE potential Async recursion",
Some("chat.rs > send_botmsg ".to_string()),
Some(&params.clone().msg),
);
Log::flush();
if let BotMsgType::SayInReplyTo(a, _) = msginput {
botlog::trace(
"BEFORE potential Async recursion",
self.send_botmsg(BotMsgType::Notif(
format!("uuh {:?} is disabled on {} : {:?}",
parent_module.clone().unwrap(),
channel_login.clone(),
lvl
),
), params.clone()
).await;
botlog::trace(
"AFTER potential Async recursion",
Some("chat.rs > send_botmsg ".to_string()),
Some(&params.clone().msg),
);
Some(&params.msg),
);
Log::flush();
return
},
Log::flush();
self.say_in_reply_to(
a,
format!("uuh {:?} is disabled on {} : {:?}",
parent_module.clone().unwrap(),
channel_login.clone(),
lvl
),
params.clone()
).await;
botlog::trace(
"AFTER potential Async recursion",
Some("chat.rs > send_botmsg ".to_string()),
Some(&params.msg),
);
Log::flush();
}
return
}
@ -315,10 +326,41 @@ impl Chat {
// params.clone()
// ).await;
return;
match msginput {
BotMsgType::Notif(_) => {
// If the BotMsg is an Error Notification , and the Sender does not have Specific Roles in the Source Channel Sent (where the Error Notif will be sent)
return // return in this case - the User should not see a notification if this path is reached
},
BotMsgType::SayInReplyTo(_,_ ) | BotMsgType::Say(_,_) => {
// If the BotMsg a Say/SayInReplyTo (from Developer or Chatter) , and the Sender does not have Specific Roles in the Source Channel Sent
self.send_botmsg(BotMsgType::Notif(
format!("uuh You do not have the right roles to send to {}",
channel_login.clone(),
),
), params.clone()
).await;
return;
},
};
}
/*
At this stage from the above Validations :
msginput would be :
a. BotMsgType::SayInReplyTo | BotMsgType::Say that is
- Towards a Destination Channel that the Sender has Elevated User Roles to Send to
b. BotMsgType::Notif that is
- Going to be sent to the Source Channel (rather than the original say/sayinreplyto was towards)
- A Sender that has Elevated User Roles in Source Channel will see a message ; otherwise, they will not
*/
/*
Use the following
@ -499,6 +541,9 @@ impl Chat {
BotMsgType::Say(a, _) => {
self.client.say(a, outmsg).await.unwrap();
}
BotMsgType::Notif(outmsg) => {
self.client.say_in_reply_to(&params.msg, outmsg).await.unwrap();
}
}
contextratelimiter.increment_counter();
@ -540,7 +585,7 @@ 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();