ExecBodyParams

This commit is contained in:
ModulatingForce 2024-03-24 14:38:09 -04:00
parent 616d1f564f
commit 203f6af869
6 changed files with 124 additions and 101 deletions

View file

@ -11,8 +11,8 @@ pub type BotAR = Arc<RwLock<BotInstance>>;
pub struct ExecBodyParams { pub struct ExecBodyParams {
bot : BotAR, pub bot : BotAR,
msg : PrivmsgMessage, pub msg : PrivmsgMessage,
// parent_act : BotAction , // parent_act : BotAction ,
} }
@ -28,13 +28,15 @@ pub mod actions_util {
// pub type BotAM = Arc<Mutex<BotInstance>>; // pub type BotAM = Arc<Mutex<BotInstance>>;
pub type ExecBody = Box< pub type ExecBody = Box<
dyn Fn(BotAR, PrivmsgMessage) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync, // dyn Fn(BotAR, PrivmsgMessage) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync,
dyn Fn(ExecBodyParams) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync,
>; >;
pub fn asyncbox<T>(f: fn(BotAR, PrivmsgMessage) -> T) -> ExecBody // pub fn asyncbox<T>(f: fn(BotAR, PrivmsgMessage) -> T) -> ExecBody
pub fn asyncbox<T>(f: fn(ExecBodyParams) -> T) -> ExecBody
where where
T: Future<Output = ()> + Send + 'static, T: Future<Output = ()> + Send + 'static,
{ {
Box::new(move |a, b| Box::pin(f(a, b))) Box::new(move |a| Box::pin(f(a)))
} }
} }

View file

@ -46,6 +46,7 @@ pub enum ChangeResult {
//simplifying from enum to struct //simplifying from enum to struct
pub struct Channel(pub String); pub struct Channel(pub String);
use super::bot_actions::ExecBodyParams;
use super::botmodules::StatusType; use super::botmodules::StatusType;
#[derive(Clone)] #[derive(Clone)]
@ -452,7 +453,8 @@ impl BotInstance {
); );
let a = Arc::clone(&bot); let a = Arc::clone(&bot);
c.execute(a, msg.clone()).await; // c.execute(a, msg.clone()).await;
c.execute(ExecBodyParams { bot : a, msg : msg.clone() }).await;
botlog::trace( botlog::trace(
"exit out of execution", "exit out of execution",
@ -498,7 +500,8 @@ impl BotInstance {
} else { } else {
let a = Arc::clone(&bot); let a = Arc::clone(&bot);
l.execute(a, msg.clone()).await; // l.execute(a, msg.clone()).await;
l.execute(ExecBodyParams { bot : a, msg : msg.clone()} ).await;
} }
} }

View file

@ -35,6 +35,7 @@ use async_trait::async_trait;
// use self::bot_actions::actions_util::BotAR; // use self::bot_actions::actions_util::BotAR;
use crate::core::bot_actions::BotAR; use crate::core::bot_actions::BotAR;
use crate::core::bot_actions::actions_util; use crate::core::bot_actions::actions_util;
use crate::core::bot_actions::ExecBodyParams;
use crate::core::botinstance::{BotInstance, Channel,ChangeResult}; use crate::core::botinstance::{BotInstance, Channel,ChangeResult};
use crate::core::botlog; use crate::core::botlog;
use crate::core::identity::{self, Permissible,IdentityManager}; use crate::core::identity::{self, Permissible,IdentityManager};
@ -70,7 +71,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// 2. Add the BotAction to ModulesManager // 2. Add the BotAction to ModulesManager
botc1.add_core_to_modmgr(Arc::clone(&mgr)).await; botc1.add_core_to_modmgr(Arc::clone(&mgr)).await;
async fn cmd_enable(bot: BotAR, msg: PrivmsgMessage) { // async fn cmd_enable(bot: BotAR, msg: PrivmsgMessage) {
async fn cmd_enable(params : ExecBodyParams) {
/* /*
There should be additional validation checks There should be additional validation checks
- BotAdmins can only run instance level (-i) enables - BotAdmins can only run instance level (-i) enables
@ -108,7 +110,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let (arg1, arg2) = { let (arg1, arg2) = {
let mut argv = msg.message_text.split(' '); let mut argv = params.msg.message_text.split(' ');
argv.next(); // Skip the command name argv.next(); // Skip the command name
@ -134,14 +136,14 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// [x] requestor: String, // [x] requestor: String,
let requestor = msg.clone().sender.name; let requestor = params.msg.clone().sender.name;
// [x] requestor_badge: Option<ChatBadge>, // [x] requestor_badge: Option<ChatBadge>,
let mut requestor_badge_mut: Option<ChatBadge> = None; let mut requestor_badge_mut: Option<ChatBadge> = None;
for b in &msg.badges { for b in &params.msg.badges {
if b.name == "moderator" { if b.name == "moderator" {
requestor_badge_mut = Some(ChatBadge::Mod); requestor_badge_mut = Some(ChatBadge::Mod);
} else if b.name == "broadcaster" { } else if b.name == "broadcaster" {
@ -161,20 +163,20 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// if let None = trg_module { // if let None = trg_module {
if trg_module.is_none() { if trg_module.is_none() {
let botlock = bot.read().await; let botlock = params.bot.read().await;
let outmsg = "uuh You need to pass a module"; let outmsg = "uuh You need to pass a module";
botlog::debug( botlog::debug(
outmsg, outmsg,
Some("botmodules.rs > cmd_enable()".to_string()), Some("botmodules.rs > cmd_enable()".to_string()),
Some(&msg), Some(&params.msg),
); );
botlock botlock
.botmgrs .botmgrs
.chat .chat
.say_in_reply_to(&msg, outmsg.to_string()) .say_in_reply_to(&params.msg, outmsg.to_string())
.await; .await;
return; return;
@ -184,7 +186,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// [x] trg_level: StatusLvl, // [x] trg_level: StatusLvl,
let currchnl = msg.channel_login.to_lowercase(); let currchnl = params.msg.channel_login.to_lowercase();
let trg_level = let trg_level =
if arg1 == Some("-i") || arg1 == Some("-f") { StatusLvl::Instance } if arg1 == Some("-i") || arg1 == Some("-f") { StatusLvl::Instance }
@ -194,7 +196,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let botlock = bot.read().await; let botlock = params.bot.read().await;
let modmgr = Arc::clone(&botlock.botmodules); let modmgr = Arc::clone(&botlock.botmodules);
let id = botlock.get_identity(); let id = botlock.get_identity();
@ -217,7 +219,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
botlock botlock
.botmgrs .botmgrs
.chat .chat
.say_in_reply_to(&msg, outmsg.to_string()) .say_in_reply_to(&params.msg, outmsg.to_string())
.await; .await;
@ -244,7 +246,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// 2. Add the BotAction to ModulesManager // 2. Add the BotAction to ModulesManager
botc1.add_core_to_modmgr(Arc::clone(&mgr)).await; botc1.add_core_to_modmgr(Arc::clone(&mgr)).await;
async fn cmd_disable(bot: BotAR, msg: PrivmsgMessage) { // async fn cmd_disable(bot: BotAR, msg: PrivmsgMessage) {
async fn cmd_disable(params : ExecBodyParams) {
/* /*
There should be additional validation checks There should be additional validation checks
- BotAdmins can only run instance level (-i) disables and (-f) force disable - BotAdmins can only run instance level (-i) disables and (-f) force disable
@ -284,7 +287,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let (arg1, arg2) = { let (arg1, arg2) = {
let mut argv = msg.message_text.split(' '); let mut argv = params.msg.message_text.split(' ');
argv.next(); // Skip the command name argv.next(); // Skip the command name
@ -312,14 +315,14 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// [x] requestor: String, // [x] requestor: String,
let requestor = msg.clone().sender.name; let requestor = params.msg.clone().sender.name;
// [x] requestor_badge: Option<ChatBadge>, // [x] requestor_badge: Option<ChatBadge>,
let mut requestor_badge_mut: Option<ChatBadge> = None; let mut requestor_badge_mut: Option<ChatBadge> = None;
for b in &msg.badges { for b in &params.msg.badges {
if b.name == "moderator" { if b.name == "moderator" {
requestor_badge_mut = Some(ChatBadge::Mod); requestor_badge_mut = Some(ChatBadge::Mod);
} else if b.name == "broadcaster" { } else if b.name == "broadcaster" {
@ -338,20 +341,20 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// if let None = trg_module { // if let None = trg_module {
if trg_module.is_none() { if trg_module.is_none() {
let botlock = bot.read().await; let botlock = params.bot.read().await;
let outmsg = "uuh You need to pass a module"; let outmsg = "uuh You need to pass a module";
botlog::debug( botlog::debug(
outmsg, outmsg,
Some("botmodules.rs > cmd_disable()".to_string()), Some("botmodules.rs > cmd_disable()".to_string()),
Some(&msg), Some(&params.msg),
); );
botlock botlock
.botmgrs .botmgrs
.chat .chat
.say_in_reply_to(&msg, outmsg.to_string()) .say_in_reply_to(&params.msg, outmsg.to_string())
.await; .await;
return; return;
@ -362,7 +365,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// [x] trg_level: StatusLvl, // [x] trg_level: StatusLvl,
let currchnl = msg.channel_login.to_lowercase(); let currchnl = params.msg.channel_login.to_lowercase();
let trg_level = let trg_level =
if arg1 == Some("-i") || arg1 == Some("-f") { StatusLvl::Instance } if arg1 == Some("-i") || arg1 == Some("-f") { StatusLvl::Instance }
@ -372,7 +375,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let botlock = bot.read().await; let botlock = params.bot.read().await;
let modmgr = Arc::clone(&botlock.botmodules); let modmgr = Arc::clone(&botlock.botmodules);
let id = botlock.get_identity(); let id = botlock.get_identity();
@ -397,7 +400,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
botlock botlock
.botmgrs .botmgrs
.chat .chat
.say_in_reply_to(&msg, outmsg.to_string()) .say_in_reply_to(&params.msg, outmsg.to_string())
.await; .await;
@ -461,10 +464,11 @@ pub enum BotAction {
} }
impl BotAction { impl BotAction {
pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) { // pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) {
pub async fn execute(&self, params : ExecBodyParams) {
match self { match self {
BotAction::L(a) => a.execute(m, n).await, BotAction::L(a) => a.execute(params).await,
BotAction::C(a) => a.execute(m, n).await, BotAction::C(a) => a.execute(params).await,
_ => (), _ => (),
} }
} }
@ -488,8 +492,9 @@ pub struct BotCommand {
} }
impl BotCommand { impl BotCommand {
pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) { // pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) {
(*self.exec_body)(m, n).await; pub async fn execute(&self, params : ExecBodyParams) {
(*self.exec_body)(params).await;
} }
} }
@ -524,8 +529,9 @@ pub struct Listener {
} }
impl Listener { impl Listener {
pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) { // pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) {
(self.exec_body)(m, n).await; pub async fn execute(&self, params : ExecBodyParams) {
(self.exec_body)(params).await;
} }
} }

View file

@ -9,6 +9,7 @@ use casual_logger::Log;
use crate::core::bot_actions::actions_util; use crate::core::bot_actions::actions_util;
use crate::core::bot_actions::BotAR; use crate::core::bot_actions::BotAR;
use crate::core::bot_actions::ExecBodyParams;
use crate::core::botinstance::{Channel,ChangeResult}; use crate::core::botinstance::{Channel,ChangeResult};
use crate::core::botlog; use crate::core::botlog;
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager}; use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager};
@ -71,11 +72,12 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// tempb.add_to_modmgr(Arc::clone(&mgr)).await; // tempb.add_to_modmgr(Arc::clone(&mgr)).await;
tempb.add_core_to_modmgr(Arc::clone(&mgr)).await; tempb.add_core_to_modmgr(Arc::clone(&mgr)).await;
async fn cmd_promote(bot: BotAR, msg: PrivmsgMessage) { // async fn cmd_promote(bot: BotAR, msg: PrivmsgMessage) {
async fn cmd_promote(params : ExecBodyParams) {
botlog::trace( botlog::trace(
"Called cmd promote", "Called cmd promote",
Some("identity.rs > cmd_prommote()".to_string()), Some("identity.rs > cmd_prommote()".to_string()),
Some(&msg), Some(&params.msg),
); );
// -- If the BotCommand.command was called (e.g., promote) & required roles were validated OUTSIDE of this call // -- If the BotCommand.command was called (e.g., promote) & required roles were validated OUTSIDE of this call
@ -104,16 +106,16 @@ pub async fn init(mgr: Arc<ModulesManager>) {
*/ */
// println!("{}",msg.message_text); // println!("{}",params.msg.message_text);
botlog::trace( botlog::trace(
format!("Twich Message > {}", msg.message_text).as_str(), format!("Twich Message > {}", params.msg.message_text).as_str(),
Some("identity.rs > cmd_promote()".to_string()), Some("identity.rs > cmd_promote()".to_string()),
None, None,
); );
let sendername = msg.clone().sender.name; let sendername = params.msg.clone().sender.name;
let mut argv = msg.message_text.split(' '); let mut argv = params.msg.message_text.split(' ');
argv.next(); // Skip the command name argv.next(); // Skip the command name
@ -123,7 +125,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let mut sender_badge: Option<ChatBadge> = None; let mut sender_badge: Option<ChatBadge> = None;
for b in &msg.badges { for b in &params.msg.badges {
if b.name == "moderator" { if b.name == "moderator" {
sender_badge = Some(ChatBadge::Mod); sender_badge = Some(ChatBadge::Mod);
} else if b.name == "broadcaster" { } else if b.name == "broadcaster" {
@ -131,7 +133,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
} }
} }
let targetchnl = msg.channel_login.to_lowercase(); let targetchnl = params.msg.channel_login.to_lowercase();
/* /*
@ -149,7 +151,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// [x] Get a required lock first // [x] Get a required lock first
let botlock = bot.read().await; let botlock = params.bot.read().await;
let id = botlock.get_identity(); let id = botlock.get_identity();
let idlock = id.read().await; let idlock = id.read().await;
@ -209,13 +211,13 @@ pub async fn init(mgr: Arc<ModulesManager>) {
botlog::debug( botlog::debug(
outmsg.as_str(), outmsg.as_str(),
Some("identity.rs > cmd_prommote()".to_string()), Some("identity.rs > cmd_prommote()".to_string()),
Some(&msg), Some(&params.msg),
); );
botlock botlock
.botmgrs .botmgrs
.chat .chat
.say_in_reply_to(&msg, outmsg.to_string()) .say_in_reply_to(&params.msg, outmsg.to_string())
.await; .await;
botlog::trace( botlog::trace(
@ -244,11 +246,12 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// add_core_to_modmgr // add_core_to_modmgr
tempb.add_core_to_modmgr(Arc::clone(&mgr)).await; tempb.add_core_to_modmgr(Arc::clone(&mgr)).await;
async fn cmd_demote(bot: BotAR, msg: PrivmsgMessage) { // async fn cmd_demote(bot: BotAR, msg: PrivmsgMessage) {
async fn cmd_demote(params : ExecBodyParams) {
botlog::debug( botlog::debug(
"Called cmd demote", "Called cmd demote",
Some("identity.rs > cmd_demote()".to_string()), Some("identity.rs > cmd_demote()".to_string()),
Some(&msg), Some(&params.msg),
); );
Log::flush(); Log::flush();
@ -281,7 +284,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// [x] Unwraps arguments from message // [x] Unwraps arguments from message
let (arg1, _arg2) = { let (arg1, _arg2) = {
let mut argv = msg.message_text.split(' '); let mut argv = params.msg.message_text.split(' ');
argv.next(); // Skip the command name argv.next(); // Skip the command name
@ -320,11 +323,11 @@ pub async fn init(mgr: Arc<ModulesManager>) {
*/ */
let sendername = msg.clone().sender.name; let sendername = params.msg.clone().sender.name;
let mut sender_badge_mut: Option<ChatBadge> = None; let mut sender_badge_mut: Option<ChatBadge> = None;
for b in &msg.badges { for b in &params.msg.badges {
if b.name == "moderator" { if b.name == "moderator" {
sender_badge_mut = Some(ChatBadge::Mod); sender_badge_mut = Some(ChatBadge::Mod);
} else if b.name == "broadcaster" { } else if b.name == "broadcaster" {
@ -336,7 +339,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let targetusr = arg1; let targetusr = arg1;
let targetchnl = msg.channel_login.to_lowercase(); let targetchnl = params.msg.channel_login.to_lowercase();
/* /*
@ -350,7 +353,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// [x] Get a required lock first // [x] Get a required lock first
let botlock = bot.read().await; let botlock = params.bot.read().await;
let id = botlock.get_identity(); let id = botlock.get_identity();
let idlock = id.read().await; let idlock = id.read().await;
@ -408,13 +411,13 @@ pub async fn init(mgr: Arc<ModulesManager>) {
botlog::debug( botlog::debug(
outmsg.as_str(), outmsg.as_str(),
Some("identity.rs > cmd_demote()".to_string()), Some("identity.rs > cmd_demote()".to_string()),
Some(&msg), Some(&params.msg),
); );
botlock botlock
.botmgrs .botmgrs
.chat .chat
.say_in_reply_to(&msg, outmsg.to_string()) .say_in_reply_to(&params.msg, outmsg.to_string())
.await; .await;
} }
@ -436,11 +439,12 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// add_core_to_modmgr // add_core_to_modmgr
tempcomm.add_core_to_modmgr(Arc::clone(&mgr)).await; tempcomm.add_core_to_modmgr(Arc::clone(&mgr)).await;
async fn getroles(bot: BotAR, msg: PrivmsgMessage) { // async fn getroles(bot: BotAR, msg: PrivmsgMessage) {
async fn getroles(params : ExecBodyParams) {
botlog::debug( botlog::debug(
"Called cmd getroles", "Called cmd getroles",
Some("identity.rs > cmd_getroles()".to_string()), Some("identity.rs > cmd_getroles()".to_string()),
Some(&msg), Some(&params.msg),
); );
/* /*
@ -451,7 +455,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
*/ */
let mut argv = msg.message_text.split(' '); let mut argv = params.msg.message_text.split(' ');
argv.next(); // Skip the command name argv.next(); // Skip the command name
@ -466,7 +470,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let targetchnl = arg2; let targetchnl = arg2;
let botlock = bot.read().await; let botlock = params.bot.read().await;
let id = botlock.get_identity(); let id = botlock.get_identity();
@ -478,7 +482,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
idlock idlock
.getspecialuserroles( .getspecialuserroles(
String::from(targetuser), String::from(targetuser),
Some(Channel(msg.channel_login.to_lowercase())), Some(Channel(params.msg.channel_login.to_lowercase())),
) )
.await .await
} }
@ -486,7 +490,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// [x] gets special roles for caller // [x] gets special roles for caller
let callersproles = idlock let callersproles = idlock
.getspecialuserroles( .getspecialuserroles(
msg.sender.name.to_lowercase(), params.msg.sender.name.to_lowercase(),
Some(Channel(targetchnl.to_lowercase().to_string())), Some(Channel(targetchnl.to_lowercase().to_string())),
) )
.await; .await;
@ -508,7 +512,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
idlock idlock
.getspecialuserroles( .getspecialuserroles(
String::from(targetuser), String::from(targetuser),
Some(Channel(msg.channel_login.to_lowercase())), Some(Channel(params.msg.channel_login.to_lowercase())),
) )
.await .await
} }
@ -518,17 +522,17 @@ pub async fn init(mgr: Arc<ModulesManager>) {
botlog::debug( botlog::debug(
&format!("User roles of Target Chatter >> {:?}", sproles), &format!("User roles of Target Chatter >> {:?}", sproles),
Some("identity.rs > init > getroles()".to_string()), Some("identity.rs > init > getroles()".to_string()),
Some(&msg), Some(&params.msg),
); );
botlog::trace( botlog::trace(
// &format!("Evaluating special roles"), // &format!("Evaluating special roles"),
"Evaluating special roles", "Evaluating special roles",
Some("identity.rs > init > getroles()".to_string()), Some("identity.rs > init > getroles()".to_string()),
Some(&msg), Some(&params.msg),
); );
let outmsg = if ((targetuser.to_lowercase() == msg.channel_login.to_lowercase()) let outmsg = if ((targetuser.to_lowercase() == params.msg.channel_login.to_lowercase())
&& arg2.is_none()) && arg2.is_none())
|| (arg2.is_some() && arg2.unwrap() == targetuser.to_lowercase()) || (arg2.is_some() && arg2.unwrap() == targetuser.to_lowercase())
{ {
@ -537,18 +541,18 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let mut outmsg = "FeelsWowMan they're the broadcaster. ".to_string(); let mut outmsg = "FeelsWowMan they're the broadcaster. ".to_string();
if sproles.contains(&UserRole::Mod(Channel( if sproles.contains(&UserRole::Mod(Channel(
msg.channel_login.to_lowercase(), params.msg.channel_login.to_lowercase(),
))) || sproles.contains(&UserRole::SupMod(Channel( ))) || sproles.contains(&UserRole::SupMod(Channel(
msg.channel_login.to_lowercase(), params.msg.channel_login.to_lowercase(),
))) || sproles.contains(&UserRole::BotAdmin) ))) || sproles.contains(&UserRole::BotAdmin)
{ {
outmsg += format!("Target chatter's user roles are : {:?}", sproles).as_str(); outmsg += format!("Target chatter's user roles are : {:?}", sproles).as_str();
} }
outmsg outmsg
} else if sproles.contains(&UserRole::Mod(Channel( } else if sproles.contains(&UserRole::Mod(Channel(
msg.channel_login.to_lowercase(), params.msg.channel_login.to_lowercase(),
))) || sproles.contains(&UserRole::SupMod(Channel( ))) || sproles.contains(&UserRole::SupMod(Channel(
msg.channel_login.to_lowercase(), params.msg.channel_login.to_lowercase(),
))) || sproles.contains(&UserRole::BotAdmin) ))) || sproles.contains(&UserRole::BotAdmin)
{ {
format!("Target chatter's user roles are : {:?}", sproles) format!("Target chatter's user roles are : {:?}", sproles)
@ -559,10 +563,10 @@ pub async fn init(mgr: Arc<ModulesManager>) {
botlog::debug( botlog::debug(
format!("Chat Say Reply message : {}", outmsg).as_str(), format!("Chat Say Reply message : {}", outmsg).as_str(),
Some("identity.rs > init > getroles()".to_string()), Some("identity.rs > init > getroles()".to_string()),
Some(&msg), Some(&params.msg),
); );
botlock.botmgrs.chat.say_in_reply_to(&msg, outmsg).await; botlock.botmgrs.chat.say_in_reply_to(&params.msg, outmsg).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 // [ ] 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

@ -15,6 +15,7 @@ use std::sync::Arc;
use twitch_irc::message::PrivmsgMessage; use twitch_irc::message::PrivmsgMessage;
use crate::core::bot_actions::ExecBodyParams;
// use crate::core::botinstance::ChType::Channel; // use crate::core::botinstance::ChType::Channel;
use crate::core::botinstance::Channel; use crate::core::botinstance::Channel;
use crate::core::botlog; use crate::core::botlog;
@ -110,19 +111,20 @@ pub async fn init(mgr: Arc<ModulesManager>) {
} }
async fn good_girl(bot: BotAR, msg: PrivmsgMessage) { // async fn good_girl(bot: BotAR, msg: PrivmsgMessage) {
async fn good_girl(params : ExecBodyParams) {
// [ ] Uses gen_ratio() to output bool based on a ratio probability . // [ ] 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) // - 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 // - More Info : https://rust-random.github.io/rand/rand/trait.Rng.html#method.gen_ratio
if msg.sender.name.to_lowercase() == "ModulatingForce".to_lowercase() if params.msg.sender.name.to_lowercase() == "ModulatingForce".to_lowercase()
|| msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase() || params.msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase()
// if msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase() // if params.msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase()
{ {
botlog::debug( botlog::debug(
"Good Girl Detected > Pausechamp", "Good Girl Detected > Pausechamp",
Some("experiments > goodgirl()".to_string()), Some("experiments > goodgirl()".to_string()),
Some(&msg), Some(&params.msg),
); );
let rollwin = rand::thread_rng().gen_ratio(1, 1); let rollwin = rand::thread_rng().gen_ratio(1, 1);
@ -131,10 +133,10 @@ async fn good_girl(bot: BotAR, msg: PrivmsgMessage) {
botlog::debug( botlog::debug(
"Oh that's a good girl!", "Oh that's a good girl!",
Some("experiments > goodgirl()".to_string()), Some("experiments > goodgirl()".to_string()),
Some(&msg), Some(&params.msg),
); );
let bot = Arc::clone(&bot); let bot = Arc::clone(&params.bot);
let botlock = bot.read().await; let botlock = bot.read().await;
@ -142,32 +144,34 @@ async fn good_girl(bot: BotAR, msg: PrivmsgMessage) {
botlock botlock
.botmgrs .botmgrs
.chat .chat
.say_in_reply_to(&msg, String::from("GoodGirl xdd ")) .say_in_reply_to(&params.msg, String::from("GoodGirl xdd "))
.await; .await;
} }
} }
} }
async fn testy(mut _chat: BotAR, msg: PrivmsgMessage) { // async fn testy(mut _chat: BotAR, msg: PrivmsgMessage) {
async fn testy(params : ExecBodyParams) {
println!("testy triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call println!("testy triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call
botlog::debug( botlog::debug(
"testy triggered!", "testy triggered!",
Some("experiments > testy()".to_string()), Some("experiments > testy()".to_string()),
Some(&msg), Some(&params.msg),
); );
} }
async fn babygirl(bot: BotAR, msg: PrivmsgMessage) { // async fn babygirl(bot: BotAR, msg: PrivmsgMessage) {
async fn babygirl(params : ExecBodyParams) {
println!("babygirl triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call println!("babygirl triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call
botlog::debug( botlog::debug(
"babygirl triggered!", "babygirl triggered!",
Some("experiments > babygirl()".to_string()), Some("experiments > babygirl()".to_string()),
Some(&msg), Some(&params.msg),
); );
let bot = Arc::clone(&bot); let bot = Arc::clone(&params.bot);
let botlock = bot.read().await; let botlock = bot.read().await;
@ -175,7 +179,7 @@ async fn babygirl(bot: BotAR, msg: PrivmsgMessage) {
botlock botlock
.botmgrs .botmgrs
.chat .chat
.say_in_reply_to(&msg, String::from("16:13 notohh: cafdk")) .say_in_reply_to(&params.msg, String::from("16:13 notohh: cafdk"))
.await; .await;
@ -184,7 +188,7 @@ async fn babygirl(bot: BotAR, msg: PrivmsgMessage) {
botlock botlock
.botmgrs .botmgrs
.chat .chat
.say_in_reply_to(&msg, String::from("16:13 notohh: have fun eating princess")) .say_in_reply_to(&params.msg, String::from("16:13 notohh: have fun eating princess"))
.await; .await;
@ -193,7 +197,7 @@ async fn babygirl(bot: BotAR, msg: PrivmsgMessage) {
botlock botlock
.botmgrs .botmgrs
.chat .chat
.say_in_reply_to(&msg, String::from("16:13 notohh: baby girl")) .say_in_reply_to(&params.msg, String::from("16:13 notohh: baby girl"))
.await; .await;
@ -202,12 +206,13 @@ async fn babygirl(bot: BotAR, msg: PrivmsgMessage) {
async fn routinelike(_bot: BotAR, msg: PrivmsgMessage) { // async fn routinelike(_bot: BotAR, msg: PrivmsgMessage) {
async fn routinelike(params : ExecBodyParams) {
println!("routinelike triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call println!("routinelike triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call
botlog::debug( botlog::debug(
"routinelike triggered!", "routinelike triggered!",
Some("experiments > routinelike()".to_string()), Some("experiments > routinelike()".to_string()),
Some(&msg), Some(&params.msg),
); );
// spawn an async block that runs independently from others // spawn an async block that runs independently from others

View file

@ -17,6 +17,7 @@ use chrono::{TimeZone,Local};
use twitch_irc::message::PrivmsgMessage; use twitch_irc::message::PrivmsgMessage;
use crate::core::bot_actions::ExecBodyParams;
// use crate::core::botinstance::ChType::Channel; // use crate::core::botinstance::ChType::Channel;
use crate::core::botinstance::Channel; use crate::core::botinstance::Channel;
// use ChType::Channel; // use ChType::Channel;
@ -61,14 +62,16 @@ pub async fn init(mgr: Arc<ModulesManager>) {
} }
async fn sayout(bot: BotAR, msg: PrivmsgMessage) { // async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
async fn sayout(params : ExecBodyParams) {
/* /*
usage : usage :
<target channel> <message> <target channel> <message>
*/ */
let reply_parent = if let Some(Some(reply)) = msg.source.tags.0.get("reply-parent-msg-body") { let reply_parent = if let Some(Some(reply)) = params.msg.source.tags.0.get("reply-parent-msg-body") {
Some(reply) Some(reply)
} else { None } } else { None }
; ;
@ -79,7 +82,7 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
// } else { None } // } else { None }
// ; // ;
let reply_parent_ts = if let Some(Some(replyts)) = msg.source.tags.0.get("tmi-sent-ts") { let reply_parent_ts = if let Some(Some(replyts)) = params.msg.source.tags.0.get("tmi-sent-ts") {
let a: i64 = replyts.parse().unwrap(); let a: i64 = replyts.parse().unwrap();
let b = Local.timestamp_millis_opt(a).unwrap(); let b = Local.timestamp_millis_opt(a).unwrap();
@ -93,7 +96,7 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
let argrslt = let argrslt =
if let Some((_,str1)) = msg.message_text.split_once(' ') { if let Some((_,str1)) = params.msg.message_text.split_once(' ') {
if reply_parent.is_none() { if reply_parent.is_none() {
if let Some((channelstr,msgstr)) = str1.split_once(' ') { if let Some((channelstr,msgstr)) = str1.split_once(' ') {
Some((channelstr,msgstr)) Some((channelstr,msgstr))
@ -114,7 +117,7 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
match argrslt { match argrslt {
Some((trgchnl,outmsg)) => { Some((trgchnl,outmsg)) => {
let bot = Arc::clone(&bot); let bot = Arc::clone(&params.bot);
let botlock = bot.read().await; let botlock = bot.read().await;
@ -141,7 +144,7 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
botlock botlock
.botmgrs .botmgrs
.chat .chat
.say_in_reply_to(&msg, format!("Not a Joined Channel : {}",trgchnl)) .say_in_reply_to(&params.msg, format!("Not a Joined Channel : {}",trgchnl))
.await; .await;
@ -178,8 +181,8 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
// srcmsg) // srcmsg)
format!("{} {} @ {} : {}", format!("{} {} @ {} : {}",
reply_parent_ts.unwrap(), reply_parent_ts.unwrap(),
msg.sender.name, params.msg.sender.name,
msg.channel_login, params.msg.channel_login,
srcmsg) srcmsg)
} else { } else {
// format!("{} from #{} says : {}", // format!("{} from #{} says : {}",
@ -187,8 +190,8 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
// msg.channel_login, // msg.channel_login,
// outmsg) // outmsg)
format!("in {} - {} : {}", format!("in {} - {} : {}",
msg.channel_login, params.msg.channel_login,
msg.sender.name, params.msg.sender.name,
outmsg) outmsg)
}; };
@ -206,10 +209,10 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
botlog::debug( botlog::debug(
"sayout had issues trying to parse arguments", "sayout had issues trying to parse arguments",
Some("experiment002 > sayout".to_string()), Some("experiment002 > sayout".to_string()),
Some(&msg), Some(&params.msg),
); );
let bot = Arc::clone(&bot); let bot = Arc::clone(&params.bot);
let botlock = bot.read().await; let botlock = bot.read().await;
@ -217,7 +220,7 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
botlock botlock
.botmgrs .botmgrs
.chat .chat
.say_in_reply_to(&msg, String::from("Invalid arguments")) .say_in_reply_to(&params.msg, String::from("Invalid arguments"))
.await; .await;
}, },