diff --git a/irc-stream b/irc-stream index bf53e62..455c49d 160000 --- a/irc-stream +++ b/irc-stream @@ -1 +1 @@ -Subproject commit bf53e62f1713dfe83198f75992cc0e889de398ff +Subproject commit 455c49dbb237b98c89692b46869ecb22cca8d0f5 diff --git a/src/main.rs b/src/main.rs index 68ef1cb..0d2c84d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,9 @@ use std::{ io::Read, net::TcpStream, collections::VecDeque, + thread, + time, + sync::mpsc::channel, }; use irc_proto::command::{ CapSubCommand, @@ -175,13 +178,23 @@ fn main() { } let mut message_queue = get_irc_identify_messages(&config).unwrap(); - message_queue = get_irc_join_messages(&config, message_queue).unwrap(); while let Some(message) = message_queue.pop_front() { - println!("Sending: {}", message.clone().to_string()); stream.write(message).unwrap(); } + message_queue = get_irc_join_messages(&config, message_queue).unwrap(); + + //TODO remove this botch + let (tx, rx) = channel(); + thread::spawn(move|| { + thread::sleep(time::Duration::from_secs(10)); + while let Some(message) = message_queue.pop_front() { + println!("Sending: {}", message.clone().to_string()); + tx.send(message).unwrap(); + } + }); + loop { let message = match stream.read() { Ok(m) => m, @@ -210,6 +223,10 @@ fn main() { ), _ => println!("{}", message.clone().to_string()) } + match rx.try_recv() { + Ok(m) => stream.write(m).unwrap(), + Err(_e) => () + } } }