Exec Body Fn should be passed Parent BotAction
#43
3 changed files with 64 additions and 0 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -41,6 +41,17 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-recursion"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "30c5ef0ede93efbf733c1a727f3b6b5a1060bbedd5600183e66f6e4be4af0ec5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.77"
|
||||
|
@ -194,6 +205,7 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
|
|||
name = "forcebot_rs"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-recursion",
|
||||
"async-trait",
|
||||
"casual_logger",
|
||||
"chrono",
|
||||
|
|
|
@ -12,9 +12,11 @@ twitch-irc = "5.0.1"
|
|||
rand = { version = "0.8.5", features = [] }
|
||||
futures = "0.3"
|
||||
async-trait = "0.1.77"
|
||||
async-recursion = "1.1.0"
|
||||
casual_logger = "0.6.5"
|
||||
chrono = "0.4.35"
|
||||
|
||||
|
||||
[lib]
|
||||
name = "bot_lib"
|
||||
path = "src/lib.rs"
|
||||
|
|
|
@ -24,6 +24,9 @@ use tokio::time::{sleep, Duration};
|
|||
use super::bot_actions::ExecBodyParams;
|
||||
use super::botmodules::BotModule;
|
||||
|
||||
|
||||
use async_recursion::async_recursion;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Chat {
|
||||
pub ratelimiters: Arc<Mutex<HashMap<Channel, RateLimiter>>>, // used to limit messages sent per channel
|
||||
|
@ -92,6 +95,52 @@ impl Chat {
|
|||
[ ] !! => 03.24 - Somewhere around here, we should be validating module for target channel
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
- Use ModulesManager.modstatus
|
||||
|
||||
modstatus(&self, in_module: BotModule, in_chnl: Channel) -> StatusType
|
||||
|
||||
*/
|
||||
|
||||
let parent_module = params.get_parent_module().await;
|
||||
// let parent_module = parent_module.clone();
|
||||
|
||||
let botlock = params.bot.read().await;
|
||||
let modmgr = Arc::clone(&botlock.botmodules);
|
||||
let modstatus = (*modmgr).modstatus(
|
||||
parent_module.clone().expect("ERROR - Expected a module"),
|
||||
Channel(channel_login.clone())
|
||||
).await;
|
||||
|
||||
match modstatus {
|
||||
super::botmodules::StatusType::Enabled(_) => (),
|
||||
super::botmodules::StatusType::Disabled(_) => (),
|
||||
}
|
||||
|
||||
if let super::botmodules::StatusType::Disabled(lvl) = modstatus {
|
||||
// Note : At this point, chat was called in a channel where the parent module IS enabled
|
||||
// - this type of validation is done outside of Chat()
|
||||
// This though takes into account scenarios where we are targetting a different channel
|
||||
|
||||
if let BotMsgType::SayInReplyTo(a, _) = msginput {
|
||||
|
||||
self.say_in_reply_to(
|
||||
a,
|
||||
format!("uuh {:?} is disabled on {} : {:?}",
|
||||
parent_module.clone().unwrap(),
|
||||
channel_login.clone(),
|
||||
lvl
|
||||
),
|
||||
params.clone()
|
||||
).await;
|
||||
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
|
||||
let rl = Arc::clone(&self.ratelimiters);
|
||||
|
@ -170,6 +219,7 @@ impl Chat {
|
|||
|
||||
|
||||
// pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String) {
|
||||
#[async_recursion]
|
||||
pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) {
|
||||
|
||||
self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg) , params).await;
|
||||
|
|
Loading…
Reference in a new issue