4d85b7932c
mutexes.
66 lines
2 KiB
Rust
66 lines
2 KiB
Rust
#![feature(if_let, slicing_syntax)]
|
|
extern crate irc;
|
|
|
|
use std::collections::HashMap;
|
|
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();
|
|
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(...)
|
|
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))
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "encode")]
|
|
fn config() -> Config {
|
|
Config {
|
|
owners: vec!("awe".into_string()),
|
|
nickname: "pickles".into_string(),
|
|
username: "pickles".into_string(),
|
|
realname: "pickles".into_string(),
|
|
password: "".into_string(),
|
|
server: "irc.fyrechat.net".into_string(),
|
|
port: 6667,
|
|
use_ssl: false,
|
|
encoding: format!("UTF-8"),
|
|
channels: vec!("#vana".into_string()),
|
|
options: HashMap::new(),
|
|
}
|
|
}
|
|
|
|
#[cfg(not(feature = "encode"))]
|
|
fn config() -> Config {
|
|
Config {
|
|
owners: vec!("awe".into_string()),
|
|
nickname: "pickles".into_string(),
|
|
username: "pickles".into_string(),
|
|
realname: "pickles".into_string(),
|
|
password: "".into_string(),
|
|
server: "irc.fyrechat.net".into_string(),
|
|
port: 6667,
|
|
use_ssl: false,
|
|
channels: vec!("#vana".into_string()),
|
|
options: HashMap::new(),
|
|
}
|
|
}
|