Version 0.2.0 #2
2 changed files with 17 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -9,3 +9,4 @@ target/
|
||||||
|
|
||||||
# Dont track the client config
|
# Dont track the client config
|
||||||
config.toml
|
config.toml
|
||||||
|
config/
|
||||||
|
|
26
src/main.rs
26
src/main.rs
|
@ -19,7 +19,6 @@ pub mod connect;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
format,
|
|
||||||
env::args,
|
env::args,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
collections::VecDeque,
|
collections::VecDeque,
|
||||||
|
@ -117,7 +116,7 @@ fn get_irc_join_messages(config: &Value, queue: VecDeque<Message>)
|
||||||
Ok(queue)
|
Ok(queue)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_message(message: Message) -> (Option<Message>, Option<[String; 4]>) {
|
fn handle_message(message: Message) -> (Option<Message>, Option<[String; 3]>) {
|
||||||
let sender = match message.clone().source_nickname() {
|
let sender = match message.clone().source_nickname() {
|
||||||
Some(s) => String::from(s),
|
Some(s) => String::from(s),
|
||||||
None => String::from("anonymous")
|
None => String::from("anonymous")
|
||||||
|
@ -131,12 +130,9 @@ fn handle_message(message: Message) -> (Option<Message>, Option<[String; 4]>) {
|
||||||
None
|
None
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
Command::PRIVMSG(ref rec, ref msg) => println!(
|
Command::PRIVMSG(ref rec, ref msg) => {
|
||||||
"{} -> {}: {}",
|
return (None, Some([rec.clone(), sender.clone(), msg.clone()]))
|
||||||
rec,
|
},
|
||||||
msg,
|
|
||||||
sender
|
|
||||||
),
|
|
||||||
_ => println!("{}", message.clone().to_string())
|
_ => println!("{}", message.clone().to_string())
|
||||||
}
|
}
|
||||||
return (None, None)
|
return (None, None)
|
||||||
|
@ -144,8 +140,9 @@ fn handle_message(message: Message) -> (Option<Message>, Option<[String; 4]>) {
|
||||||
|
|
||||||
fn handle_server(config: Value, tx: Sender<[String; 4]>)
|
fn handle_server(config: Value, tx: Sender<[String; 4]>)
|
||||||
-> Result<(), Box<dyn std::error::Error>> {
|
-> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
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 stream = connect::connect_irc(&config).unwrap();
|
||||||
|
|
||||||
let mut message_queue = get_irc_identify_messages(&config).unwrap();
|
let mut message_queue = get_irc_identify_messages(&config).unwrap();
|
||||||
|
|
||||||
while let Some(message) = message_queue.pop_front() {
|
while let Some(message) = message_queue.pop_front() {
|
||||||
|
@ -180,7 +177,16 @@ fn handle_server(config: Value, tx: Sender<[String; 4]>)
|
||||||
None => ()
|
None => ()
|
||||||
}
|
}
|
||||||
match data {
|
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 => (),
|
None => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue