rust-irc/examples/tweeter.rs

31 lines
1,020 B
Rust
Raw Normal View History

#![feature(slicing_syntax)]
extern crate irc;
use std::default::Default;
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() {
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());
let irc_server2 = irc_server.clone();
// The wrapper provides us with methods like send_privmsg(...) and identify(...)
2014-12-11 06:06:12 +01:00
let server = Wrapper::new(&*irc_server2);
server.identify().unwrap();
2014-12-11 06:06:12 +01:00
// Let's set up a loop that just prints the messages.
spawn(proc() { irc_server.iter().map(|m| print!("{}", m.into_string())).count(); });
loop {
server.send_privmsg("#vana", "TWEET TWEET").unwrap();
sleep(Duration::seconds(10))
}
}