(init) say require parent module

This commit is contained in:
ModulatingForce 2024-03-24 16:59:50 -04:00
parent 7e5e43fec3
commit ee0b9ee196
6 changed files with 344 additions and 81 deletions

View file

@ -412,7 +412,10 @@ impl BotInstance {
let botlock = bot.read().await;
let outstr =
format!("sadg Module is disabled : {:?}",a);
botlock.botmgrs.chat.say_in_reply_to(msg, outstr).await;
botlock.botmgrs.chat.say_in_reply_to(
msg,
outstr,
c.module.clone()).await;
}
return;
@ -451,7 +454,11 @@ impl BotInstance {
let botlock = bot.read().await;
let outstr =
"o7 a Mod. I kneel to serve! pepeKneel ".to_string();
botlock.botmgrs.chat.say_in_reply_to(msg, outstr).await;
botlock.botmgrs.chat.say_in_reply_to(
msg,
outstr,
c.module.clone(),
).await;
}
}

View file

@ -104,6 +104,22 @@ pub async fn init(mgr: Arc<ModulesManager>) {
*/
/*
Get 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,
};
// [x] Unwraps arguments from message
@ -172,12 +188,17 @@ pub async fn init(mgr: Arc<ModulesManager>) {
Some("botmodules.rs > cmd_enable()".to_string()),
Some(&params.msg),
);
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, outmsg.to_string())
.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())
.await;
}
return;
@ -216,11 +237,19 @@ pub async fn init(mgr: Arc<ModulesManager>) {
ChangeResult::Success(a) => format!("YAAY Success : {}",a),
};
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, outmsg.to_string())
.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())
.await;
}
}
@ -282,6 +311,20 @@ pub async fn init(mgr: Arc<ModulesManager>) {
3c. , and is -f (forced) , return a Success
*/
/*
[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,
};
// [x] Unwraps arguments from message
@ -350,13 +393,30 @@ pub async fn init(mgr: Arc<ModulesManager>) {
Some("botmodules.rs > cmd_disable()".to_string()),
Some(&params.msg),
);
botlock
// 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() {
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, outmsg.to_string())
.say_in_reply_to(&params.msg, outmsg.to_string(),parent_module.unwrap().clone())
.await;
}
return;
}
@ -397,11 +457,35 @@ pub async fn init(mgr: Arc<ModulesManager>) {
ChangeResult::Success(a) => format!("YAAY Success : {}",a),
};
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, outmsg.to_string())
.await;
// 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() {
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, outmsg.to_string(),parent_module.unwrap().clone())
.await;
}
@ -413,13 +497,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
#[derive(Debug, Clone)]
// pub enum BotModule {
// BotModule(String),
// }
pub struct BotModule(pub String);
impl PartialEq for BotModule {
fn eq(&self, other: &Self) -> bool {
let BotModule(name1) = self.clone();

View file

@ -21,6 +21,8 @@ use crate::core::botlog;
use tokio::time::{sleep, Duration};
use super::botmodules::BotModule;
#[derive(Clone)]
pub struct Chat {
pub ratelimiters: Arc<Mutex<HashMap<Channel, RateLimiter>>>, // used to limit messages sent per channel
@ -54,7 +56,8 @@ impl Chat {
async fn send_botmsg(&self, msginput: BotMsgType<'_>) {
// async fn send_botmsg(&self, msginput: BotMsgType<'_>) {
async fn send_botmsg(&self, msginput: BotMsgType<'_>, _ : BotModule) {
/*
formats message before sending to TwitchIRC
@ -159,16 +162,18 @@ 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) {
pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , parent_module : BotModule) {
self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg)).await;
self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg) , parent_module).await;
}
pub async fn say(&self, channel_login: String, message: String) {
// pub async fn say(&self, channel_login: String, message: String) {
pub async fn say(&self, channel_login: String, message: String , parent_module : BotModule) {
// 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)).await;
self.send_botmsg(BotMsgType::Say(channel_login.to_lowercase(), message), parent_module).await;
}
async fn _me(&self, _: String, _: String) {

View file

@ -12,6 +12,7 @@ use crate::core::bot_actions::BotAR;
use crate::core::bot_actions::ExecBodyParams;
use crate::core::botinstance::{Channel,ChangeResult};
use crate::core::botlog;
use crate::core::botmodules::BotAction;
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager};
use dotenv::dotenv;
@ -106,6 +107,21 @@ 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,
};
// println!("{}",params.msg.message_text);
botlog::trace(
format!("Twich Message > {}", params.msg.message_text).as_str(),
@ -214,11 +230,20 @@ pub async fn init(mgr: Arc<ModulesManager>) {
Some(&params.msg),
);
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, outmsg.to_string())
.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())
.await;
}
botlog::trace(
// &format!("End of cmd_promote()"),
@ -281,6 +306,22 @@ 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,
};
// [x] Unwraps arguments from message
let (arg1, _arg2) = {
@ -414,11 +455,23 @@ pub async fn init(mgr: Arc<ModulesManager>) {
Some(&params.msg),
);
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, outmsg.to_string())
.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())
.await;
}
}
let tempcomm = BotCommand {
@ -455,6 +508,20 @@ 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 mut argv = params.msg.message_text.split(' ');
argv.next(); // Skip the command name
@ -566,7 +633,16 @@ pub async fn init(mgr: Arc<ModulesManager>) {
Some(&params.msg),
);
botlock.botmgrs.chat.say_in_reply_to(&params.msg, outmsg).await;
if parent_module.is_some() {
botlock.botmgrs.chat.say_in_reply_to(
&params.msg,
outmsg,
parent_module.unwrap().clone()
).await;
}
// [ ] NOTE : After the above, I should receive only the roles in the context of the current channel I received this ideally and maybe BotAdmin ; not outside
}

View file

@ -22,6 +22,7 @@ use crate::core::botlog;
use crate::core::bot_actions::actions_util;
use crate::core::bot_actions::BotAR;
use crate::core::botmodules::BotAction;
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager};
use crate::core::identity::UserRole::*;
@ -113,6 +114,19 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// async fn good_girl(bot: BotAR, msg: PrivmsgMessage) {
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,
};
// [ ] 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)
// - More Info : https://rust-random.github.io/rand/rand/trait.Rng.html#method.gen_ratio
@ -140,12 +154,21 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let botlock = bot.read().await;
// uses chat.say_in_reply_to() for the bot controls for messages
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, String::from("GoodGirl xdd "))
.await;
if parent_module.is_some() {
// uses chat.say_in_reply_to() for the bot controls for messages
botlock
.botmgrs
.chat
.say_in_reply_to(
&params.msg,
String::from("GoodGirl xdd "),
parent_module.unwrap().clone()
).await;
}
}
}
}
@ -163,6 +186,22 @@ async fn testy(params : ExecBodyParams) {
// async fn babygirl(bot: BotAR, msg: PrivmsgMessage) {
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,
};
println!("babygirl triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call
botlog::debug(
"babygirl triggered!",
@ -175,30 +214,43 @@ async fn babygirl(params : ExecBodyParams) {
let botlock = bot.read().await;
// uses chat.say_in_reply_to() for the bot controls for messages
botlock
if parent_module.is_some() {
// uses chat.say_in_reply_to() for the bot controls for messages
botlock
.botmgrs
.chat
.say_in_reply_to(
&params.msg,
String::from("16:13 notohh: cafdk"),
parent_module.unwrap().clone()
).await;
sleep(Duration::from_secs_f64(0.5)).await;
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, String::from("16:13 notohh: cafdk"))
.await;
.say_in_reply_to(
&params.msg,
String::from("16:13 notohh: have fun eating princess"),
parent_module.unwrap().clone()
).await;
sleep(Duration::from_secs_f64(0.5)).await;
sleep(Duration::from_secs_f64(2.0)).await;
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, String::from("16:13 notohh: have fun eating princess"))
.await;
botlock
.botmgrs
.chat
.say_in_reply_to(
&params.msg,
String::from("16:13 notohh: baby girl"),
parent_module.unwrap().clone()
).await;
sleep(Duration::from_secs_f64(2.0)).await;
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, String::from("16:13 notohh: baby girl"))
.await;
}
}

View file

@ -22,6 +22,7 @@ use crate::core::bot_actions::ExecBodyParams;
use crate::core::botinstance::Channel;
// use ChType::Channel;
use crate::core::botlog;
use crate::core::botmodules::BotAction;
use casual_logger::Log;
@ -71,6 +72,24 @@ async fn sayout(params : ExecBodyParams) {
<target channel> <message>
*/
/*
[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 reply_parent = if let Some(Some(reply)) = params.msg.source.tags.0.get("reply-parent-msg-body") {
Some(reply)
} else { None }
@ -141,11 +160,19 @@ async fn sayout(params : ExecBodyParams) {
);
// return ;
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, format!("Not a Joined Channel : {}",trgchnl))
.await;
if parent_module.is_some() {
botlock
.botmgrs
.chat
.say_in_reply_to(
&params.msg,
format!("Not a Joined Channel : {}",trgchnl),
parent_module.unwrap().clone()
).await;
}
}
@ -195,12 +222,21 @@ async fn sayout(params : ExecBodyParams) {
outmsg)
};
// uses chat.say_in_reply_to() for the bot controls for messages
botlock
.botmgrs
.chat
.say(trgchnl.to_string(), newoutmsg.to_string())
.await;
if parent_module.is_some() {
// uses chat.say_in_reply_to() for the bot controls for messages
botlock
.botmgrs
.chat
.say(
trgchnl.to_string(),
newoutmsg.to_string(),
parent_module.unwrap().clone())
.await;
}
@ -216,12 +252,20 @@ async fn sayout(params : ExecBodyParams) {
let botlock = bot.read().await;
// uses chat.say_in_reply_to() for the bot controls for messages
botlock
if parent_module.is_some() {
// uses chat.say_in_reply_to() for the bot controls for messages
botlock
.botmgrs
.chat
.say_in_reply_to(&params.msg, String::from("Invalid arguments"))
.await;
.say_in_reply_to(
&params.msg,
String::from("Invalid arguments"),
parent_module.unwrap().clone()
).await;
}
},