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",
|
||||
]
|
||||
|
||||
[[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
|
||||
|
@ -93,6 +96,52 @@ impl Chat {
|
|||
*/
|
||||
|
||||
|
||||
/*
|
||||
- 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 mut rllock = rl.lock().await;
|
||||
|
@ -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