rust-irc/examples/simple_cmd.rs

26 lines
875 B
Rust
Raw Normal View History

extern crate irc;
use std::default::Default;
use irc::client::prelude::*;
fn main() {
let config = Config {
nickname: Some(format!("pickles")),
alt_nicks: Some(vec![format!("bananas"), format!("apples")]),
server: Some(format!("irc.fyrechat.net")),
channels: Some(vec![format!("#vana")]),
.. Default::default()
};
2015-06-22 18:03:57 +02:00
let server = IrcServer::from_config(config).unwrap();
server.identify().unwrap();
for command in server.iter_cmd() {
2015-02-24 16:55:08 +01:00
// Use of unwrap() on the results of iter_cmd() is discouraged since response codes will be
// received as parsing errors when using this type of iterator.
2015-02-24 05:27:50 +01:00
if let Ok(Command::PRIVMSG(chan, msg)) = command { // Ignore errors.
if msg.contains("pickles") {
server.send_privmsg(&chan, "Hi!").unwrap();
}
}
}
}