diff --git a/.gitignore b/.gitignore index f044ebe..596273a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ target/ # Dont track the client config config.toml +config/ diff --git a/src/main.rs b/src/main.rs index e4a1347..fc7db93 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,6 @@ pub mod connect; pub mod config; use std::{ - format, env::args, path::PathBuf, collections::VecDeque, @@ -117,7 +116,7 @@ fn get_irc_join_messages(config: &Value, queue: VecDeque) Ok(queue) } -fn handle_message(message: Message) -> (Option, Option<[String; 4]>) { +fn handle_message(message: Message) -> (Option, Option<[String; 3]>) { let sender = match message.clone().source_nickname() { Some(s) => String::from(s), None => String::from("anonymous") @@ -131,12 +130,9 @@ fn handle_message(message: Message) -> (Option, Option<[String; 4]>) { None ); }, - Command::PRIVMSG(ref rec, ref msg) => println!( - "{} -> {}: {}", - rec, - msg, - sender - ), + Command::PRIVMSG(ref rec, ref msg) => { + return (None, Some([rec.clone(), sender.clone(), msg.clone()])) + }, _ => println!("{}", message.clone().to_string()) } return (None, None) @@ -144,8 +140,9 @@ fn handle_message(message: Message) -> (Option, Option<[String; 4]>) { fn handle_server(config: Value, tx: Sender<[String; 4]>) -> Result<(), Box> { + let server_name = config.get("server").unwrap().as_str() + .ok_or("Could not get server adress from config")?; let mut stream = connect::connect_irc(&config).unwrap(); - let mut message_queue = get_irc_identify_messages(&config).unwrap(); while let Some(message) = message_queue.pop_front() { @@ -180,7 +177,16 @@ fn handle_server(config: Value, tx: Sender<[String; 4]>) None => () } match data { - Some(d) => tx.send(d)?, + Some(d) => { + // There must be a better way to do this… + let d = [ + server_name.to_owned(), + d[0].clone(), + d[1].clone(), + d[2].clone() + ]; + tx.send(d)? + }, None => (), } }