This commit is contained in:
ModulatingForce 2024-04-02 23:35:20 -04:00
parent e3718688a7
commit b6a75f8d91
4 changed files with 50 additions and 17 deletions

View file

@ -207,13 +207,13 @@ impl BotInstance {
let msgtext = msg.message_text.clone();
dbg!("will spawn listener_main_prvmsg from runner",msgtext.clone());
dbg!("will spawn listener_main_prvmsg from runner",chrono::offset::Local::now(),msgtext.clone());
tokio::spawn( async move {
// let msgarc_c = msgarc.clone();
BotInstance::listener_main_prvmsg(botarc, &msg.clone()).await;
});
// BotInstance::listener_main_prvmsg(Arc::clone(&bot), &msg).await;
dbg!("completed spawn listener_main_prvmsg from runner", msgtext);
dbg!("completed spawn listener_main_prvmsg from runner",chrono::offset::Local::now(), msgtext);
}
ServerMessage::Whisper(msg) => {
botlog::debug(

View file

@ -1,6 +1,8 @@
use std::collections::HashMap;
use std::i8;
use std::sync::Arc;
use std::num::{self, Wrapping};
use std::num::{self, Saturating, Wrapping};
use std::time::Instant;
use chrono::NaiveDateTime;
use tokio::sync::{Mutex, RwLock};
@ -68,8 +70,9 @@ pub struct Chat {
// outqueue : Arc<RwLock<Vec<(BotMsgType,ExecBodyParams)>>>
outqueue : (Sender<(BotMsgType,ExecBodyParams)>,
Arc<RwLock<Receiver<(BotMsgType,ExecBodyParams)>>>),
// https://doc.rust-lang.org/std/num/struct.Wrapping.html
// https://doc.rust-lang.org/std/num/struct.Saturating.html
// spaceiter : Arc<Mutex<Wrapping<i64>>>,
spaceiter : Arc<Mutex<bool>>,
}
@ -92,7 +95,7 @@ impl Chat {
let r = Arc::new(RwLock::new(r));
// let spaceiter = Arc::new(Mutex::new(Wrapping(3)));
let spaceiter = Arc::new(Mutex::new(true));
let chat = Chat {
@ -100,7 +103,7 @@ impl Chat {
client,
// outqueue : Arc::new(RwLock::new(vec![])),
outqueue : (s,r.clone()),
// spaceiter ,
spaceiter ,
};
let chat_ar = Arc::new(RwLock::new(chat));
@ -679,21 +682,44 @@ impl Chat {
ratelimiter::LimiterResp::Allow => {
// let maxblanks = rand::thread_rng().gen_range(1..=20);
// let mut blanks_to_add_lock = self.spaceiter.lock().await;
// (*blanks_to_add_lock).0 += 1;
let chat_guard = chat_clone.read().await;
let mut blanks_to_add_lock = chat_guard.spaceiter.lock().await;
dbg!("Before blanks to add adjusted",*blanks_to_add_lock);
// *blanks_to_add_lock += 1;
*blanks_to_add_lock = if *blanks_to_add_lock { false } else { true };
dbg!("After blanks to add adjusted",*blanks_to_add_lock);
// for _i in 1..(*blanks_to_add_lock).0 {
let mut outmsg = outmsg;
// for i in 0..*blanks_to_add_lock+1 {
// dbg!("Processing blank spaces : ",i,*blanks_to_add_lock);
// // let blankspace: &str = " 󠀀";
// // let blankspace: &str = " .";
// let blankspace: &str = ".";
// outmsg.push_str(blankspace);
// }
// if i > 0 {
// // let blankspace: &str = " \u{e0000}";
// let blankspace: &str = " ";
// outmsg.push_str(blankspace);
// dbg!("Added 'blank' string",outmsg.clone(),blankspace);
// }
// };
// drop(blanks_to_add_lock);
// let blankspace: &str = " ";
// let (firstword,restofstr) = outmsg.split_once(' ');
outmsg = if let Some((firstword,restofstr)) = outmsg.split_once(' ') {
if *blanks_to_add_lock { format!("{} {}\u{e0000}",firstword,restofstr,) }
else { format!("{} {}",firstword,restofstr) }
} else { outmsg.clone() } ;
drop(blanks_to_add_lock);
dbg!("Area that used to add blanks to out message");
dbg!("Sending the following messag to chat > ", outmsg.clone());
dbg!("OUT MESSAGE TO CHAT > ", chrono::offset::Local::now(), outmsg.clone());
botlog::trace(
&format!("Out Message TO {} >> {}",channel_login.clone(),outmsg.clone()),
@ -708,7 +734,7 @@ impl Chat {
BotMsgType::Say(a, _) => {
chat_clone.read().await.client.say(a, outmsg.clone()).await.unwrap();
}
BotMsgType::Notif(outmsg) => {
BotMsgType::Notif(_) => {
chat_clone.read().await.client.say_in_reply_to(&params.read().await.msg, outmsg.clone()).await.unwrap();
}
}
@ -752,6 +778,11 @@ impl Chat {
Some("Chat > send_botmsg".to_string()),
None,
);
dbg!("Rate Limiter returned Sleep unexpetedly > Re-enqueueing message");
// [x] Need to Re-Enqueue the message , but needs to be controlled
chat_clone.read().await.send_botmsg_inner(msginput.clone(),params).await;
}
}

View file

@ -102,13 +102,15 @@ impl RateLimiter {
dbg!(matches!(rsp.clone(),LimiterResp::Allow));
// [-] Comment this area if removing Duplicate checking functionality
/* */
let rsp = if rl_guard.dupmsg(inmsg.clone()) && matches!(rsp,LimiterResp::Allow) {
//self.lastmsgdup = String::new();
// LimiterResp::Sleep(DUPMSG_MIN_SEND_S)
dbg!("Duplicate detected");
LimiterResp::Sleep(DUPMSG_MIN_SEND_S - rl_guard.lastmsgtimer.elapsed().as_secs_f64() + 0.1)
} else { rsp.clone() };
/* */
// => 04.02 - Don't update here
// // After Dup is checked, Set the lastmsgdup to latest message

View file

@ -158,7 +158,7 @@ async fn countdown_chnl_v1(params : ExecBodyParams) {
let routine_attr = vec![
// RoutineAttr::RunOnce
RoutineAttr::MaxIterations(10),
RoutineAttr::MaxIterations(5),
RoutineAttr::LoopDuration(Duration::from_secs(1))
];
// let exec_body = actions_util::asyncbox(rtestbody);