parentact to ExecBodyParams

This commit is contained in:
ModulatingForce 2024-03-24 15:46:08 -04:00
parent 203f6af869
commit 7e5e43fec3
4 changed files with 58 additions and 21 deletions

View file

@ -6,14 +6,16 @@ use tokio::sync::RwLock;
use crate::core::botinstance::BotInstance;
use super::botmodules::BotAction;
pub type BotAR = Arc<RwLock<BotInstance>>;
pub type ActAR = Arc<RwLock<BotAction>>;
pub struct ExecBodyParams {
pub bot : BotAR,
pub msg : PrivmsgMessage,
// parent_act : BotAction ,
pub parent_act : ActAR ,
}
pub mod actions_util {

View file

@ -47,7 +47,7 @@ pub enum ChangeResult {
pub struct Channel(pub String);
use super::bot_actions::ExecBodyParams;
use super::botmodules::StatusType;
use super::botmodules::{BotAction, StatusType};
#[derive(Clone)]
pub struct BotManagers {
@ -264,16 +264,6 @@ impl BotInstance {
// // [ ] #todo Need to run through all Listener Bodies for Enabled Modules for the context of the message (e.g., ModStatus is Enabled in the context for the channel)
let botlock = bot.read().await;
let actsdb = Arc::clone(&botlock.botmodules.botactions);
let actsdblock = actsdb.read().await;
botlog::debug(
format!("# of BotModules: {}", (*actsdblock).len()).as_str(),
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(msg),
);
/*
[ ] What we should do instead is :
@ -309,9 +299,30 @@ impl BotInstance {
},
};
let botlock = bot.read().await;
let actsdb = Arc::clone(&botlock.botmodules.botactions);
let actsdblock = actsdb.read().await;
botlog::debug(
format!("# of BotModules: {}", (*actsdblock).len()).as_str(),
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(msg),
);
for acts in (*actsdblock).values() {
for a in acts {
match a {
// let act_ar = Arc::new(RwLock::new(a));
// let act_ar_clone = Arc::clone(&act_ar);
let act_clone = Arc::clone(a);
// match a {
// match &(*act_ar_clone.read().await) {
match &(*act_clone.read().await) {
crate::core::botmodules::BotAction::C(c) => {
/*
BotCommand handling -
@ -454,7 +465,13 @@ impl BotInstance {
let a = Arc::clone(&bot);
// c.execute(a, msg.clone()).await;
c.execute(ExecBodyParams { bot : a, msg : msg.clone() }).await;
// c.execute(ExecBodyParams { bot : a, msg : msg.clone() }).await;
c.execute(ExecBodyParams {
bot : a,
msg : msg.clone() ,
// parent_act : BotAction::C(c) ,
parent_act : Arc::clone(&act_clone),
}).await;
botlog::trace(
"exit out of execution",
@ -501,7 +518,12 @@ impl BotInstance {
} else {
let a = Arc::clone(&bot);
// l.execute(a, msg.clone()).await;
l.execute(ExecBodyParams { bot : a, msg : msg.clone()} ).await;
l.execute(ExecBodyParams {
bot : a,
msg : msg.clone() ,
// parent_act : BotAction::L(l) ,
parent_act : Arc::clone(&act_clone),
} ).await;
}
}

View file

@ -573,10 +573,11 @@ impl BotActionTrait for Listener {
pub struct Routine {}
type StatusdbEntry = (ModGroup, Vec<StatusType>);
type ModuleActions = Vec<Arc<RwLock<BotAction>>>;
pub struct ModulesManager {
statusdb: Arc<RwLock<HashMap<BotModule, StatusdbEntry>>>,
pub botactions: Arc<RwLock<HashMap<BotModule, Vec<BotAction>>>>,
pub botactions: Arc<RwLock<HashMap<BotModule, ModuleActions>>>,
}
/*
@ -1329,12 +1330,20 @@ impl ModulesManager {
// Check All Other BotAction Command Names & Aliases to ensure they don't conflict
async fn find_conflict_module(mgr: &ModulesManager, act: &BotAction) -> Option<BotModule> {
if let BotAction::C(incmd) = act {
let actdb = mgr.botactions.read().await;
for (module, moduleactions) in &(*actdb) {
for modact in moduleactions.iter() {
if let BotAction::C(dbcmd) = &modact {
// for modact in moduleactions.iter() {
for modact_prelock in moduleactions.iter() {
let modact = modact_prelock.read().await;
// if let BotAction::C(dbcmd) = &modact {
if let BotAction::C(dbcmd) = &(*modact) {
// At this point, there is an command incmd and looked up dbcmd
// [x] check if given botcommand c.command:String conflicts with any in botactions
@ -1390,7 +1399,7 @@ impl ModulesManager {
let mut a = self.botactions.write().await;
let modactions = a.entry(in_module.clone()).or_insert(Vec::new());
modactions.push(in_action);
modactions.push(Arc::new(RwLock::new(in_action)));
botlog::trace(
format!(

View file

@ -33,7 +33,11 @@ pub async fn main() {
for acts in (*actsdb_lock).values() {
for act in acts {
let outstr = match act {
let act_prelock = act;
let act = act_prelock.read().await;
let outstr = match &(*act) {
botmodules::BotAction::C(b) => {
format!("bot actions > Command : {}", b.command)
}