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>,
|
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,7 +51,10 @@ 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
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match msginput.clone() {
|
||||||
|
BotMsgType::SayInReplyTo(msg, _) => {
|
||||||
self.client.say_in_reply_to(msg, outmsg).await.unwrap();
|
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
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if let BotMsgType::SayInReplyTo(msg,_ ) = msginput {
|
||||||
botlog::trace(
|
botlog::trace(
|
||||||
logstr.as_str(),
|
logstr.as_str(),
|
||||||
Some("Chat > say_in_reply_to".to_string()),
|
Some("Chat > say_in_reply_to".to_string()),
|
||||||
Some(msg),
|
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,9 +136,18 @@ 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) {
|
||||||
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
|
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue