refactor core to use Notif msg

This commit is contained in:
ModulatingForce 2024-03-25 14:11:21 -04:00
parent c0603739c9
commit 628db3c229
4 changed files with 184 additions and 102 deletions

View file

@ -410,38 +410,57 @@ impl BotInstance {
// Only respond to those with th ebelow User Roles // Only respond to those with th ebelow User Roles
if user_roles.contains(&identity::UserRole::Mod(Channel(msg.channel_login.clone()))) let outstr =
|| user_roles.contains(&identity::UserRole::SupMod(Channel(msg.channel_login.clone()))) format!("sadg Module is disabled : {:?}",a);
|| user_roles.contains(&identity::UserRole::Broadcaster)
|| user_roles.contains(&identity::UserRole::BotAdmin)
{ let params = ExecBodyParams {
bot : Arc::clone(&bot),
msg : (*msg).clone(),
parent_act : Arc::clone(&act_clone),
};
// When sending a BotMsgTypeNotif, send_botmsg does Roles related validation as required
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
outstr
),
params,
).await;
// if user_roles.contains(&identity::UserRole::Mod(Channel(msg.channel_login.clone())))
// || user_roles.contains(&identity::UserRole::SupMod(Channel(msg.channel_login.clone())))
// || user_roles.contains(&identity::UserRole::Broadcaster)
// || user_roles.contains(&identity::UserRole::BotAdmin)
// {
// self.say_in_reply_to( // // self.say_in_reply_to(
// &params.msg, // // &params.msg,
// format!("uuh You do not have the right roles to send to {}", // // format!("uuh You do not have the right roles to send to {}",
// channel_login.clone(), // // channel_login.clone(),
// ), // // ),
// params.clone() // // params.clone()
// ).await; // // ).await;
let outstr = // let outstr =
format!("sadg Module is disabled : {:?}",a); // format!("sadg Module is disabled : {:?}",a);
let params = ExecBodyParams { // let params = ExecBodyParams {
bot : Arc::clone(&bot), // bot : Arc::clone(&bot),
msg : (*msg).clone(), // msg : (*msg).clone(),
parent_act : Arc::clone(&act_clone), // parent_act : Arc::clone(&act_clone),
}; // };
botlock.botmgrs.chat.say_in_reply_to( // botlock.botmgrs.chat.say_in_reply_to(
msg, // msg,
outstr, // outstr,
// c.module.clone() // // c.module.clone()
params, // params,
).await; // ).await;
} // }
// botlog::trace( // botlog::trace(

View file

@ -117,9 +117,9 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// BotAction::C(c) => Some(&(*c).module), // BotAction::C(c) => Some(&(*c).module),
// BotAction::L(l) => Some(&(*l).module), // BotAction::L(l) => Some(&(*l).module),
// _ => None, // _ => None,
// }; // // };
let parent_module = params.get_parent_module().await; // let parent_module = params.get_parent_module().await;
@ -191,20 +191,42 @@ pub async fn init(mgr: Arc<ModulesManager>) {
Some(&params.msg), Some(&params.msg),
); );
// Only call Say if there is a parent module passed // We should call a notification around here
if parent_module.is_some() {
let bot = params.clone().bot;
let botclone = Arc::clone(&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.msg.sender.name.clone(),
Some(Channel(params.msg.channel_login.clone()))
).await;
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
outmsg.to_string()
),
params.clone(),
).await;
// // Only call Say if there is a parent module passed
// if parent_module.is_some() {
botlock // botlock
.botmgrs // .botmgrs
.chat // .chat
.say_in_reply_to( // .say_in_reply_to(
&params.msg, // &params.msg,
outmsg.to_string() , // outmsg.to_string() ,
// parent_module.unwrap().clone() // // parent_module.unwrap().clone()
params.clone(), // params.clone(),
).await; // ).await;
} // }
return; return;
@ -236,6 +258,9 @@ pub async fn init(mgr: Arc<ModulesManager>) {
trg_level, trg_level,
id).await; id).await;
// We should call a notification around here
let outmsg = match rslt.clone() { let outmsg = match rslt.clone() {
ChangeResult::Failed(a) => format!("Stare Failed : {}",a), ChangeResult::Failed(a) => format!("Stare Failed : {}",a),
@ -243,22 +268,30 @@ pub async fn init(mgr: Arc<ModulesManager>) {
ChangeResult::Success(a) => format!("YAAY Success : {}",a), ChangeResult::Success(a) => format!("YAAY Success : {}",a),
}; };
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
outmsg.to_string()
),
params.clone(),
).await;
// Only call Say if there is a parent module passed
if parent_module.is_some() {
// // Only call Say if there is a parent module passed
// if parent_module.is_some() {
botlock // botlock
.botmgrs // .botmgrs
.chat // .chat
.say_in_reply_to( // .say_in_reply_to(
&params.msg, // &params.msg,
outmsg.to_string(), // outmsg.to_string(),
// parent_module.unwrap().clone() // // parent_module.unwrap().clone()
params.clone(), // params.clone(),
).await; // ).await;
} // }
@ -414,22 +447,29 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// _ => None, // _ => None,
// }; // };
// We should call a notification around here
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
outmsg.to_string()
),
params.clone(),
).await;
// Only call Say if there is a parent module passed // // Only call Say if there is a parent module passed
if parent_module.is_some() { // if parent_module.is_some() {
botlock // botlock
.botmgrs // .botmgrs
.chat // .chat
.say_in_reply_to( // .say_in_reply_to(
&params.msg, // &params.msg,
outmsg.to_string(), // outmsg.to_string(),
// ,parent_module.unwrap().clone() // // ,parent_module.unwrap().clone()
params.clone() // params.clone()
).await; // ).await;
} // }
return; return;
@ -471,21 +511,29 @@ pub async fn init(mgr: Arc<ModulesManager>) {
ChangeResult::Success(a) => format!("YAAY Success : {}",a), ChangeResult::Success(a) => format!("YAAY Success : {}",a),
}; };
// We should call a notification around here
// Only call Say if there is a parent module passed botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
if parent_module.is_some() { outmsg.to_string()
),
params.clone(),
).await;
botlock
.botmgrs
.chat
.say_in_reply_to(
&params.msg,
outmsg.to_string(),
// parent_module.unwrap().clone()
params.clone(),
).await;
} // // Only call Say if there is a parent module passed
// if parent_module.is_some() {
// botlock
// .botmgrs
// .chat
// .say_in_reply_to(
// &params.msg,
// outmsg.to_string(),
// // parent_module.unwrap().clone()
// params.clone(),
// ).await;
// }

View file

@ -37,7 +37,7 @@ pub struct Chat {
#[derive(Clone,Debug)] #[derive(Clone,Debug)]
enum BotMsgType<'a> { pub enum BotMsgType<'a> {
SayInReplyTo(&'a PrivmsgMessage,String), SayInReplyTo(&'a PrivmsgMessage,String),
Say(String,String), Say(String,String),
Notif(String), // For Bot Sent Notifications Notif(String), // For Bot Sent Notifications
@ -66,7 +66,7 @@ impl Chat {
// async fn send_botmsg(&self, msginput: BotMsgType<'_>) { // async fn send_botmsg(&self, msginput: BotMsgType<'_>) {
#[async_recursion] #[async_recursion]
// async fn send_botmsg(&self, msginput: BotMsgType<'_>, params : ExecBodyParams) { // async fn send_botmsg(&self, msginput: BotMsgType<'_>, params : ExecBodyParams) {
async fn send_botmsg(&self, msginput: BotMsgType<'async_recursion>, params : ExecBodyParams) { pub async fn send_botmsg(&self, msginput: BotMsgType<'async_recursion>, params : ExecBodyParams) {

View file

@ -231,21 +231,30 @@ pub async fn init(mgr: Arc<ModulesManager>) {
Some(&params.msg), Some(&params.msg),
); );
// Only call Say if there is a parent module passed // We should call a notification around here
if parent_module.is_some() {
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
outmsg.to_string()
),
params.clone(),
).await;
botlock // // Only call Say if there is a parent module passed
.botmgrs // if parent_module.is_some() {
.chat
.say_in_reply_to(
&params.msg,
outmsg.to_string(),
// parent_module.unwrap().clone()
params.clone(),
).await;
}
// botlock
// .botmgrs
// .chat
// .say_in_reply_to(
// &params.msg,
// outmsg.to_string(),
// // parent_module.unwrap().clone()
// params.clone(),
// ).await;
// }
botlog::trace( botlog::trace(
// &format!("End of cmd_promote()"), // &format!("End of cmd_promote()"),
@ -458,21 +467,27 @@ pub async fn init(mgr: Arc<ModulesManager>) {
Some(&params.msg), Some(&params.msg),
); );
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
outmsg.to_string()
),
params.clone(),
).await;
// Only call Say if there is a parent module passed
if parent_module.is_some() {
botlock // // Only call Say if there is a parent module passed
.botmgrs // if parent_module.is_some() {
.chat
.say_in_reply_to(
&params.msg,
outmsg.to_string(),
// parent_module.unwrap().clone()
params.clone()
).await;
} // botlock
// .botmgrs
// .chat
// .say_in_reply_to(
// &params.msg,
// outmsg.to_string(),
// // parent_module.unwrap().clone()
// params.clone()
// ).await;
// }