Exec Body Fn should be passed Parent BotAction
#43
7 changed files with 17 additions and 821 deletions
|
@ -1,7 +1,6 @@
|
|||
|
||||
use twitch_irc::message::PrivmsgMessage;
|
||||
use std::sync::Arc;
|
||||
// use tokio::sync::{Mutex, RwLock};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use crate::core::botinstance::BotInstance;
|
||||
|
@ -27,18 +26,6 @@ impl ExecBodyParams {
|
|||
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
|
||||
// };
|
||||
// parent_module
|
||||
match act {
|
||||
BotAction::C(c) => {
|
||||
let temp = c.module.clone();
|
||||
|
@ -67,10 +54,6 @@ impl ExecBodyParams {
|
|||
requestor_badge_mut = Some(ChatBadge::Broadcaster);
|
||||
}
|
||||
}
|
||||
|
||||
// let requestor_badge = requestor_badge_mut;
|
||||
|
||||
// requestor_badge
|
||||
requestor_badge_mut
|
||||
}
|
||||
|
||||
|
@ -87,15 +70,10 @@ pub mod actions_util {
|
|||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
|
||||
|
||||
// pub type BotAM = Arc<Mutex<BotInstance>>;
|
||||
|
||||
pub type ExecBody = Box<
|
||||
// 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(ExecBodyParams) -> T) -> ExecBody
|
||||
where
|
||||
T: Future<Output = ()> + Send + 'static,
|
||||
|
|
|
@ -17,7 +17,6 @@ use casual_logger::Log;
|
|||
|
||||
use crate::core::ratelimiter::RateLimiter;
|
||||
|
||||
// use crate::core::bot_actions::actions_util::BotAR;
|
||||
use crate::core::bot_actions::BotAR;
|
||||
use crate::core::botmodules::ModulesManager;
|
||||
use crate::core::identity::{IdentityManager, Permissible};
|
||||
|
@ -34,16 +33,8 @@ pub enum ChangeResult {
|
|||
}
|
||||
|
||||
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||
|
||||
// pub enum ChType {
|
||||
// Channel(String),
|
||||
// }
|
||||
//
|
||||
// pub use ChType::Channel;
|
||||
//
|
||||
//simplifying from enum to struct
|
||||
pub struct Channel(pub String);
|
||||
|
||||
use super::bot_actions::ExecBodyParams;
|
||||
|
@ -316,12 +307,8 @@ impl BotInstance {
|
|||
|
||||
for a in acts {
|
||||
|
||||
// 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) => {
|
||||
/*
|
||||
|
@ -428,85 +415,6 @@ impl BotInstance {
|
|||
params,
|
||||
).await;
|
||||
|
||||
|
||||
// if user_roles.contains(&identity::UserRole::Mod(Channel(msg.channel_login.clone())))
|
||||
// || user_roles.contains(&identity::UserRole::SupMod(Channel(msg.channel_login.clone())))
|
||||
// || user_roles.contains(&identity::UserRole::Broadcaster)
|
||||
// || user_roles.contains(&identity::UserRole::BotAdmin)
|
||||
// {
|
||||
|
||||
|
||||
// // self.say_in_reply_to(
|
||||
// // ¶ms.msg,
|
||||
// // format!("uuh You do not have the right roles to send to {}",
|
||||
// // channel_login.clone(),
|
||||
// // ),
|
||||
// // params.clone()
|
||||
// // ).await;
|
||||
// let outstr =
|
||||
// format!("sadg Module is disabled : {:?}",a);
|
||||
|
||||
|
||||
// let params = ExecBodyParams {
|
||||
// bot : Arc::clone(&bot),
|
||||
// msg : (*msg).clone(),
|
||||
// parent_act : Arc::clone(&act_clone),
|
||||
// };
|
||||
|
||||
// botlock.botmgrs.chat.say_in_reply_to(
|
||||
// msg,
|
||||
// outstr,
|
||||
// // c.module.clone()
|
||||
// params,
|
||||
// ).await;
|
||||
|
||||
// }
|
||||
|
||||
|
||||
// botlog::trace(
|
||||
// "ACQUIRING WRITE LOCK : ID",
|
||||
// Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||
// Some(msg),
|
||||
// );
|
||||
|
||||
|
||||
// const OF_CMD_CHANNEL:Channel = Channel(String::new());
|
||||
|
||||
// let elevated_access = {
|
||||
// let mut idlock = id.write().await;
|
||||
// let (permissability, _) = idlock
|
||||
// .can_user_run_prvmsg(msg,
|
||||
// vec![
|
||||
// identity::UserRole::BotAdmin,
|
||||
// identity::UserRole::Mod(OF_CMD_CHANNEL),
|
||||
// identity::UserRole::SupMod(OF_CMD_CHANNEL),
|
||||
// identity::UserRole::Broadcaster,
|
||||
// ])
|
||||
// .await;
|
||||
|
||||
// permissability
|
||||
// };
|
||||
|
||||
// if let Permissible::Allow = elevated_access {
|
||||
// let botlock = bot.read().await;
|
||||
// let outstr =
|
||||
// format!("sadg Module is disabled : {:?}",a);
|
||||
|
||||
// let params = ExecBodyParams {
|
||||
// bot : Arc::clone(&bot),
|
||||
// msg : (*msg).clone(),
|
||||
// parent_act : Arc::clone(&act_clone),
|
||||
|
||||
// };
|
||||
|
||||
// botlock.botmgrs.chat.say_in_reply_to(
|
||||
// msg,
|
||||
// outstr,
|
||||
// // c.module.clone()
|
||||
// params,
|
||||
// ).await;
|
||||
// }
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
|
@ -575,19 +483,15 @@ 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() ,
|
||||
// parent_act : BotAction::C(c) ,
|
||||
parent_act : Arc::clone(&act_clone),
|
||||
}).await;
|
||||
|
||||
botlog::trace(
|
||||
"exit out of execution",
|
||||
Some("BotInstance > listener_main_prvmsg()".to_string()),
|
||||
// Some(&msg),
|
||||
Some(msg),
|
||||
);
|
||||
}
|
||||
|
@ -606,7 +510,6 @@ impl BotInstance {
|
|||
crate::core::botmodules::BotAction::L(l) => {
|
||||
|
||||
let botlock = bot.read().await;
|
||||
// let id = botlock.get_identity();
|
||||
|
||||
// [x] Check first if the Module for that Given Command is Enabled or Disabled on the given Channel
|
||||
let modmgr = Arc::clone(&botlock.botmodules);
|
||||
|
@ -628,11 +531,9 @@ impl BotInstance {
|
|||
|
||||
} else {
|
||||
let a = Arc::clone(&bot);
|
||||
// l.execute(a, msg.clone()).await;
|
||||
l.execute(ExecBodyParams {
|
||||
bot : a,
|
||||
msg : msg.clone() ,
|
||||
// parent_act : BotAction::L(l) ,
|
||||
parent_act : Arc::clone(&act_clone),
|
||||
} ).await;
|
||||
}
|
||||
|
|
|
@ -24,16 +24,12 @@ use core::panic;
|
|||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
// use twitch_irc::message::PrivmsgMessage;
|
||||
|
||||
use casual_logger::Log;
|
||||
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
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};
|
||||
|
@ -104,25 +100,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
Get parent module
|
||||
|
||||
*/
|
||||
|
||||
// let params_clone = Arc::clone(¶ms.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
|
||||
|
||||
|
@ -197,13 +174,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
let botclone = Arc::clone(&bot);
|
||||
let botlock = botclone.read().await;
|
||||
// let id = botlock.get_identity();
|
||||
// let id = Arc::clone(&id);
|
||||
// let idlock = id.read().await; // <-- [ ] 03.24 - seems to work
|
||||
// let user_roles = idlock.getspecialuserroles(
|
||||
// params.msg.sender.name.clone(),
|
||||
// Some(Channel(params.msg.channel_login.clone()))
|
||||
// ).await;
|
||||
|
||||
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
|
||||
outmsg.to_string()
|
||||
|
@ -211,23 +181,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
params.clone(),
|
||||
).await;
|
||||
|
||||
|
||||
|
||||
// // Only call Say if there is a parent module passed
|
||||
// if parent_module.is_some() {
|
||||
|
||||
|
||||
// botlock
|
||||
// .botmgrs
|
||||
// .chat
|
||||
// .say_in_reply_to(
|
||||
// ¶ms.msg,
|
||||
// outmsg.to_string() ,
|
||||
// // parent_module.unwrap().clone()
|
||||
// params.clone(),
|
||||
// ).await;
|
||||
// }
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
@ -239,7 +192,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
let trg_level =
|
||||
if arg1 == Some("-i") || arg1 == Some("-f") { StatusLvl::Instance }
|
||||
// else if arg1 == Some("-f") { StatusLvl::Instance }
|
||||
else { StatusLvl::Ch(Channel(currchnl)) }
|
||||
;
|
||||
|
||||
|
@ -249,8 +201,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
let modmgr = Arc::clone(&botlock.botmodules);
|
||||
let id = botlock.get_identity();
|
||||
|
||||
|
||||
// modmgr.exec_enable(requestor, requestor_badge, trg_module, trg_level, id)
|
||||
let rslt = modmgr.exec_enable(
|
||||
requestor,
|
||||
requestor_badge,
|
||||
|
@ -274,26 +224,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
params.clone(),
|
||||
).await;
|
||||
|
||||
|
||||
|
||||
|
||||
// // Only call Say if there is a parent module passed
|
||||
// if parent_module.is_some() {
|
||||
|
||||
|
||||
// botlock
|
||||
// .botmgrs
|
||||
// .chat
|
||||
// .say_in_reply_to(
|
||||
// ¶ms.msg,
|
||||
// outmsg.to_string(),
|
||||
// // parent_module.unwrap().clone()
|
||||
// params.clone(),
|
||||
// ).await;
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -354,22 +285,8 @@ 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(¶ms.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
|
||||
// [x] Unwraps arguments from message
|
||||
|
||||
let (arg1, arg2) = {
|
||||
|
||||
|
@ -424,7 +341,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
let trg_module = if (arg1 == Some("-i")) || (arg1 == Some("-f")) { arg2 } else { arg1 };
|
||||
|
||||
// if no trg_module was passed
|
||||
// if let None = trg_module {
|
||||
if trg_module.is_none() {
|
||||
|
||||
let botlock = params.bot.read().await;
|
||||
|
@ -437,16 +353,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
Some(¶ms.msg),
|
||||
);
|
||||
|
||||
|
||||
// let params_clone = Arc::clone(¶ms.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,
|
||||
// };
|
||||
|
||||
// We should call a notification around here
|
||||
|
||||
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
|
||||
|
@ -455,22 +361,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
params.clone(),
|
||||
).await;
|
||||
|
||||
|
||||
// // Only call Say if there is a parent module passed
|
||||
// if parent_module.is_some() {
|
||||
|
||||
// botlock
|
||||
// .botmgrs
|
||||
// .chat
|
||||
// .say_in_reply_to(
|
||||
// ¶ms.msg,
|
||||
// outmsg.to_string(),
|
||||
// // ,parent_module.unwrap().clone()
|
||||
// params.clone()
|
||||
// ).await;
|
||||
|
||||
// }
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
@ -495,7 +385,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
let force = arg1 == Some("-f");
|
||||
|
||||
// modmgr.exec_enable(requestor, requestor_badge, trg_module, trg_level, id)
|
||||
let rslt = modmgr.exec_disable(
|
||||
requestor,
|
||||
requestor_badge,
|
||||
|
@ -519,24 +408,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
params.clone(),
|
||||
).await;
|
||||
|
||||
|
||||
// // Only call Say if there is a parent module passed
|
||||
// if parent_module.is_some() {
|
||||
|
||||
// botlock
|
||||
// .botmgrs
|
||||
// .chat
|
||||
// .say_in_reply_to(
|
||||
// ¶ms.msg,
|
||||
// outmsg.to_string(),
|
||||
// // parent_module.unwrap().clone()
|
||||
// params.clone(),
|
||||
// ).await;
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -558,8 +429,6 @@ impl Eq for BotModule {}
|
|||
|
||||
impl Hash for BotModule{
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
// self.id.hash(state);
|
||||
// self.phone.hash(state);
|
||||
let BotModule(name) = self.clone();
|
||||
name.to_lowercase().hash(state);
|
||||
}
|
||||
|
@ -591,7 +460,6 @@ pub enum BotAction {
|
|||
}
|
||||
|
||||
impl BotAction {
|
||||
// pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) {
|
||||
pub async fn execute(&self, params : ExecBodyParams) {
|
||||
match self {
|
||||
BotAction::L(a) => a.execute(params).await,
|
||||
|
@ -619,7 +487,6 @@ pub struct BotCommand {
|
|||
}
|
||||
|
||||
impl BotCommand {
|
||||
// pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) {
|
||||
pub async fn execute(&self, params : ExecBodyParams) {
|
||||
(*self.exec_body)(params).await;
|
||||
}
|
||||
|
@ -656,7 +523,6 @@ pub struct Listener {
|
|||
}
|
||||
|
||||
impl Listener {
|
||||
// pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) {
|
||||
pub async fn execute(&self, params : ExecBodyParams) {
|
||||
(self.exec_body)(params).await;
|
||||
}
|
||||
|
@ -782,7 +648,6 @@ impl ModulesManager {
|
|||
|
||||
let dbt = self.statusdb.read().await;
|
||||
|
||||
// let a = dbt.entry(in_module.clone()).;
|
||||
let (mgrp,statusvector) = dbt.get(&in_module).unwrap();
|
||||
|
||||
match mgrp {
|
||||
|
@ -1261,7 +1126,6 @@ impl ModulesManager {
|
|||
},
|
||||
}
|
||||
|
||||
// (StatusType::Disabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string()))
|
||||
}
|
||||
|
||||
pub async fn force_disable(&self, in_module: BotModule) -> (StatusType,ChangeResult) {
|
||||
|
@ -1305,7 +1169,6 @@ impl ModulesManager {
|
|||
},
|
||||
}
|
||||
|
||||
// (StatusType::Disabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string()))
|
||||
}
|
||||
|
||||
pub async fn set_instance_enabled(&self, in_module: BotModule) -> (StatusType,ChangeResult) {
|
||||
|
@ -1340,7 +1203,6 @@ impl ModulesManager {
|
|||
},
|
||||
}
|
||||
|
||||
// (StatusType::Enabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string()))
|
||||
}
|
||||
|
||||
pub async fn set_ch_disabled(&self, in_module: BotModule , in_chnl: Channel) -> (StatusType,ChangeResult) {
|
||||
|
@ -1378,7 +1240,6 @@ impl ModulesManager {
|
|||
},
|
||||
}
|
||||
|
||||
// (StatusType::Disabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string()))
|
||||
}
|
||||
|
||||
pub async fn set_ch_enabled(&self, in_module: BotModule , in_chnl: Channel) -> (StatusType,ChangeResult) {
|
||||
|
@ -1416,7 +1277,6 @@ impl ModulesManager {
|
|||
}
|
||||
|
||||
|
||||
// (StatusType::Enabled(StatusLvl::Instance),ChangeResult::NoChange("Nothing needed".to_string()))
|
||||
}
|
||||
|
||||
|
||||
|
|
213
src/core/chat.rs
213
src/core/chat.rs
|
@ -12,7 +12,6 @@ use casual_logger::Log;
|
|||
|
||||
use rand::Rng;
|
||||
|
||||
// use crate::core::identity::Permissible;
|
||||
use crate::core::ratelimiter;
|
||||
use crate::core::ratelimiter::RateLimiter;
|
||||
|
||||
|
@ -23,7 +22,6 @@ use crate::core::botlog;
|
|||
use tokio::time::{sleep, Duration};
|
||||
|
||||
use super::bot_actions::ExecBodyParams;
|
||||
// use super::botmodules::BotModule;
|
||||
use super::identity;
|
||||
|
||||
|
||||
|
@ -60,17 +58,12 @@ impl Chat {
|
|||
self.ratelimiters.lock().await.insert(chnl, n);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// async fn send_botmsg(&self, msginput: BotMsgType<'_>) {
|
||||
#[async_recursion]
|
||||
// async fn send_botmsg(&self, msginput: BotMsgType<'_>, params : ExecBodyParams) {
|
||||
pub async fn send_botmsg(&self, msginput: BotMsgType<'async_recursion>, params : ExecBodyParams) {
|
||||
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
formats message before sending to TwitchIRC
|
||||
|
||||
- [x] Custom String Formatting (e.g., adding random black spaces)
|
||||
|
@ -95,7 +88,6 @@ impl Chat {
|
|||
(a.clone(),b.clone())
|
||||
},
|
||||
BotMsgType::Notif(outmsg) => {
|
||||
// (msg.channel_login.clone(),outmsg)
|
||||
(params.msg.channel_login.clone(),outmsg)
|
||||
}
|
||||
};
|
||||
|
@ -110,7 +102,6 @@ impl Chat {
|
|||
);
|
||||
|
||||
let parent_module = params.get_parent_module().await;
|
||||
// let parent_module = parent_module.clone();
|
||||
|
||||
let params_clone = params.clone();
|
||||
let botclone = Arc::clone(¶ms_clone.bot);
|
||||
|
@ -121,36 +112,6 @@ impl Chat {
|
|||
Channel(channel_login.clone())
|
||||
).await;
|
||||
|
||||
|
||||
// botlog::trace(
|
||||
// "BEFORE GET_CHANNEL_STATUS",
|
||||
// Some("chat.rs > send_botmsg ".to_string()),
|
||||
// Some(¶ms.msg),
|
||||
// );
|
||||
|
||||
// let rslt = self.client.get_channel_status(channel_login.clone()).await == (false,false);
|
||||
|
||||
// botlog::trace(
|
||||
// format!("GET_CHANNEL_STATUS result = {:?}",rslt).as_str(),
|
||||
// Some("chat.rs > send_botmsg ".to_string()),
|
||||
// Some(¶ms.msg),
|
||||
// );
|
||||
|
||||
// Log::flush();
|
||||
|
||||
|
||||
|
||||
// if rslt {
|
||||
// // in the case where the provided channel isn't something we're known to be connected to
|
||||
|
||||
// botlog::warn(
|
||||
// &format!("A message attempted to send for a Non-Joined Channel : {}",channel_login.clone()),
|
||||
// Some("Chat > send_botmsg".to_string()),
|
||||
// None,
|
||||
// );
|
||||
// return ;
|
||||
// }
|
||||
|
||||
if !params.bot.read().await.bot_channels.contains(&Channel(channel_login.clone())) {
|
||||
botlog::warn(
|
||||
&format!("A message attempted to send for a Non-Joined Channel : {}",channel_login.clone()),
|
||||
|
@ -158,18 +119,8 @@ impl Chat {
|
|||
None,
|
||||
);
|
||||
|
||||
// self.say_in_reply_to(
|
||||
// ¶ms.msg,
|
||||
// "uuh Bot can't send to a channel it isn't joined".to_string(),
|
||||
// params.clone()
|
||||
// ).await;
|
||||
if let BotMsgType::SayInReplyTo(_prvmsg,_outmsg) = msginput {
|
||||
|
||||
// self.say_in_reply_to(
|
||||
// a,
|
||||
// "uuh Bot can't send to a channel it isn't joined".to_string(),
|
||||
// params.clone()
|
||||
// ).await;
|
||||
self.send_botmsg(BotMsgType::Notif(
|
||||
"uuh Bot can't send to a channel it isn't joined".to_string(),
|
||||
),
|
||||
|
@ -192,13 +143,6 @@ impl Chat {
|
|||
|
||||
*/
|
||||
|
||||
|
||||
// match modstatus {
|
||||
// super::botmodules::StatusType::Enabled(_) => (),
|
||||
// super::botmodules::StatusType::Disabled(_) => (),
|
||||
// }
|
||||
|
||||
|
||||
botlog::trace(
|
||||
format!("BEFORE modstatus check : modstatus = {:?}",modstatus).as_str(),
|
||||
Some("chat.rs > send_botmsg ".to_string()),
|
||||
|
@ -263,7 +207,7 @@ impl Chat {
|
|||
|
||||
/*
|
||||
|
||||
[ ] !! => 03.24 - Would be nice if around here , validate the user has at least some special roles in target channel
|
||||
[x] !! => 03.24 - Would be nice if around here , validate the user has at least some special roles in target channel
|
||||
- NOTE : If these need to be refined, they can be by the custom module developer at the parent calling function of say()
|
||||
- This just prevents Chat from being triggered in a channel where the sending chatter does not have any special roles
|
||||
|
||||
|
@ -271,8 +215,6 @@ impl Chat {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Use
|
||||
|
@ -290,7 +232,7 @@ impl Chat {
|
|||
let botlock = botclone.read().await;
|
||||
let id = botlock.get_identity();
|
||||
let id = Arc::clone(&id);
|
||||
let idlock = id.read().await; // <-- [ ] 03.24 - seems to work
|
||||
let idlock = id.read().await; // <-- [x] 03.24 - seems to work
|
||||
let user_roles = idlock.getspecialuserroles(
|
||||
params.get_sender(),
|
||||
Some(Channel(channel_login.clone()))
|
||||
|
@ -304,18 +246,10 @@ impl Chat {
|
|||
|
||||
Log::flush();
|
||||
|
||||
// [ ] If user has any of the following target roles, they will be allowed - otherwise, they will not be allowed to send
|
||||
// [x] If user has any of the following target roles, they will be allowed - otherwise, they will not be allowed to send
|
||||
// - Otherwise if not (checked here) , this will not run
|
||||
// - NOTE : For now, I've removed BotAdmin just for curiosity - BotAdmins can always elevate themselves if they want
|
||||
|
||||
// if !(user_roles.contains(&identity::UserRole::Mod(Channel(channel_login.clone())))
|
||||
// || user_roles.contains(&identity::UserRole::SupMod(Channel(channel_login.clone())))
|
||||
// || user_roles.contains(&identity::UserRole::Broadcaster))
|
||||
// if !(user_roles.contains(&identity::UserRole::Mod(Channel(channel_login.clone())))
|
||||
// || user_roles.contains(&identity::UserRole::SupMod(Channel(channel_login.clone())))
|
||||
// || user_roles.contains(&identity::UserRole::Broadcaster)
|
||||
// || user_roles.contains(&identity::UserRole::BotAdmin))
|
||||
|
||||
if !(user_roles.contains(&identity::UserRole::Mod(Channel(channel_login.clone())))
|
||||
|| user_roles.contains(&identity::UserRole::SupMod(Channel(channel_login.clone())))
|
||||
|| user_roles.contains(&identity::UserRole::Broadcaster)
|
||||
|
@ -323,14 +257,6 @@ impl Chat {
|
|||
{
|
||||
|
||||
|
||||
// self.say_in_reply_to(
|
||||
// ¶ms.msg,
|
||||
// format!("uuh You do not have the right roles to send to {}",
|
||||
// channel_login.clone(),
|
||||
// ),
|
||||
// params.clone()
|
||||
// ).await;
|
||||
|
||||
match msginput {
|
||||
BotMsgType::Notif(_) => {
|
||||
// If Sender is Not a BotAdmin, don't do anything about the notification and return
|
||||
|
@ -382,137 +308,6 @@ impl Chat {
|
|||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
botlog::trace(
|
||||
"BEFORE Permissibility checks",
|
||||
Some("chat.rs > send_botmsg ".to_string()),
|
||||
Some(¶ms.msg),
|
||||
);
|
||||
|
||||
Log::flush();
|
||||
|
||||
|
||||
const OF_CMD_CHANNEL:Channel = Channel(String::new());
|
||||
|
||||
let permissability = Permissible::Allow;
|
||||
|
||||
{
|
||||
|
||||
|
||||
// let id = botlock.get_identity();
|
||||
// let mut idlock = id.write().await; // <-- [ ] 03.24 - This is definitely locking it
|
||||
let channel_login_clone = channel_login.clone();
|
||||
|
||||
|
||||
let spawnhandle = tokio::spawn(
|
||||
async move {
|
||||
let botclone = Arc::clone(¶ms_clone.bot);
|
||||
let botlock = botclone.read().await;
|
||||
let id = botlock.get_identity();
|
||||
|
||||
|
||||
// botlog::trace(
|
||||
// "ACQUIRING WRITE LOCK : ID",
|
||||
// Some("Chat > send_botmsg".to_string()),
|
||||
// Some(¶ms.msg),
|
||||
// );
|
||||
|
||||
|
||||
// {
|
||||
// let mut idlock = id.write().await; // <-- [ ] 03.24 - This is definitely locking it
|
||||
// }
|
||||
|
||||
// botlog::trace(
|
||||
// "ACQUIRED WRITE LOCK : ID",
|
||||
// Some("Chat > send_botmsg".to_string()),
|
||||
// Some(¶ms.msg),
|
||||
// );
|
||||
|
||||
// let (permissability, _) = idlock
|
||||
// .can_user_run(
|
||||
// params.get_sender(),
|
||||
// Channel(channel_login_clone),
|
||||
// params.get_sender_chatbadge(),
|
||||
// vec![
|
||||
// //identity::UserRole::BotAdmin,
|
||||
// identity::UserRole::Mod(OF_CMD_CHANNEL),
|
||||
// identity::UserRole::SupMod(OF_CMD_CHANNEL),
|
||||
// identity::UserRole::Broadcaster,
|
||||
// ]
|
||||
// ).await;
|
||||
// permissability
|
||||
}
|
||||
);
|
||||
|
||||
if let Ok(permissibility) = spawnhandle.await {
|
||||
botlog::trace(
|
||||
format!("permisibility check : {:?}",permissability).as_str(),
|
||||
Some("chat.rs > send_botmsg ".to_string()),
|
||||
None
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// let permissability = {
|
||||
// let id = botlock.get_identity();
|
||||
// let mut idlock = id.write().await; // <-- [ ] 03.24 - This is definitely locking it
|
||||
// let (permissability, _) = idlock
|
||||
// .can_user_run(
|
||||
// params.get_sender(),
|
||||
// Channel(channel_login.clone()),
|
||||
// params.get_sender_chatbadge(),
|
||||
// vec![
|
||||
// //identity::UserRole::BotAdmin,
|
||||
// identity::UserRole::Mod(OF_CMD_CHANNEL),
|
||||
// identity::UserRole::SupMod(OF_CMD_CHANNEL),
|
||||
// identity::UserRole::Broadcaster,
|
||||
// ]
|
||||
// ).await;
|
||||
// permissability
|
||||
// };
|
||||
|
||||
// match permissability {
|
||||
// Permissible::Allow => (),
|
||||
// Permissible::Block => (),
|
||||
// }
|
||||
|
||||
|
||||
botlog::trace(
|
||||
format!("permisibility check : {:?}",permissability).as_str(),
|
||||
Some("chat.rs > send_botmsg ".to_string()),
|
||||
None,
|
||||
);
|
||||
|
||||
Log::flush();
|
||||
|
||||
if let Permissible::Block = permissability {
|
||||
|
||||
|
||||
if let BotMsgType::SayInReplyTo(a, _) = msginput {
|
||||
|
||||
// self.say_in_reply_to(
|
||||
// a,
|
||||
// format!("uuh you don't have special privileges in {}",
|
||||
// channel_login.clone()
|
||||
// ),
|
||||
// params.clone()
|
||||
// ).await;
|
||||
|
||||
}
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
let rl = Arc::clone(&self.ratelimiters);
|
||||
let mut rllock = rl.lock().await;
|
||||
|
||||
|
|
|
@ -8,11 +8,9 @@ use twitch_irc::message::PrivmsgMessage;
|
|||
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::BotAction;
|
||||
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager};
|
||||
|
||||
use dotenv::dotenv;
|
||||
|
@ -70,10 +68,8 @@ 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(params : ExecBodyParams) {
|
||||
botlog::trace(
|
||||
"Called cmd promote",
|
||||
|
@ -107,22 +103,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
[x] Get the parent module
|
||||
*/
|
||||
|
||||
// let params_clone = Arc::clone(¶ms.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(
|
||||
format!("Twich Message > {}", params.msg.message_text).as_str(),
|
||||
|
@ -200,7 +180,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
None => {
|
||||
botlog::debug(
|
||||
// &format!("No Targer User argument"),
|
||||
"No Targer User argument",
|
||||
Some("identity.rs > cmd_demote()".to_string()),
|
||||
None,
|
||||
|
@ -240,24 +219,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
).await;
|
||||
|
||||
|
||||
// // Only call Say if there is a parent module passed
|
||||
// if parent_module.is_some() {
|
||||
|
||||
|
||||
// botlock
|
||||
// .botmgrs
|
||||
// .chat
|
||||
// .say_in_reply_to(
|
||||
// ¶ms.msg,
|
||||
// outmsg.to_string(),
|
||||
// // parent_module.unwrap().clone()
|
||||
// params.clone(),
|
||||
// ).await;
|
||||
|
||||
// }
|
||||
|
||||
botlog::trace(
|
||||
// &format!("End of cmd_promote()"),
|
||||
"End of cmd_promote()",
|
||||
Some("identity.rs > cmd_prommote()".to_string()),
|
||||
None,
|
||||
|
@ -278,11 +240,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
],
|
||||
};
|
||||
|
||||
// tempb.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||
// 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(params : ExecBodyParams) {
|
||||
botlog::debug(
|
||||
"Called cmd demote",
|
||||
|
@ -317,23 +276,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
[x] Get the parent module
|
||||
*/
|
||||
|
||||
// let params_clone = Arc::clone(¶ms.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
|
||||
|
||||
let (arg1, _arg2) = {
|
||||
|
@ -413,7 +355,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
let rslt = match targetusr {
|
||||
Some(targetusr) => {
|
||||
botlog::debug(
|
||||
// &format!("running demote()"),
|
||||
"running demote()",
|
||||
Some("identity.rs > cmd_demote()".to_string()),
|
||||
None,
|
||||
|
@ -432,7 +373,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
None => {
|
||||
botlog::debug(
|
||||
// &format!("No Targer User argument"),
|
||||
"No Targer User argument",
|
||||
Some("identity.rs > cmd_demote()".to_string()),
|
||||
None,
|
||||
|
@ -474,23 +414,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
).await;
|
||||
|
||||
|
||||
// // Only call Say if there is a parent module passed
|
||||
// if parent_module.is_some() {
|
||||
|
||||
// botlock
|
||||
// .botmgrs
|
||||
// .chat
|
||||
// .say_in_reply_to(
|
||||
// ¶ms.msg,
|
||||
// outmsg.to_string(),
|
||||
// // parent_module.unwrap().clone()
|
||||
// params.clone()
|
||||
// ).await;
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
let tempcomm = BotCommand {
|
||||
|
@ -507,11 +430,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
],
|
||||
};
|
||||
|
||||
// tempcomm.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||
// add_core_to_modmgr
|
||||
tempcomm.add_core_to_modmgr(Arc::clone(&mgr)).await;
|
||||
|
||||
// async fn getroles(bot: BotAR, msg: PrivmsgMessage) {
|
||||
async fn getroles(params : ExecBodyParams) {
|
||||
botlog::debug(
|
||||
"Called cmd getroles",
|
||||
|
@ -527,20 +447,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
*/
|
||||
|
||||
/*
|
||||
[x] Get the parent module
|
||||
*/
|
||||
|
||||
// let params_clone = Arc::clone(¶ms.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(' ');
|
||||
|
||||
|
@ -613,7 +519,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
);
|
||||
|
||||
botlog::trace(
|
||||
// &format!("Evaluating special roles"),
|
||||
"Evaluating special roles",
|
||||
Some("identity.rs > init > getroles()".to_string()),
|
||||
Some(¶ms.msg),
|
||||
|
@ -659,17 +564,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
params.clone(),
|
||||
).await;
|
||||
|
||||
// if parent_module.is_some() {
|
||||
|
||||
// botlock.botmgrs.chat.say_in_reply_to(
|
||||
// ¶ms.msg,
|
||||
// outmsg,
|
||||
// // parent_module.unwrap().clone()
|
||||
// params.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
|
||||
}
|
||||
|
@ -716,13 +610,6 @@ pub enum ChatBadge {
|
|||
Mod,
|
||||
}
|
||||
|
||||
// #[derive(Debug, PartialEq, Eq)]
|
||||
// pub enum ChangeResult {
|
||||
// Success(String),
|
||||
// Failed(String),
|
||||
// NoChange(String),
|
||||
// }
|
||||
|
||||
impl IdentityManager {
|
||||
pub fn init() -> IdentityManager {
|
||||
let mut a = HashMap::new();
|
||||
|
@ -790,7 +677,6 @@ impl IdentityManager {
|
|||
botlog::trace(
|
||||
"Checking within PRVMSG",
|
||||
Some("identity.rs > can_user_run_PRVMSG()".to_string()),
|
||||
// Some(&msg),
|
||||
Some(msg),
|
||||
);
|
||||
|
||||
|
@ -806,7 +692,6 @@ impl IdentityManager {
|
|||
|
||||
self.can_user_run(
|
||||
msg.sender.name.to_owned(),
|
||||
// Channel::construct(msg.channel_login.to_owned()),
|
||||
Channel(msg.channel_login.to_owned()),
|
||||
sender_badge,
|
||||
cmdreqroles,
|
||||
|
@ -822,7 +707,6 @@ impl IdentityManager {
|
|||
chat_badge: Option<ChatBadge>,
|
||||
cmdreqroles: Vec<UserRole>, // ) -> Result<Permissible,Box<dyn Error>> {
|
||||
) -> (Permissible, ChangeResult) {
|
||||
// println!{"Checking within can_user_run()"};
|
||||
botlog::debug(
|
||||
&format!(
|
||||
"Checking within can_user_run() :
|
||||
|
@ -869,8 +753,6 @@ impl IdentityManager {
|
|||
|
||||
// [x] If cmdreqroles is empty vector , automatically assume Ok(Permissible::Allow)
|
||||
|
||||
// let idar = Arc::new(RwLock::new(self));
|
||||
|
||||
let usr = usr.to_lowercase();
|
||||
|
||||
|
||||
|
@ -891,9 +773,7 @@ impl IdentityManager {
|
|||
);
|
||||
}
|
||||
|
||||
// if cmdreqroles.len() == 0 {
|
||||
if cmdreqroles.is_empty() {
|
||||
// return Ok(Permissible::Allow)
|
||||
return (
|
||||
Permissible::Allow,
|
||||
ChangeResult::NoChange("Command has no required cmdreqroles".to_string()),
|
||||
|
@ -907,10 +787,6 @@ impl IdentityManager {
|
|||
// [x] and cmdreqroles includes UserRole::Broadcaster , Ok(Permissible::Allow)
|
||||
// [x] and cmdreqroles includes UserRole::Mod("") OR UserRole::SupMod("") , Ok(Permissible::Allow)
|
||||
Some(ChatBadge::Broadcaster) => {
|
||||
// if cmdreqroles.contains(&UserRole::Broadcaster)
|
||||
// || cmdreqroles.contains(&UserRole::Mod(Channel::construct(String::new())))
|
||||
// || cmdreqroles.contains(&UserRole::SupMod(Channel::construct(String::new())))
|
||||
// {
|
||||
if cmdreqroles.contains(&UserRole::Broadcaster)
|
||||
|| cmdreqroles.contains(&UserRole::Mod(Channel(String::new())))
|
||||
|| cmdreqroles.contains(&UserRole::SupMod(Channel(String::new())))
|
||||
|
@ -982,7 +858,6 @@ impl IdentityManager {
|
|||
None,
|
||||
);
|
||||
|
||||
// if cmdreqroles.contains(&UserRole::Mod(Channel::construct(String::new()))) {
|
||||
if cmdreqroles.contains(&UserRole::Mod(Channel(String::new()))) {
|
||||
botlog::trace(
|
||||
"Command requires Mod Role",
|
||||
|
@ -1019,7 +894,6 @@ impl IdentityManager {
|
|||
|
||||
// [x] If cmdreqroles includes UserRole::SupMod("") , checks if chatter has UserRole::SupMod(channelname::ChType) to determine if Ok(Permissible::Allow)
|
||||
|
||||
// if cmdreqroles.contains(&UserRole::SupMod(Channel::construct(String::new()))) {
|
||||
if cmdreqroles.contains(&UserRole::SupMod(Channel(String::new()))) {
|
||||
if let Some(a) = self
|
||||
.special_roles_users
|
||||
|
@ -1564,7 +1438,6 @@ mod core_identity {
|
|||
let test_id_mgr = IdentityManager::init();
|
||||
|
||||
// [x] Broadcaster Promotes Chatter to SupMod
|
||||
// let channel = Some(Channel::construct("broadcasterer".to_string()));
|
||||
let channel = Some(Channel("broadcasterer".to_string()));
|
||||
let trgchatter = "regularChatter".to_string();
|
||||
let authorizer_badge = &Some(ChatBadge::Broadcaster);
|
||||
|
@ -1644,7 +1517,6 @@ mod core_identity {
|
|||
|
||||
let broadcaster = "broadcasterer".to_string();
|
||||
let broadcaster_badge = &Some(ChatBadge::Broadcaster);
|
||||
// let channel = Some(ChType::Channel(broadcaster.clone()));
|
||||
let channel = Channel(broadcaster.clone());
|
||||
let supchatter = "superModerator".to_string();
|
||||
let trg_role = None;
|
||||
|
@ -1687,7 +1559,6 @@ mod core_identity {
|
|||
|
||||
// [x] SupMod Attempts to Promote Chatter to SupMod
|
||||
|
||||
// let broadcaster = "broadcasterer".to_string();
|
||||
let authorizer = supchatter;
|
||||
let authorizer_badge = &Some(ChatBadge::Broadcaster);
|
||||
let channel = Some(Channel(broadcaster.clone()));
|
||||
|
@ -1758,7 +1629,6 @@ mod core_identity {
|
|||
|
||||
// [x] SupMod Attempts to Promote Chatter to SupMod
|
||||
|
||||
// let broadcaster = "broadcasterer".to_string();
|
||||
let authorizer = botadmin;
|
||||
let authorizer_badge = botadmin_badge;
|
||||
let channel = Some(Channel("somechannel".to_string()));
|
||||
|
|
|
@ -13,16 +13,11 @@
|
|||
use rand::Rng;
|
||||
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;
|
||||
|
||||
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::*;
|
||||
|
@ -62,18 +57,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
// 2. Add the BotAction to ModulesManager
|
||||
list1.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||
|
||||
|
||||
// // 1. Define the BotAction
|
||||
// let list1 = Listener {
|
||||
// module: BotModule(String::from("experiments001")),
|
||||
// name: String::from("babygirl Listener"),
|
||||
// exec_body: actions_util::asyncbox(babygirl),
|
||||
// help: String::from(""),
|
||||
// };
|
||||
|
||||
// // 2. Add the BotAction to ModulesManager
|
||||
// list1.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||
|
||||
// 1. Define the BotAction
|
||||
let botc1 = BotCommand {
|
||||
module: BotModule(String::from("experiments001")),
|
||||
|
@ -112,21 +95,7 @@ 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(¶ms.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;
|
||||
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)
|
||||
|
@ -134,7 +103,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
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",
|
||||
|
@ -163,30 +131,14 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
.say_in_reply_to(
|
||||
¶ms.msg,
|
||||
String::from("GoodGirl xdd "),
|
||||
// parent_module.unwrap().clone()
|
||||
params.clone()
|
||||
).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(
|
||||
// ¶ms.msg,
|
||||
// String::from("GoodGirl xdd "),
|
||||
// // parent_module.unwrap().clone()
|
||||
// params.clone()
|
||||
// ).await;
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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(
|
||||
|
@ -197,26 +149,8 @@ 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(¶ms.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(
|
||||
|
@ -231,8 +165,6 @@ async fn babygirl(params : ExecBodyParams) {
|
|||
let botlock = bot.read().await;
|
||||
|
||||
|
||||
|
||||
// uses chat.say_in_reply_to() for the bot controls for messages
|
||||
botlock
|
||||
.botmgrs
|
||||
.chat
|
||||
|
@ -268,54 +200,9 @@ async fn babygirl(params : ExecBodyParams) {
|
|||
|
||||
|
||||
|
||||
// if parent_module.is_some() {
|
||||
|
||||
// // uses chat.say_in_reply_to() for the bot controls for messages
|
||||
// botlock
|
||||
// .botmgrs
|
||||
// .chat
|
||||
// .say_in_reply_to(
|
||||
// ¶ms.msg,
|
||||
// String::from("16:13 notohh: cafdk"),
|
||||
// // parent_module.clone().unwrap().clone()
|
||||
// params.clone()
|
||||
// ).await;
|
||||
|
||||
|
||||
// sleep(Duration::from_secs_f64(0.5)).await;
|
||||
|
||||
// botlock
|
||||
// .botmgrs
|
||||
// .chat
|
||||
// .say_in_reply_to(
|
||||
// ¶ms.msg,
|
||||
// String::from("16:13 notohh: have fun eating princess"),
|
||||
// // parent_module.clone().unwrap().clone()
|
||||
// params.clone()
|
||||
// ).await;
|
||||
|
||||
|
||||
// sleep(Duration::from_secs_f64(2.0)).await;
|
||||
|
||||
// botlock
|
||||
// .botmgrs
|
||||
// .chat
|
||||
// .say_in_reply_to(
|
||||
// ¶ms.msg,
|
||||
// String::from("16:13 notohh: baby girl"),
|
||||
// // parent_module.unwrap().clone()
|
||||
// params.clone()
|
||||
// ).await;
|
||||
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 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(
|
||||
|
|
|
@ -10,30 +10,22 @@
|
|||
|
||||
*/
|
||||
|
||||
// use rand::Rng;
|
||||
use std::sync::Arc;
|
||||
|
||||
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;
|
||||
use crate::core::botlog;
|
||||
// use crate::core::botmodules::BotAction;
|
||||
|
||||
use casual_logger::Log;
|
||||
|
||||
use crate::core::bot_actions::actions_util;
|
||||
// use crate::core::bot_actions::BotAR;
|
||||
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager};
|
||||
|
||||
use crate::core::identity::UserRole::*;
|
||||
|
||||
// use tokio::time::{sleep, Duration};
|
||||
|
||||
pub async fn init(mgr: Arc<ModulesManager>) {
|
||||
|
||||
const OF_CMD_CHANNEL:Channel = Channel(String::new());
|
||||
|
@ -57,16 +49,13 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
// 2. Add the BotAction to ModulesManager
|
||||
botc1.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||
|
||||
// If enabling by defauling at instance level
|
||||
mgr.set_instance_enabled(BotModule(String::from("experiments002"))).await;
|
||||
|
||||
// [ ] #TODO - FOR SOME REASON, IF DISABLED BY DEFAULT, IT OVERFLOWS at RUNGTIME
|
||||
// If enabling by defauling at instance level , uncomment the following
|
||||
// mgr.set_instance_enabled(BotModule(String::from("experiments002"))).await;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// async fn sayout(bot: BotAR, msg: PrivmsgMessage) {
|
||||
async fn sayout(params : ExecBodyParams) {
|
||||
|
||||
|
||||
|
@ -77,32 +66,16 @@ async fn sayout(params : ExecBodyParams) {
|
|||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
[x] Get the parent module
|
||||
*/
|
||||
|
||||
let parent_module = params.get_parent_module().await;
|
||||
|
||||
|
||||
|
||||
let reply_parent = if let Some(Some(reply)) = params.msg.source.tags.0.get("reply-parent-msg-body") {
|
||||
Some(reply)
|
||||
} else { None }
|
||||
;
|
||||
|
||||
|
||||
// let reply_parent_usr = if let Some(Some(reply)) = msg.source.tags.0.get("reply-thread-parent-user-login") {
|
||||
// Some(reply)
|
||||
// } else { None }
|
||||
// ;
|
||||
|
||||
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();
|
||||
// println!("Output : {}",b.to_string());
|
||||
// println!("Formatted : {}",b.format("%m-%d %H:%M") );
|
||||
Some(b.format("%m-%d %H:%M"))
|
||||
} else { None }
|
||||
;
|
||||
|
@ -145,35 +118,6 @@ async fn sayout(params : ExecBodyParams) {
|
|||
None,
|
||||
);
|
||||
|
||||
// // if botlock.botmgrs.chat.client.get_channel_status(trgchnl.to_string().clone()).await == (false,false) {
|
||||
// if !botlock.bot_channels.contains(&Channel(trgchnl.to_lowercase().to_string().clone())) {
|
||||
|
||||
// // in the case where the provided channel isn't something we're known to be connected to
|
||||
// botlog::warn(
|
||||
// &format!("A message attempted to send for a Non-Joined Channel : {}",trgchnl.to_string().clone()),
|
||||
// Some("Chat > send_botmsg".to_string()),
|
||||
// None,
|
||||
// );
|
||||
// // return ;
|
||||
|
||||
// if parent_module.clone().is_some() {
|
||||
|
||||
|
||||
// botlock
|
||||
// .botmgrs
|
||||
// .chat
|
||||
// .say_in_reply_to(
|
||||
// ¶ms.msg,
|
||||
// format!("Not a Joined Channel : {}",trgchnl),
|
||||
// // parent_module.clone().unwrap().clone()
|
||||
// params.clone(),
|
||||
// ).await;
|
||||
|
||||
// }
|
||||
|
||||
|
||||
// }
|
||||
|
||||
/*
|
||||
1. If a Reply ,
|
||||
[ ] Get Parent Content message - reply_parent
|
||||
|
@ -194,48 +138,26 @@ async fn sayout(params : ExecBodyParams) {
|
|||
|
||||
let newoutmsg = if let Some(srcmsg) = reply_parent {
|
||||
|
||||
// format!("{} from #{} says {} . Replying to: {} : {}",
|
||||
// msg.sender.name,msg.channel_login,outmsg, reply_parent_usr.unwrap(),srcmsg)
|
||||
// format!("{} from #{} says {} @ {} {} : {}",
|
||||
// msg.sender.name,
|
||||
// msg.channel_login,
|
||||
// outmsg,
|
||||
// reply_parent_ts.unwrap(),
|
||||
// reply_parent_usr.unwrap(),
|
||||
// srcmsg)
|
||||
format!("{} {} @ {} : {}",
|
||||
reply_parent_ts.unwrap(),
|
||||
params.msg.sender.name,
|
||||
params.msg.channel_login,
|
||||
srcmsg)
|
||||
} else {
|
||||
// format!("{} from #{} says : {}",
|
||||
// msg.sender.name,
|
||||
// msg.channel_login,
|
||||
// outmsg)
|
||||
format!("in {} - {} : {}",
|
||||
params.msg.channel_login,
|
||||
params.msg.sender.name,
|
||||
outmsg)
|
||||
};
|
||||
|
||||
|
||||
if parent_module.clone().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()
|
||||
params.clone(),
|
||||
).await;
|
||||
|
||||
}
|
||||
|
||||
botlock
|
||||
.botmgrs
|
||||
.chat
|
||||
.say(
|
||||
trgchnl.to_string(),
|
||||
newoutmsg.to_string(),
|
||||
params.clone(),
|
||||
).await;
|
||||
|
||||
|
||||
},
|
||||
|
@ -257,30 +179,13 @@ async fn sayout(params : ExecBodyParams) {
|
|||
.say_in_reply_to(
|
||||
¶ms.msg,
|
||||
String::from("Invalid arguments"),
|
||||
// parent_module.unwrap().clone()
|
||||
params.clone()
|
||||
).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(
|
||||
// ¶ms.msg,
|
||||
// String::from("Invalid arguments"),
|
||||
// // parent_module.unwrap().clone()
|
||||
// params.clone()
|
||||
// ).await;
|
||||
|
||||
// }
|
||||
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
|
||||
Log::flush();
|
||||
}
|
Loading…
Reference in a new issue