reorg common say logic
This commit is contained in:
parent
45e3f02297
commit
2957f9462b
1 changed files with 59 additions and 12 deletions
|
@ -27,6 +27,14 @@ pub struct Chat {
|
|||
pub client: TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone)]
|
||||
enum BotMsgType<'a> {
|
||||
SayInReplyTo(&'a PrivmsgMessage,String),
|
||||
_Say(String,String)
|
||||
}
|
||||
|
||||
|
||||
impl Chat {
|
||||
pub fn init(
|
||||
ratelimiters: HashMap<ChType, RateLimiter>,
|
||||
|
@ -43,8 +51,11 @@ impl Chat {
|
|||
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
|
||||
|
||||
- [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 mut rllock = rl.lock().await;
|
||||
|
||||
let contextratelimiter = rllock
|
||||
// .get_mut()
|
||||
.get_mut(&Channel(String::from(&msg.channel_login)))
|
||||
.get_mut(&Channel(String::from(channel_login.clone())))
|
||||
.expect("ERROR: Issue with Rate limiters");
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
let logstr = format!(
|
||||
"(#{}) > {} ; contextratelimiter : {:?}",
|
||||
msg.channel_login, "rate limit counter increase", contextratelimiter
|
||||
channel_login.clone(), "rate limit counter increase", contextratelimiter
|
||||
);
|
||||
|
||||
botlog::trace(
|
||||
logstr.as_str(),
|
||||
Some("Chat > say_in_reply_to".to_string()),
|
||||
Some(msg),
|
||||
);
|
||||
if let BotMsgType::SayInReplyTo(msg,_ ) = msginput {
|
||||
botlog::trace(
|
||||
logstr.as_str(),
|
||||
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 => {
|
||||
// (); // 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) {
|
||||
|
|
Loading…
Reference in a new issue