2014-12-21 02:13:16 +01:00
|
|
|
extern crate irc;
|
|
|
|
|
|
|
|
use std::default::Default;
|
2015-02-21 16:18:53 +01:00
|
|
|
use std::thread::spawn;
|
2015-02-23 03:22:33 +01:00
|
|
|
use irc::client::prelude::*;
|
2014-12-21 02:13:16 +01:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let config = Config {
|
|
|
|
nickname: Some(format!("pickles")),
|
|
|
|
server: Some(format!("irc.fyrechat.net")),
|
|
|
|
channels: Some(vec![format!("#vana")]),
|
|
|
|
.. Default::default()
|
|
|
|
};
|
2016-01-03 11:39:44 +01:00
|
|
|
let server = IrcServer::from_config(config).unwrap();
|
2015-06-22 18:03:57 +02:00
|
|
|
// FIXME: if set_keepalive is stabilized, this can be readded.
|
2015-04-05 05:06:13 +02:00
|
|
|
// server.conn().set_keepalive(Some(5)).unwrap();
|
2015-02-24 16:14:44 +01:00
|
|
|
let server = server.clone();
|
2015-06-22 18:03:57 +02:00
|
|
|
let _ = spawn(move || {
|
2014-12-21 02:13:16 +01:00
|
|
|
server.identify().unwrap();
|
|
|
|
loop {
|
|
|
|
let mut quit = false;
|
|
|
|
for msg in server.iter() {
|
|
|
|
match msg {
|
2015-06-22 18:03:57 +02:00
|
|
|
Ok(msg) => {
|
2014-12-21 02:13:16 +01:00
|
|
|
print!("{}", msg.into_string());
|
2015-06-06 03:27:15 +02:00
|
|
|
match (&msg).into() {
|
2015-06-22 18:03:57 +02:00
|
|
|
Ok(Command::PRIVMSG(_, msg)) => if msg.contains("bye") {
|
|
|
|
server.send_quit("").unwrap()
|
2014-12-21 02:13:16 +01:00
|
|
|
},
|
2015-02-23 00:00:58 +01:00
|
|
|
Ok(Command::ERROR(ref msg)) if msg.contains("Quit") => quit = true,
|
2014-12-21 02:13:16 +01:00
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(_) => break,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if quit { break }
|
2015-02-24 16:14:44 +01:00
|
|
|
server.reconnect().unwrap();
|
2014-12-21 02:13:16 +01:00
|
|
|
server.identify().unwrap();
|
|
|
|
}
|
2015-06-22 18:03:57 +02:00
|
|
|
}).join();
|
2014-12-21 02:13:16 +01:00
|
|
|
}
|