2023-11-29 22:11:12 -05:00
|
|
|
|
|
|
|
|
|
|
2023-10-22 08:35:09 -04:00
|
|
|
|
use twitch_irc::login::StaticLoginCredentials;
|
|
|
|
|
use twitch_irc::ClientConfig;
|
|
|
|
|
use twitch_irc::SecureTCPTransport;
|
|
|
|
|
use twitch_irc::TwitchIRCClient;
|
2023-11-28 03:08:55 -05:00
|
|
|
|
use twitch_irc::message::ServerMessage;
|
2023-11-28 01:49:51 -05:00
|
|
|
|
use std::env;
|
2023-11-28 23:13:43 -05:00
|
|
|
|
use std::time::Instant;
|
|
|
|
|
use rand::Rng;
|
2023-10-22 08:35:09 -04:00
|
|
|
|
|
2023-11-29 22:11:12 -05:00
|
|
|
|
// mod helpers;
|
|
|
|
|
|
2023-10-22 08:35:09 -04:00
|
|
|
|
#[tokio::main]
|
|
|
|
|
pub async fn main() {
|
2023-11-28 01:49:51 -05:00
|
|
|
|
let login_name = "modulatingforcebot".to_owned();
|
|
|
|
|
let oauth_token = env::var("access_token").unwrap().to_owned();
|
2023-10-22 08:35:09 -04:00
|
|
|
|
|
2023-11-28 03:08:55 -05:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Vector of channels to join
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
let mut botchannels = Vec::new();
|
|
|
|
|
/* botchannels.push(String::from("modulatingforcebot"));
|
|
|
|
|
botchannels.push(String::from("notohh"));
|
|
|
|
|
botchannels.push(String::from("modulatingforce"));
|
|
|
|
|
botchannels.push(String::from("secondsocksan"));
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
for chnl in env::var("bot_channels").unwrap().split(',') {
|
|
|
|
|
// println!("(Env Var # {})",chnl);
|
|
|
|
|
botchannels.push(String::from(chnl));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-10-22 08:35:09 -04:00
|
|
|
|
let config = ClientConfig::new_simple(
|
|
|
|
|
StaticLoginCredentials::new(login_name, Some(oauth_token))
|
|
|
|
|
);
|
|
|
|
|
let (mut incoming_messages, client) =
|
|
|
|
|
TwitchIRCClient::<SecureTCPTransport, StaticLoginCredentials>::new(config);
|
|
|
|
|
|
2023-11-28 23:13:43 -05:00
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
|
2023-10-22 08:35:09 -04:00
|
|
|
|
let join_handle = tokio::spawn(async move {
|
|
|
|
|
while let Some(message) = incoming_messages.recv().await {
|
2023-11-28 03:08:55 -05:00
|
|
|
|
// Below can be used to debug if I want to capture all messages
|
|
|
|
|
// println!("Received message: {:?}", message);
|
|
|
|
|
|
|
|
|
|
match message {
|
2023-11-28 23:13:43 -05:00
|
|
|
|
ServerMessage::Notice(msg) => {
|
|
|
|
|
if let Some(chnl) = msg.channel_login {
|
|
|
|
|
println!("NOTICE : (#{}) {}", chnl, msg.message_text);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-28 03:08:55 -05:00
|
|
|
|
ServerMessage::Privmsg(msg) => {
|
|
|
|
|
println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
2023-11-28 23:13:43 -05:00
|
|
|
|
if !ratelimittimer {
|
|
|
|
|
println!("(#{}) > {}", msg.channel_login, "started rate limit timer");
|
2023-11-29 02:15:11 -05:00
|
|
|
|
// ratelimitstart = Instant::now();
|
|
|
|
|
// ratelimittimer = true;
|
|
|
|
|
( ratelimittimer , ratelimitstart ) = ( true , Instant::now() );
|
2023-11-28 23:13:43 -05:00
|
|
|
|
} 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");
|
2023-11-29 02:15:11 -05:00
|
|
|
|
// ratelimittimer = false;
|
|
|
|
|
// ratelimitcounter = 0;
|
|
|
|
|
( ratelimittimer , ratelimitcounter ) = ( false , 0 ) ;
|
2023-11-28 23:13:43 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
2023-11-28 03:08:55 -05:00
|
|
|
|
},
|
|
|
|
|
ServerMessage::Whisper(msg) => {
|
|
|
|
|
println!("(w) {}: {}", msg.sender.name, msg.message_text);
|
|
|
|
|
},
|
|
|
|
|
ServerMessage::Join(msg) => {
|
|
|
|
|
println!("JOINED: {}", msg.channel_login);
|
|
|
|
|
},
|
|
|
|
|
ServerMessage::Part(msg) => {
|
|
|
|
|
println!("PARTED: {}", msg.channel_login);
|
|
|
|
|
},
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
2023-10-22 08:35:09 -04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-11-28 03:08:55 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-22 08:35:09 -04:00
|
|
|
|
|
|
|
|
|
join_handle.await.unwrap();
|
|
|
|
|
}
|