ExecBodyParams get_parent_module()

This commit is contained in:
ModulatingForce 2024-03-24 17:40:57 -04:00
parent ee0b9ee196
commit 0eb43c87f2
5 changed files with 134 additions and 72 deletions

View file

@ -6,7 +6,7 @@ use tokio::sync::RwLock;
use crate::core::botinstance::BotInstance;
use super::botmodules::BotAction;
use super::botmodules::{BotAction, BotModule};
pub type BotAR = Arc<RwLock<BotInstance>>;
@ -18,6 +18,57 @@ pub struct ExecBodyParams {
pub parent_act : ActAR ,
}
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);
let parent_module = match act {
BotAction::C(c) => {
let temp = c.module.clone();
Some(temp)
},
BotAction::L(l) => {
let temp = l.module.clone();
Some(temp)
},
_ => None
};
// Arc::new(a)
parent_module
// let a = BotModule("hello".to_string());
// Arc::new(Some(a))
}
}
pub mod actions_util {
use super::*;

View file

@ -110,14 +110,16 @@ pub async fn init(mgr: Arc<ModulesManager>) {
*/
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,
};
// 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,
// };
let parent_module = params.get_parent_module().await;
@ -315,16 +317,16 @@ pub async fn init(mgr: Arc<ModulesManager>) {
[x] Get the parent module
*/
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,
};
// 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,
// };
let parent_module = params.get_parent_module().await;
// [x] Unwraps arguments from message

View file

@ -112,15 +112,16 @@ pub async fn init(mgr: Arc<ModulesManager>) {
[x] Get the parent module
*/
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,
};
// 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,
// };
let parent_module = params.get_parent_module().await;
// println!("{}",params.msg.message_text);
botlog::trace(
@ -311,15 +312,16 @@ pub async fn init(mgr: Arc<ModulesManager>) {
[x] Get the parent module
*/
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,
};
// 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,
// };
let parent_module = params.get_parent_module().await;
// [x] Unwraps arguments from message
@ -512,15 +514,16 @@ pub async fn init(mgr: Arc<ModulesManager>) {
[x] Get the parent module
*/
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,
};
// 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,
// };
let parent_module = params.get_parent_module().await;
let mut argv = params.msg.message_text.split(' ');

View file

@ -116,16 +116,17 @@ pub async fn init(mgr: Arc<ModulesManager>) {
async fn good_girl(params : ExecBodyParams) {
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,
};
// 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,
// };
let parent_module = params.get_parent_module().await;
// [ ] Uses gen_ratio() to output bool based on a ratio probability .
// - For example gen_ratio(2,3) is 2 out of 3 or 0.67% (numerator,denomitator)
@ -191,16 +192,19 @@ async fn babygirl(params : ExecBodyParams) {
[x] Get the parent module
*/
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,
};
// 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,
// };
let parent_module = params.get_parent_module().await;
println!("babygirl triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call
botlog::debug(
@ -223,7 +227,7 @@ async fn babygirl(params : ExecBodyParams) {
.say_in_reply_to(
&params.msg,
String::from("16:13 notohh: cafdk"),
parent_module.unwrap().clone()
parent_module.clone().unwrap().clone()
).await;
@ -235,7 +239,7 @@ async fn babygirl(params : ExecBodyParams) {
.say_in_reply_to(
&params.msg,
String::from("16:13 notohh: have fun eating princess"),
parent_module.unwrap().clone()
parent_module.clone().unwrap().clone()
).await;

View file

@ -79,14 +79,16 @@ async fn sayout(params : ExecBodyParams) {
[x] Get the parent module
*/
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,
};
// 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,
// };
let parent_module = params.get_parent_module().await;
@ -160,7 +162,7 @@ async fn sayout(params : ExecBodyParams) {
);
// return ;
if parent_module.is_some() {
if parent_module.clone().is_some() {
botlock
@ -169,7 +171,7 @@ async fn sayout(params : ExecBodyParams) {
.say_in_reply_to(
&params.msg,
format!("Not a Joined Channel : {}",trgchnl),
parent_module.unwrap().clone()
parent_module.clone().unwrap().clone()
).await;
}
@ -223,7 +225,7 @@ async fn sayout(params : ExecBodyParams) {
};
if parent_module.is_some() {
if parent_module.clone().is_some() {
// uses chat.say_in_reply_to() for the bot controls for messages