From 3e3821d835c084ca980db1d7402d14668c1db5cb Mon Sep 17 00:00:00 2001 From: Thelie Date: Tue, 4 May 2021 00:40:51 +0200 Subject: [PATCH] First trash commit --- src/main.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index a913402..68ef1cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -135,6 +135,28 @@ fn get_irc_identify_messages (config: &Value) Ok(queue) } +fn get_irc_join_messages(config: &Value, queue: VecDeque) + -> Result, Box> { + let mut queue = queue; + + match config.get("channels") { + Some(c) => { + for channel in c.as_array().ok_or("Could not parse channels.")? { + queue.push_back(Message::from( + Command::JOIN( + String::from(channel.as_str().ok_or("Could not parse one of the channels")?), + None, + None + ) + )) + } + }, + None => () + } + + Ok(queue) +} + fn main() { let config_path = args().nth(1) .expect("no config given"); @@ -153,13 +175,13 @@ 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(); } - stream.flush().unwrap(); - loop { let message = match stream.read() { Ok(m) => m, @@ -186,7 +208,7 @@ fn main() { msg, sender ), - _ => println!("Other message: {}", message.clone().to_string()) + _ => println!("{}", message.clone().to_string()) } } }