aboutsummaryrefslogtreecommitdiffstats
path: root/examples/client.rs
blob: ba8c1de64bf7c0b51c8c895d373cc75e95e736e9 (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
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 on_msg = |message: &Message| {
		println!("{}", *message);
	};

	connection.run_loop(on_msg);
}