Restrict replies to published rate limit
Twitch notices in stdout
This commit is contained in:
parent
4d52772010
commit
8bfc2b9b8f
3 changed files with 229 additions and 70 deletions
src
58
src/main.rs
58
src/main.rs
|
@ -4,6 +4,8 @@ use twitch_irc::SecureTCPTransport;
|
|||
use twitch_irc::TwitchIRCClient;
|
||||
use twitch_irc::message::ServerMessage;
|
||||
use std::env;
|
||||
use std::time::Instant;
|
||||
use rand::Rng;
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn main() {
|
||||
|
@ -34,14 +36,63 @@ pub async fn main() {
|
|||
let (mut incoming_messages, client) =
|
||||
TwitchIRCClient::<SecureTCPTransport, StaticLoginCredentials>::new(config);
|
||||
|
||||
|
||||
// client.join("modulatingforcebot".to_owned()).unwrap();
|
||||
// client.say("modulatingforcebot".to_owned(), "Connected!".to_owned()).await.unwrap();
|
||||
|
||||
for chnl in botchannels {
|
||||
client.join(chnl.to_owned()).unwrap();
|
||||
// client.say(chnl.to_owned(), "Connected!".to_owned()).await.unwrap();
|
||||
client.say(chnl.to_owned(), "annytfLurk".to_owned()).await.unwrap();
|
||||
}
|
||||
|
||||
// Adding rate limit functionality to be under : https://dev.twitch.tv/docs/irc/#rate-limits
|
||||
|
||||
let mut ratelimittimer = false.to_owned();
|
||||
|
||||
let mut ratelimitstart = Instant::now();
|
||||
let mut ratelimitcounter = 0;
|
||||
|
||||
|
||||
let join_handle = tokio::spawn(async move {
|
||||
while let Some(message) = incoming_messages.recv().await {
|
||||
// Below can be used to debug if I want to capture all messages
|
||||
// println!("Received message: {:?}", message);
|
||||
|
||||
match message {
|
||||
ServerMessage::Notice(msg) => {
|
||||
if let Some(chnl) = msg.channel_login {
|
||||
println!("NOTICE : (#{}) {}", chnl, msg.message_text);
|
||||
}
|
||||
}
|
||||
ServerMessage::Privmsg(msg) => {
|
||||
println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
||||
if !ratelimittimer {
|
||||
println!("(#{}) > {}", msg.channel_login, "started rate limit timer");
|
||||
ratelimitstart = Instant::now();
|
||||
ratelimittimer = true;
|
||||
} else if ratelimittimer && ratelimitstart.elapsed().as_secs() < 30 && ratelimitcounter >= 20 {
|
||||
// skip iteration if rate limit is being reached
|
||||
println!("(#{}) > {}", msg.channel_login, "rate limit reached");
|
||||
continue;
|
||||
} else if ratelimitstart.elapsed().as_secs() >= 30 {
|
||||
println!("(#{}) > {}", msg.channel_login, "rate limit timer reset");
|
||||
ratelimittimer = false;
|
||||
ratelimitcounter = 0;
|
||||
}
|
||||
|
||||
let maxblanks = rand::thread_rng().gen_range(1..=5);
|
||||
let mut outmsg = "GotTrolled".to_owned();
|
||||
|
||||
for _i in 1..maxblanks {
|
||||
let blankspace: &str = "";
|
||||
outmsg.push_str(blankspace);
|
||||
}
|
||||
|
||||
client.say_in_reply_to(&msg,outmsg).await.unwrap();
|
||||
println!("(#{}) > {}", msg.channel_login, "rate limit counter increase");
|
||||
ratelimitcounter += 1;
|
||||
// client.say(msg.channel_login, "GotTrolled".to_owned()).await.unwrap();
|
||||
},
|
||||
ServerMessage::Whisper(msg) => {
|
||||
println!("(w) {}: {}", msg.sender.name, msg.message_text);
|
||||
|
@ -58,14 +109,7 @@ pub async fn main() {
|
|||
});
|
||||
|
||||
|
||||
// client.join("modulatingforcebot".to_owned()).unwrap();
|
||||
// client.say("modulatingforcebot".to_owned(), "Connected!".to_owned()).await.unwrap();
|
||||
|
||||
for chnl in botchannels {
|
||||
client.join(chnl.to_owned()).unwrap();
|
||||
// client.say(chnl.to_owned(), "Connected!".to_owned()).await.unwrap();
|
||||
client.say(chnl.to_owned(), "annytfLurk".to_owned()).await.unwrap();
|
||||
}
|
||||
|
||||
|
||||
join_handle.await.unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue