chat.send validates target channel module status
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
This commit is contained in:
parent
958aeea48e
commit
6deac8e6c7
3 changed files with 64 additions and 0 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -41,6 +41,17 @@ dependencies = [
|
||||||
"libc",
|
"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]]
|
[[package]]
|
||||||
name = "async-trait"
|
name = "async-trait"
|
||||||
version = "0.1.77"
|
version = "0.1.77"
|
||||||
|
@ -194,6 +205,7 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
|
||||||
name = "forcebot_rs"
|
name = "forcebot_rs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"async-recursion",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"casual_logger",
|
"casual_logger",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|
|
@ -12,9 +12,11 @@ twitch-irc = "5.0.1"
|
||||||
rand = { version = "0.8.5", features = [] }
|
rand = { version = "0.8.5", features = [] }
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
async-trait = "0.1.77"
|
async-trait = "0.1.77"
|
||||||
|
async-recursion = "1.1.0"
|
||||||
casual_logger = "0.6.5"
|
casual_logger = "0.6.5"
|
||||||
chrono = "0.4.35"
|
chrono = "0.4.35"
|
||||||
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "bot_lib"
|
name = "bot_lib"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
|
@ -24,6 +24,9 @@ use tokio::time::{sleep, Duration};
|
||||||
use super::bot_actions::ExecBodyParams;
|
use super::bot_actions::ExecBodyParams;
|
||||||
use super::botmodules::BotModule;
|
use super::botmodules::BotModule;
|
||||||
|
|
||||||
|
|
||||||
|
use async_recursion::async_recursion;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Chat {
|
pub struct Chat {
|
||||||
pub ratelimiters: Arc<Mutex<HashMap<Channel, RateLimiter>>>, // used to limit messages sent per channel
|
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
|
[ ] !! => 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);
|
let rl = Arc::clone(&self.ratelimiters);
|
||||||
|
@ -170,6 +219,7 @@ impl Chat {
|
||||||
|
|
||||||
|
|
||||||
// pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String) {
|
// pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String) {
|
||||||
|
#[async_recursion]
|
||||||
pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) {
|
pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String , params : ExecBodyParams) {
|
||||||
|
|
||||||
self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg) , params).await;
|
self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg) , params).await;
|
||||||
|
|
Loading…
Reference in a new issue