reorg common say logic

This commit is contained in:
ModulatingForce 2024-03-23 12:14:51 -04:00
parent 45e3f02297
commit 2957f9462b

View file

@ -27,6 +27,14 @@ pub struct Chat {
pub client: TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>, pub client: TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>,
} }
#[derive(Clone)]
enum BotMsgType<'a> {
SayInReplyTo(&'a PrivmsgMessage,String),
_Say(String,String)
}
impl Chat { impl Chat {
pub fn init( pub fn init(
ratelimiters: HashMap<ChType, RateLimiter>, ratelimiters: HashMap<ChType, RateLimiter>,
@ -43,8 +51,11 @@ impl Chat {
self.ratelimiters.lock().await.insert(chnl, n); self.ratelimiters.lock().await.insert(chnl, n);
} }
pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, mut outmsg: String) {
/*
async fn send_botmsg(&self, msginput: BotMsgType<'_>) {
/*
formats message before sending to TwitchIRC formats message before sending to TwitchIRC
- [x] Custom String Formatting (e.g., adding random black spaces) - [x] Custom String Formatting (e.g., adding random black spaces)
@ -53,12 +64,21 @@ impl Chat {
*/ */
let (channel_login,mut outmsg) = match msginput.clone() {
BotMsgType::SayInReplyTo(msg, outmsg) => {
(msg.channel_login.clone(),outmsg)
},
_ => {
panic!("ISSUE : NOT IMPLEMENTED")
},
};
let rl = Arc::clone(&self.ratelimiters); let rl = Arc::clone(&self.ratelimiters);
let mut rllock = rl.lock().await; let mut rllock = rl.lock().await;
let contextratelimiter = rllock let contextratelimiter = rllock
// .get_mut() // .get_mut()
.get_mut(&Channel(String::from(&msg.channel_login))) .get_mut(&Channel(String::from(channel_login.clone())))
.expect("ERROR: Issue with Rate limiters"); .expect("ERROR: Issue with Rate limiters");
// Continue to check the limiter and sleep if required if the minimum is not reached // Continue to check the limiter and sleep if required if the minimum is not reached
@ -75,20 +95,38 @@ impl Chat {
outmsg.push_str(blankspace); outmsg.push_str(blankspace);
} }
self.client.say_in_reply_to(msg, outmsg).await.unwrap(); match msginput.clone() {
BotMsgType::SayInReplyTo(msg, _) => {
self.client.say_in_reply_to(msg, outmsg).await.unwrap();
},
_ => {
panic!("ISSUE : NOT IMPLEMENTED")
},
}
contextratelimiter.increment_counter(); contextratelimiter.increment_counter();
let logstr = format!( let logstr = format!(
"(#{}) > {} ; contextratelimiter : {:?}", "(#{}) > {} ; contextratelimiter : {:?}",
msg.channel_login, "rate limit counter increase", contextratelimiter channel_login.clone(), "rate limit counter increase", contextratelimiter
); );
botlog::trace( if let BotMsgType::SayInReplyTo(msg,_ ) = msginput {
logstr.as_str(), botlog::trace(
Some("Chat > say_in_reply_to".to_string()), logstr.as_str(),
Some(msg), Some("Chat > say_in_reply_to".to_string()),
); Some(&msg),
);
} else {
botlog::trace(
logstr.as_str(),
Some("Chat > say_in_reply_to".to_string()),
None,
);
}
} }
ratelimiter::LimiterResp::Skip => { ratelimiter::LimiterResp::Skip => {
// (); // do nothing otherwise // (); // do nothing otherwise
@ -98,7 +136,16 @@ impl Chat {
} }
} }
Log::flush();
Log::flush();
}
pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, outmsg: String) {
self.send_botmsg(BotMsgType::SayInReplyTo(msg, outmsg)).await;
} }
async fn _say(&self, _: String, _: String) { async fn _say(&self, _: String, _: String) {