2015-01-09 23:38:46 +01:00
|
|
|
#![allow(unstable)]
|
2014-12-21 02:13:16 +01:00
|
|
|
#![feature(slicing_syntax)]
|
|
|
|
extern crate irc;
|
|
|
|
|
|
|
|
use std::default::Default;
|
|
|
|
use std::sync::Arc;
|
2014-12-23 19:00:07 +01:00
|
|
|
use std::thread::Thread;
|
2015-01-13 08:39:59 +01:00
|
|
|
use irc::client::data::{Command, Config};
|
|
|
|
use irc::client::server::{IrcServer, Server};
|
|
|
|
use irc::client::server::utils::Wrapper;
|
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()
|
|
|
|
};
|
|
|
|
let irc_server = Arc::new(IrcServer::from_config(config).unwrap());
|
|
|
|
irc_server.conn().set_keepalive(Some(5)).unwrap();
|
|
|
|
// The wrapper provides us with methods like send_privmsg(...) and identify(...)
|
2015-01-09 23:38:46 +01:00
|
|
|
let _ = Thread::scoped(move || {
|
2014-12-21 02:13:16 +01:00
|
|
|
let server = Wrapper::new(&*irc_server);
|
|
|
|
server.identify().unwrap();
|
|
|
|
loop {
|
|
|
|
let mut quit = false;
|
|
|
|
for msg in server.iter() {
|
|
|
|
match msg {
|
|
|
|
Ok(msg) => {
|
|
|
|
print!("{}", msg.into_string());
|
|
|
|
match Command::from_message(&msg) {
|
|
|
|
Ok(Command::PRIVMSG(_, msg)) => if msg.contains("bye") {
|
|
|
|
server.send_quit("").unwrap()
|
|
|
|
},
|
|
|
|
Ok(Command::ERROR(msg)) if msg.contains("Quit") => quit = true,
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(_) => break,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if quit { break }
|
|
|
|
irc_server.reconnect().unwrap();
|
|
|
|
server.identify().unwrap();
|
|
|
|
}
|
2014-12-23 19:00:07 +01:00
|
|
|
}).join();
|
2014-12-21 02:13:16 +01:00
|
|
|
}
|