blob: 4363060e027ce9a280d6656fc124fbe78c01bf4c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
extern crate irc;
use std::io::stdio;
use irc::IrcClient;
use irc::msg::Message;
//use irc::msg::cmd;
fn main() {
let mut stderr = stdio::stderr();
let mut args = std::os::args().move_iter();
args.next();
let host = args.next().expect("No hostname passed");
let port: u16 = from_str(args.next().unwrap_or_else(|| { let _ = writeln!(stderr, "No port given. Assuming 6667."); "6667".to_string() }).as_slice())
.expect("Port must be a number");
drop(args);
let mut connection = IrcClient::connect(host.as_slice(), port, "rusty-irc".to_string(), "dremann".to_string(), "Zachary Dremann".to_string()).unwrap();
let sender = connection.sender();
let on_msg = |message: &Message| {
println!("{} {}", message.prefix, message.command);
};
spawn(proc() {
let mut stdin = stdio::stdin();
for line in stdin.lines() {
match line {
Ok(s) => {
match from_str(s.as_slice()) {
Some(msg) => sender.send(msg),
None => ()
}
}
Err(_) => break,
}
}
});
connection.run_loop(on_msg);
}
|