use std::net::TcpStream;
use std::thread;
use std::time::Duration;
use twitchchat::{Client, UserConfig};
use rand::prelude::*;
fn main() -> Result<(), Box<std::error::Error>> {
let (read, write) = {
let stream = TcpStream::connect(twitchchat::TWITCH_IRC_ADDRESS)?;
(stream.try_clone()?, stream)
};
let (read, write) = twitchchat::sync_adapters(read, write);
let conf = user_config();
let mut client = Client::new(read, write);
client.register(conf)?;
let _local = client.wait_for_ready()?;
let w = client.writer();
thread::spawn(move || {
const EMOTES: [&str; 9] = [
"Kappa",
"SMOrc",
"LUL",
"SeemsGood",
"HeyGuys",
"PogChamp",
"NotLikeThis",
"WutFace",
"ResidentSleeper",
];
let mut rng = thread_rng();
loop {
thread::sleep(Duration::from_secs(rng.gen_range(5, 10)));
let poop: Vec<_> = EMOTES.choose_multiple(&mut rng, 3).map(|s| *s).collect();
if w.send("museun", poop.join(" ")).is_err() {
return;
};
}
});
client.writer().join("museun")?;
client.run()?;
Ok(())
}
fn user_config() -> UserConfig {
let (nick, pass) = (var("MY_TWITCH_NICK"), var("MY_TWITCH_PASS"));
let config = UserConfig::builder()
.nick(nick)
.token(pass)
.membership()
.commands()
.tags();;
config.build().unwrap()
}
fn var(key: &str) -> String {
std::env::var(key).unwrap_or_else(|_| panic!("please set the env var `{}`", key))
}