Exec Body Fn should be passed Parent BotAction #43

Merged
modulatingforce merged 19 commits from parent-botaction-to-child-fn into main 2024-03-25 16:29:44 -04:00
7 changed files with 82 additions and 69 deletions
Showing only changes of commit 958aeea48e - Show all commits

View file

@ -12,6 +12,7 @@ use super::botmodules::{BotAction, BotModule};
pub type BotAR = Arc<RwLock<BotInstance>>;
pub type ActAR = Arc<RwLock<BotAction>>;
#[derive(Clone)]
pub struct ExecBodyParams {
pub bot : BotAR,
pub msg : PrivmsgMessage,
@ -21,26 +22,8 @@ pub struct ExecBodyParams {
impl ExecBodyParams {
// pub async fn get_parent_module(&self) -> Arc<Option<BotModule>> {
pub async fn get_parent_module(&self) -> Option<BotModule> {
// let params_clone = Arc::clone(&self.parent_act);
// // let actlock = params_clone.read().await;
// // let act = &(*actlock);
// // let a = Arc::new(&act);
// // let parent_module = match act {
// // let parent_module = match &(*actlock) {
// let parent_module = match &(*(params_clone.read().await)) {
// BotAction::C(c) => Some(&(*c).module),
// BotAction::L(l) => Some(&(*l).module),
// _ => None,
// };
// // Some(BotModule("Tester".to_string()))
// let a = Arc::new(parent_module);
// a
let parent_act = Arc::clone(&self.parent_act);
let parent_act_lock = parent_act.read().await;
let act = &(*parent_act_lock);
@ -55,12 +38,7 @@ impl ExecBodyParams {
},
_ => None
};
// Arc::new(a)
parent_module
// let a = BotModule("hello".to_string());
// Arc::new(Some(a))
}

View file

@ -412,10 +412,20 @@ impl BotInstance {
let botlock = bot.read().await;
let outstr =
format!("sadg Module is disabled : {:?}",a);
let params = ExecBodyParams {
bot : Arc::clone(&bot),
msg : (*msg).clone(),
parent_act : Arc::clone(&act_clone),
};
botlock.botmgrs.chat.say_in_reply_to(
msg,
outstr,
c.module.clone()).await;
// c.module.clone()
params,
).await;
}
return;
@ -454,10 +464,20 @@ impl BotInstance {
let botlock = bot.read().await;
let outstr =
"o7 a Mod. I kneel to serve! pepeKneel ".to_string();
let params = ExecBodyParams {
bot : Arc::clone(&bot),
msg : (*msg).clone(),
parent_act : Arc::clone(&act_clone),
};
botlock.botmgrs.chat.say_in_reply_to(
msg,
outstr,
c.module.clone(),
// c.module.clone(),
params
).await;
}
}

View file

@ -198,8 +198,12 @@ pub async fn init(mgr: Arc<ModulesManager>) {
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, outmsg.to_string() , parent_module.unwrap().clone())
.await;
.say_in_reply_to(
&params.msg,
outmsg.to_string() ,
// parent_module.unwrap().clone()
params.clone(),
).await;
}
return;
@ -247,8 +251,12 @@ pub async fn init(mgr: Arc<ModulesManager>) {
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, outmsg.to_string(),parent_module.unwrap().clone())
.await;
.say_in_reply_to(
&params.msg,
outmsg.to_string(),
// parent_module.unwrap().clone()
params.clone(),
).await;
}
@ -414,8 +422,12 @@ pub async fn init(mgr: Arc<ModulesManager>) {
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, outmsg.to_string(),parent_module.unwrap().clone())
.await;
.say_in_reply_to(
&params.msg,
outmsg.to_string(),
// ,parent_module.unwrap().clone()
params.clone()
).await;
}
@ -459,24 +471,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
ChangeResult::Success(a) => format!("YAAY Success : {}",a),
};
// let actlock = params.parent_act.read().await;
// let act = *actlock;
// let parent_module = match act {
// BotAction::C(c) => Some(c.module),
// BotAction::L(l) => Some(l.module),
// _ => None,
// };
// let params_clone = Arc::clone(&params.parent_act);
// let actlock = params_clone.read().await;
// let act = &(*actlock);
// let parent_module = match act {
// BotAction::C(c) => Some(&(*c).module),
// BotAction::L(l) => Some(&(*l).module),
// _ => None,
// };
// Only call Say if there is a parent module passed
if parent_module.is_some() {
@ -484,8 +478,12 @@ pub async fn init(mgr: Arc<ModulesManager>) {
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, outmsg.to_string(),parent_module.unwrap().clone())
.await;
.say_in_reply_to(
&params.msg,
outmsg.to_string(),
// parent_module.unwrap().clone()
params.clone(),
).await;
}

View file

@ -21,6 +21,7 @@ use crate::core::botlog;
use tokio::time::{sleep, Duration};
use super::bot_actions::ExecBodyParams;
use super::botmodules::BotModule;
#[derive(Clone)]
@ -57,7 +58,7 @@ impl Chat {
// async fn send_botmsg(&self, msginput: BotMsgType<'_>) {
async fn send_botmsg(&self, msginput: BotMsgType<'_>, _ : BotModule) {
async fn send_botmsg(&self, msginput: BotMsgType<'_>, params : ExecBodyParams) {
/*
formats message before sending to TwitchIRC
@ -87,6 +88,12 @@ impl Chat {
return ;
}
/*
[ ] !! => 03.24 - Somewhere around here, we should be validating module for target channel
*/
let rl = Arc::clone(&self.ratelimiters);
let mut rllock = rl.lock().await;
@ -163,17 +170,17 @@ impl Chat {
// pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String) {
pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , parent_module : BotModule) {
pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) {
self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg) , parent_module).await;
self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg) , params).await;
}
// pub async fn say(&self, channel_login: String, message: String) {
pub async fn say(&self, channel_login: String, message: String , parent_module : BotModule) {
pub async fn say(&self, channel_login: String, message: String , params : ExecBodyParams) {
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
self.send_botmsg(BotMsgType::Say(channel_login.to_lowercase(), message), parent_module).await;
self.send_botmsg(BotMsgType::Say(channel_login.to_lowercase(), message), params).await;
}
async fn _me(&self, _: String, _: String) {

View file

@ -241,8 +241,9 @@ pub async fn init(mgr: Arc<ModulesManager>) {
.say_in_reply_to(
&params.msg,
outmsg.to_string(),
parent_module.unwrap().clone())
.await;
// parent_module.unwrap().clone()
params.clone(),
).await;
}
@ -467,8 +468,9 @@ pub async fn init(mgr: Arc<ModulesManager>) {
.say_in_reply_to(
&params.msg,
outmsg.to_string(),
parent_module.unwrap().clone())
.await;
// parent_module.unwrap().clone()
params.clone()
).await;
}
@ -641,7 +643,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
botlock.botmgrs.chat.say_in_reply_to(
&params.msg,
outmsg,
parent_module.unwrap().clone()
// parent_module.unwrap().clone()
params.clone()
).await;
}

View file

@ -165,7 +165,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
.say_in_reply_to(
&params.msg,
String::from("GoodGirl xdd "),
parent_module.unwrap().clone()
// parent_module.unwrap().clone()
params.clone()
).await;
}
@ -227,7 +228,8 @@ async fn babygirl(params : ExecBodyParams) {
.say_in_reply_to(
&params.msg,
String::from("16:13 notohh: cafdk"),
parent_module.clone().unwrap().clone()
// parent_module.clone().unwrap().clone()
params.clone()
).await;
@ -239,7 +241,8 @@ async fn babygirl(params : ExecBodyParams) {
.say_in_reply_to(
&params.msg,
String::from("16:13 notohh: have fun eating princess"),
parent_module.clone().unwrap().clone()
// parent_module.clone().unwrap().clone()
params.clone()
).await;
@ -251,7 +254,8 @@ async fn babygirl(params : ExecBodyParams) {
.say_in_reply_to(
&params.msg,
String::from("16:13 notohh: baby girl"),
parent_module.unwrap().clone()
// parent_module.unwrap().clone()
params.clone()
).await;
}

View file

@ -171,7 +171,8 @@ async fn sayout(params : ExecBodyParams) {
.say_in_reply_to(
&params.msg,
format!("Not a Joined Channel : {}",trgchnl),
parent_module.clone().unwrap().clone()
// parent_module.clone().unwrap().clone()
params.clone(),
).await;
}
@ -235,8 +236,9 @@ async fn sayout(params : ExecBodyParams) {
.say(
trgchnl.to_string(),
newoutmsg.to_string(),
parent_module.unwrap().clone())
.await;
// parent_module.unwrap().clone()
params.clone(),
).await;
}
@ -264,7 +266,8 @@ async fn sayout(params : ExecBodyParams) {
.say_in_reply_to(
&params.msg,
String::from("Invalid arguments"),
parent_module.unwrap().clone()
// parent_module.unwrap().clone()
params.clone()
).await;
}