First trash commit
This commit is contained in:
parent
66308f678f
commit
3e3821d835
1 changed files with 26 additions and 4 deletions
28
src/main.rs
28
src/main.rs
|
@ -135,6 +135,28 @@ fn get_irc_identify_messages (config: &Value)
|
||||||
Ok(queue)
|
Ok(queue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_irc_join_messages(config: &Value, queue: VecDeque<Message>)
|
||||||
|
-> Result<VecDeque<Message>, Box<dyn std::error::Error>> {
|
||||||
|
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() {
|
fn main() {
|
||||||
let config_path = args().nth(1)
|
let config_path = args().nth(1)
|
||||||
.expect("no config given");
|
.expect("no config given");
|
||||||
|
@ -153,13 +175,13 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut message_queue = get_irc_identify_messages(&config).unwrap();
|
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() {
|
while let Some(message) = message_queue.pop_front() {
|
||||||
|
println!("Sending: {}", message.clone().to_string());
|
||||||
stream.write(message).unwrap();
|
stream.write(message).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.flush().unwrap();
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let message = match stream.read() {
|
let message = match stream.read() {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
|
@ -186,7 +208,7 @@ fn main() {
|
||||||
msg,
|
msg,
|
||||||
sender
|
sender
|
||||||
),
|
),
|
||||||
_ => println!("Other message: {}", message.clone().to_string())
|
_ => println!("{}", message.clone().to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue