2014-12-08 21:00:10 +01:00
|
|
|
#![feature(slicing_syntax)]
|
2014-11-29 11:26:55 +01:00
|
|
|
extern crate irc;
|
|
|
|
|
2014-12-05 03:04:22 +01:00
|
|
|
use std::default::Default;
|
2014-11-29 11:26:55 +01:00
|
|
|
use std::io::timer::sleep;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::time::duration::Duration;
|
|
|
|
use irc::data::config::Config;
|
|
|
|
use irc::server::{IrcServer, Server};
|
|
|
|
use irc::server::utils::Wrapper;
|
|
|
|
|
|
|
|
fn main() {
|
2014-12-05 03:04:22 +01:00
|
|
|
let config = Config {
|
|
|
|
nickname: Some(format!("pickles")),
|
|
|
|
server: Some(format!("irc.fyrechat.net")),
|
|
|
|
channels: Some(vec![format!("#vana")]),
|
|
|
|
.. Default::default()
|
|
|
|
};
|
2014-12-02 01:27:30 +01:00
|
|
|
let irc_server = Arc::new(IrcServer::from_config(config).unwrap());
|
2014-11-29 11:26:55 +01:00
|
|
|
let irc_server2 = irc_server.clone();
|
|
|
|
// The wrapper provides us with methods like send_privmsg(...) and identify(...)
|
|
|
|
let server = Wrapper::new(&*irc_server);
|
|
|
|
server.identify().unwrap();
|
|
|
|
// Let's set up a loop that ignores timeouts, and reads perpetually.
|
|
|
|
// n.b. this shouldn't exit automatically if the connection closes.
|
|
|
|
spawn(proc() {
|
|
|
|
let mut iter = irc_server2.iter();
|
|
|
|
loop {
|
|
|
|
if let Some(msg) = iter.next() {
|
|
|
|
print!("{}", msg.into_string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
loop {
|
|
|
|
server.send_privmsg("#vana", "TWEET TWEET").unwrap();
|
|
|
|
sleep(Duration::seconds(10))
|
|
|
|
}
|
|
|
|
}
|