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
|
||||
config.toml
|
||||
config/
|
||||
|
|
26
src/main.rs
26
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<Message>)
|
|||
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() {
|
||||
Some(s) => String::from(s),
|
||||
None => String::from("anonymous")
|
||||
|
@ -131,12 +130,9 @@ fn handle_message(message: Message) -> (Option<Message>, 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<Message>, Option<[String; 4]>) {
|
|||
|
||||
fn handle_server(config: Value, tx: Sender<[String; 4]>)
|
||||
-> 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 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 => (),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue