Exec Body Fn should be passed Parent BotAction
#43
6 changed files with 124 additions and 101 deletions
|
@ -11,8 +11,8 @@ pub type BotAR = Arc<RwLock<BotInstance>>;
|
|||
|
||||
|
||||
pub struct ExecBodyParams {
|
||||
bot : BotAR,
|
||||
msg : PrivmsgMessage,
|
||||
pub bot : BotAR,
|
||||
pub msg : PrivmsgMessage,
|
||||
// parent_act : BotAction ,
|
||||
}
|
||||
|
||||
|
@ -28,13 +28,15 @@ pub mod actions_util {
|
|||
// pub type BotAM = Arc<Mutex<BotInstance>>;
|
||||
|
||||
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
|
||||
T: Future<Output = ()> + Send + 'static,
|
||||
{
|
||||
Box::new(move |a, b| Box::pin(f(a, b)))
|
||||
Box::new(move |a| Box::pin(f(a)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ pub enum ChangeResult {
|
|||
//simplifying from enum to struct
|
||||
pub struct Channel(pub String);
|
||||
|
||||
use super::bot_actions::ExecBodyParams;
|
||||
use super::botmodules::StatusType;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -452,7 +453,8 @@ impl BotInstance {
|
|||
);
|
||||
|
||||
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(
|
||||
"exit out of execution",
|
||||
|
@ -498,7 +500,8 @@ impl BotInstance {
|
|||
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ use async_trait::async_trait;
|
|||
// use self::bot_actions::actions_util::BotAR;
|
||||
use crate::core::bot_actions::BotAR;
|
||||
use crate::core::bot_actions::actions_util;
|
||||
use crate::core::bot_actions::ExecBodyParams;
|
||||
use crate::core::botinstance::{BotInstance, Channel,ChangeResult};
|
||||
use crate::core::botlog;
|
||||
use crate::core::identity::{self, Permissible,IdentityManager};
|
||||
|
@ -70,7 +71,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
// 2. Add the BotAction to ModulesManager
|
||||
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
|
||||
- BotAdmins can only run instance level (-i) enables
|
||||
|
@ -108,7 +110,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
let (arg1, arg2) = {
|
||||
|
||||
let mut argv = msg.message_text.split(' ');
|
||||
let mut argv = params.msg.message_text.split(' ');
|
||||
|
||||
argv.next(); // Skip the command name
|
||||
|
||||
|
@ -134,14 +136,14 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
|
||||
// [x] requestor: String,
|
||||
let requestor = msg.clone().sender.name;
|
||||
let requestor = params.msg.clone().sender.name;
|
||||
|
||||
|
||||
// [x] requestor_badge: Option<ChatBadge>,
|
||||
|
||||
let mut requestor_badge_mut: Option<ChatBadge> = None;
|
||||
|
||||
for b in &msg.badges {
|
||||
for b in ¶ms.msg.badges {
|
||||
if b.name == "moderator" {
|
||||
requestor_badge_mut = Some(ChatBadge::Mod);
|
||||
} else if b.name == "broadcaster" {
|
||||
|
@ -161,20 +163,20 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
// if let None = trg_module {
|
||||
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";
|
||||
|
||||
botlog::debug(
|
||||
outmsg,
|
||||
Some("botmodules.rs > cmd_enable()".to_string()),
|
||||
Some(&msg),
|
||||
Some(¶ms.msg),
|
||||
);
|
||||
|
||||
botlock
|
||||
.botmgrs
|
||||
.chat
|
||||
.say_in_reply_to(&msg, outmsg.to_string())
|
||||
.say_in_reply_to(¶ms.msg, outmsg.to_string())
|
||||
.await;
|
||||
|
||||
return;
|
||||
|
@ -184,7 +186,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
// [x] trg_level: StatusLvl,
|
||||
|
||||
let currchnl = msg.channel_login.to_lowercase();
|
||||
let currchnl = params.msg.channel_login.to_lowercase();
|
||||
|
||||
let trg_level =
|
||||
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 id = botlock.get_identity();
|
||||
|
||||
|
@ -217,7 +219,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
botlock
|
||||
.botmgrs
|
||||
.chat
|
||||
.say_in_reply_to(&msg, outmsg.to_string())
|
||||
.say_in_reply_to(¶ms.msg, outmsg.to_string())
|
||||
.await;
|
||||
|
||||
|
||||
|
@ -244,7 +246,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
// 2. Add the BotAction to ModulesManager
|
||||
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
|
||||
- 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 mut argv = msg.message_text.split(' ');
|
||||
let mut argv = params.msg.message_text.split(' ');
|
||||
|
||||
argv.next(); // Skip the command name
|
||||
|
||||
|
@ -312,14 +315,14 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
|
||||
// [x] requestor: String,
|
||||
let requestor = msg.clone().sender.name;
|
||||
let requestor = params.msg.clone().sender.name;
|
||||
|
||||
|
||||
// [x] requestor_badge: Option<ChatBadge>,
|
||||
|
||||
let mut requestor_badge_mut: Option<ChatBadge> = None;
|
||||
|
||||
for b in &msg.badges {
|
||||
for b in ¶ms.msg.badges {
|
||||
if b.name == "moderator" {
|
||||
requestor_badge_mut = Some(ChatBadge::Mod);
|
||||
} else if b.name == "broadcaster" {
|
||||
|
@ -338,20 +341,20 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
// if let None = trg_module {
|
||||
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";
|
||||
|
||||
botlog::debug(
|
||||
outmsg,
|
||||
Some("botmodules.rs > cmd_disable()".to_string()),
|
||||
Some(&msg),
|
||||
Some(¶ms.msg),
|
||||
);
|
||||
|
||||
botlock
|
||||
.botmgrs
|
||||
.chat
|
||||
.say_in_reply_to(&msg, outmsg.to_string())
|
||||
.say_in_reply_to(¶ms.msg, outmsg.to_string())
|
||||
.await;
|
||||
|
||||
return;
|
||||
|
@ -362,7 +365,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
// [x] trg_level: StatusLvl,
|
||||
|
||||
let currchnl = msg.channel_login.to_lowercase();
|
||||
let currchnl = params.msg.channel_login.to_lowercase();
|
||||
|
||||
let trg_level =
|
||||
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 id = botlock.get_identity();
|
||||
|
||||
|
@ -397,7 +400,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
botlock
|
||||
.botmgrs
|
||||
.chat
|
||||
.say_in_reply_to(&msg, outmsg.to_string())
|
||||
.say_in_reply_to(¶ms.msg, outmsg.to_string())
|
||||
.await;
|
||||
|
||||
|
||||
|
@ -461,10 +464,11 @@ pub enum 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 {
|
||||
BotAction::L(a) => a.execute(m, n).await,
|
||||
BotAction::C(a) => a.execute(m, n).await,
|
||||
BotAction::L(a) => a.execute(params).await,
|
||||
BotAction::C(a) => a.execute(params).await,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
@ -488,8 +492,9 @@ pub struct BotCommand {
|
|||
}
|
||||
|
||||
impl BotCommand {
|
||||
pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) {
|
||||
(*self.exec_body)(m, n).await;
|
||||
// pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) {
|
||||
pub async fn execute(&self, params : ExecBodyParams) {
|
||||
(*self.exec_body)(params).await;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -524,8 +529,9 @@ pub struct Listener {
|
|||
}
|
||||
|
||||
impl Listener {
|
||||
pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) {
|
||||
(self.exec_body)(m, n).await;
|
||||
// pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) {
|
||||
pub async fn execute(&self, params : ExecBodyParams) {
|
||||
(self.exec_body)(params).await;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ use casual_logger::Log;
|
|||
|
||||
use crate::core::bot_actions::actions_util;
|
||||
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::{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_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(
|
||||
"Called cmd promote",
|
||||
Some("identity.rs > cmd_prommote()".to_string()),
|
||||
Some(&msg),
|
||||
Some(¶ms.msg),
|
||||
);
|
||||
|
||||
// -- 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(
|
||||
format!("Twich Message > {}", msg.message_text).as_str(),
|
||||
format!("Twich Message > {}", params.msg.message_text).as_str(),
|
||||
Some("identity.rs > cmd_promote()".to_string()),
|
||||
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
|
||||
|
||||
|
@ -123,7 +125,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
let mut sender_badge: Option<ChatBadge> = None;
|
||||
|
||||
for b in &msg.badges {
|
||||
for b in ¶ms.msg.badges {
|
||||
if b.name == "moderator" {
|
||||
sender_badge = Some(ChatBadge::Mod);
|
||||
} 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
|
||||
|
||||
let botlock = bot.read().await;
|
||||
let botlock = params.bot.read().await;
|
||||
let id = botlock.get_identity();
|
||||
let idlock = id.read().await;
|
||||
|
||||
|
@ -209,13 +211,13 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
botlog::debug(
|
||||
outmsg.as_str(),
|
||||
Some("identity.rs > cmd_prommote()".to_string()),
|
||||
Some(&msg),
|
||||
Some(¶ms.msg),
|
||||
);
|
||||
|
||||
botlock
|
||||
.botmgrs
|
||||
.chat
|
||||
.say_in_reply_to(&msg, outmsg.to_string())
|
||||
.say_in_reply_to(¶ms.msg, outmsg.to_string())
|
||||
.await;
|
||||
|
||||
botlog::trace(
|
||||
|
@ -244,11 +246,12 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
// add_core_to_modmgr
|
||||
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(
|
||||
"Called cmd demote",
|
||||
Some("identity.rs > cmd_demote()".to_string()),
|
||||
Some(&msg),
|
||||
Some(¶ms.msg),
|
||||
);
|
||||
Log::flush();
|
||||
|
||||
|
@ -281,7 +284,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
// [x] Unwraps arguments from message
|
||||
|
||||
let (arg1, _arg2) = {
|
||||
let mut argv = msg.message_text.split(' ');
|
||||
let mut argv = params.msg.message_text.split(' ');
|
||||
|
||||
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;
|
||||
|
||||
for b in &msg.badges {
|
||||
for b in ¶ms.msg.badges {
|
||||
if b.name == "moderator" {
|
||||
sender_badge_mut = Some(ChatBadge::Mod);
|
||||
} else if b.name == "broadcaster" {
|
||||
|
@ -336,7 +339,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
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
|
||||
|
||||
let botlock = bot.read().await;
|
||||
let botlock = params.bot.read().await;
|
||||
let id = botlock.get_identity();
|
||||
let idlock = id.read().await;
|
||||
|
||||
|
@ -408,13 +411,13 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
botlog::debug(
|
||||
outmsg.as_str(),
|
||||
Some("identity.rs > cmd_demote()".to_string()),
|
||||
Some(&msg),
|
||||
Some(¶ms.msg),
|
||||
);
|
||||
|
||||
botlock
|
||||
.botmgrs
|
||||
.chat
|
||||
.say_in_reply_to(&msg, outmsg.to_string())
|
||||
.say_in_reply_to(¶ms.msg, outmsg.to_string())
|
||||
.await;
|
||||
}
|
||||
|
||||
|
@ -436,11 +439,12 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
// add_core_to_modmgr
|
||||
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(
|
||||
"Called cmd getroles",
|
||||
Some("identity.rs > cmd_getroles()".to_string()),
|
||||
Some(&msg),
|
||||
Some(¶ms.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
|
||||
|
||||
|
@ -466,7 +470,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
let targetchnl = arg2;
|
||||
|
||||
let botlock = bot.read().await;
|
||||
let botlock = params.bot.read().await;
|
||||
|
||||
let id = botlock.get_identity();
|
||||
|
||||
|
@ -478,7 +482,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
idlock
|
||||
.getspecialuserroles(
|
||||
String::from(targetuser),
|
||||
Some(Channel(msg.channel_login.to_lowercase())),
|
||||
Some(Channel(params.msg.channel_login.to_lowercase())),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
@ -486,7 +490,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
// [x] gets special roles for caller
|
||||
let callersproles = idlock
|
||||
.getspecialuserroles(
|
||||
msg.sender.name.to_lowercase(),
|
||||
params.msg.sender.name.to_lowercase(),
|
||||
Some(Channel(targetchnl.to_lowercase().to_string())),
|
||||
)
|
||||
.await;
|
||||
|
@ -508,7 +512,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
idlock
|
||||
.getspecialuserroles(
|
||||
String::from(targetuser),
|
||||
Some(Channel(msg.channel_login.to_lowercase())),
|
||||
Some(Channel(params.msg.channel_login.to_lowercase())),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
@ -518,17 +522,17 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
botlog::debug(
|
||||
&format!("User roles of Target Chatter >> {:?}", sproles),
|
||||
Some("identity.rs > init > getroles()".to_string()),
|
||||
Some(&msg),
|
||||
Some(¶ms.msg),
|
||||
);
|
||||
|
||||
botlog::trace(
|
||||
// &format!("Evaluating special roles"),
|
||||
"Evaluating special roles",
|
||||
Some("identity.rs > init > getroles()".to_string()),
|
||||
Some(&msg),
|
||||
Some(¶ms.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_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();
|
||||
|
||||
if sproles.contains(&UserRole::Mod(Channel(
|
||||
msg.channel_login.to_lowercase(),
|
||||
params.msg.channel_login.to_lowercase(),
|
||||
))) || sproles.contains(&UserRole::SupMod(Channel(
|
||||
msg.channel_login.to_lowercase(),
|
||||
params.msg.channel_login.to_lowercase(),
|
||||
))) || sproles.contains(&UserRole::BotAdmin)
|
||||
{
|
||||
outmsg += format!("Target chatter's user roles are : {:?}", sproles).as_str();
|
||||
}
|
||||
outmsg
|
||||
} else if sproles.contains(&UserRole::Mod(Channel(
|
||||
msg.channel_login.to_lowercase(),
|
||||
params.msg.channel_login.to_lowercase(),
|
||||
))) || sproles.contains(&UserRole::SupMod(Channel(
|
||||
msg.channel_login.to_lowercase(),
|
||||
params.msg.channel_login.to_lowercase(),
|
||||
))) || sproles.contains(&UserRole::BotAdmin)
|
||||
{
|
||||
format!("Target chatter's user roles are : {:?}", sproles)
|
||||
|
@ -559,10 +563,10 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
botlog::debug(
|
||||
format!("Chat Say Reply message : {}", outmsg).as_str(),
|
||||
Some("identity.rs > init > getroles()".to_string()),
|
||||
Some(&msg),
|
||||
Some(¶ms.msg),
|
||||
);
|
||||
|
||||
botlock.botmgrs.chat.say_in_reply_to(&msg, outmsg).await;
|
||||
botlock.botmgrs.chat.say_in_reply_to(¶ms.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
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ use std::sync::Arc;
|
|||
|
||||
use twitch_irc::message::PrivmsgMessage;
|
||||
|
||||
use crate::core::bot_actions::ExecBodyParams;
|
||||
// use crate::core::botinstance::ChType::Channel;
|
||||
use crate::core::botinstance::Channel;
|
||||
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 .
|
||||
// - 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
|
||||
|
||||
if msg.sender.name.to_lowercase() == "ModulatingForce".to_lowercase()
|
||||
|| msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase()
|
||||
// if msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase()
|
||||
if params.msg.sender.name.to_lowercase() == "ModulatingForce".to_lowercase()
|
||||
|| params.msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase()
|
||||
// if params.msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase()
|
||||
{
|
||||
botlog::debug(
|
||||
"Good Girl Detected > Pausechamp",
|
||||
Some("experiments > goodgirl()".to_string()),
|
||||
Some(&msg),
|
||||
Some(¶ms.msg),
|
||||
);
|
||||
|
||||
let rollwin = rand::thread_rng().gen_ratio(1, 1);
|
||||
|
@ -131,10 +133,10 @@ async fn good_girl(bot: BotAR, msg: PrivmsgMessage) {
|
|||
botlog::debug(
|
||||
"Oh that's a good girl!",
|
||||
Some("experiments > goodgirl()".to_string()),
|
||||
Some(&msg),
|
||||
Some(¶ms.msg),
|
||||
);
|
||||
|
||||
let bot = Arc::clone(&bot);
|
||||
let bot = Arc::clone(¶ms.bot);
|
||||
|
||||
let botlock = bot.read().await;
|
||||
|
||||
|
@ -142,32 +144,34 @@ async fn good_girl(bot: BotAR, msg: PrivmsgMessage) {
|
|||
botlock
|
||||
.botmgrs
|
||||
.chat
|
||||
.say_in_reply_to(&msg, String::from("GoodGirl xdd "))
|
||||
.say_in_reply_to(¶ms.msg, String::from("GoodGirl xdd "))
|
||||
.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
|
||||
botlog::debug(
|
||||
"testy triggered!",
|
||||
Some("experiments > testy()".to_string()),
|
||||
Some(&msg),
|
||||
Some(¶ms.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
|
||||
botlog::debug(
|
||||
"babygirl triggered!",
|
||||
Some("experiments > babygirl()".to_string()),
|
||||
Some(&msg),
|
||||
Some(¶ms.msg),
|
||||
);
|
||||
|
||||
|
||||
let bot = Arc::clone(&bot);
|
||||
let bot = Arc::clone(¶ms.bot);
|
||||
|
||||
let botlock = bot.read().await;
|
||||
|
||||
|
@ -175,7 +179,7 @@ async fn babygirl(bot: BotAR, msg: PrivmsgMessage) {
|
|||
botlock
|
||||
.botmgrs
|
||||
.chat
|
||||
.say_in_reply_to(&msg, String::from("16:13 notohh: cafdk"))
|
||||
.say_in_reply_to(¶ms.msg, String::from("16:13 notohh: cafdk"))
|
||||
.await;
|
||||
|
||||
|
||||
|
@ -184,7 +188,7 @@ async fn babygirl(bot: BotAR, msg: PrivmsgMessage) {
|
|||
botlock
|
||||
.botmgrs
|
||||
.chat
|
||||
.say_in_reply_to(&msg, String::from("16:13 notohh: have fun eating princess"))
|
||||
.say_in_reply_to(¶ms.msg, String::from("16:13 notohh: have fun eating princess"))
|
||||
.await;
|
||||
|
||||
|
||||
|
@ -193,7 +197,7 @@ async fn babygirl(bot: BotAR, msg: PrivmsgMessage) {
|
|||
botlock
|
||||
.botmgrs
|
||||
.chat
|
||||
.say_in_reply_to(&msg, String::from("16:13 notohh: baby girl"))
|
||||
.say_in_reply_to(¶ms.msg, String::from("16:13 notohh: baby girl"))
|
||||
.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
|
||||
botlog::debug(
|
||||
"routinelike triggered!",
|
||||
Some("experiments > routinelike()".to_string()),
|
||||
Some(&msg),
|
||||
Some(¶ms.msg),
|
||||
);
|
||||
|
||||
// spawn an async block that runs independently from others
|
||||
|
|
|
@ -17,6 +17,7 @@ use chrono::{TimeZone,Local};
|
|||
|
||||
use twitch_irc::message::PrivmsgMessage;
|
||||
|
||||
use crate::core::bot_actions::ExecBodyParams;
|
||||
// use crate::core::botinstance::ChType::Channel;
|
||||
use crate::core::botinstance::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 :
|
||||
<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)
|
||||
} else { None }
|
||||
;
|
||||
|
@ -79,7 +82,7 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
|
|||
// } 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 b = Local.timestamp_millis_opt(a).unwrap();
|
||||
|
@ -93,7 +96,7 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
|
|||
|
||||
|
||||
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 let Some((channelstr,msgstr)) = str1.split_once(' ') {
|
||||
Some((channelstr,msgstr))
|
||||
|
@ -114,7 +117,7 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
|
|||
match argrslt {
|
||||
Some((trgchnl,outmsg)) => {
|
||||
|
||||
let bot = Arc::clone(&bot);
|
||||
let bot = Arc::clone(¶ms.bot);
|
||||
|
||||
let botlock = bot.read().await;
|
||||
|
||||
|
@ -141,7 +144,7 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
|
|||
botlock
|
||||
.botmgrs
|
||||
.chat
|
||||
.say_in_reply_to(&msg, format!("Not a Joined Channel : {}",trgchnl))
|
||||
.say_in_reply_to(¶ms.msg, format!("Not a Joined Channel : {}",trgchnl))
|
||||
.await;
|
||||
|
||||
|
||||
|
@ -178,8 +181,8 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
|
|||
// srcmsg)
|
||||
format!("{} {} @ {} : {}",
|
||||
reply_parent_ts.unwrap(),
|
||||
msg.sender.name,
|
||||
msg.channel_login,
|
||||
params.msg.sender.name,
|
||||
params.msg.channel_login,
|
||||
srcmsg)
|
||||
} else {
|
||||
// format!("{} from #{} says : {}",
|
||||
|
@ -187,8 +190,8 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
|
|||
// msg.channel_login,
|
||||
// outmsg)
|
||||
format!("in {} - {} : {}",
|
||||
msg.channel_login,
|
||||
msg.sender.name,
|
||||
params.msg.channel_login,
|
||||
params.msg.sender.name,
|
||||
outmsg)
|
||||
};
|
||||
|
||||
|
@ -206,10 +209,10 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
|
|||
botlog::debug(
|
||||
"sayout had issues trying to parse arguments",
|
||||
Some("experiment002 > sayout".to_string()),
|
||||
Some(&msg),
|
||||
Some(¶ms.msg),
|
||||
);
|
||||
|
||||
let bot = Arc::clone(&bot);
|
||||
let bot = Arc::clone(¶ms.bot);
|
||||
|
||||
let botlock = bot.read().await;
|
||||
|
||||
|
@ -217,7 +220,7 @@ async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
|
|||
botlock
|
||||
.botmgrs
|
||||
.chat
|
||||
.say_in_reply_to(&msg, String::from("Invalid arguments"))
|
||||
.say_in_reply_to(¶ms.msg, String::from("Invalid arguments"))
|
||||
.await;
|
||||
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue