2018-01-28 01:50:39 +01:00
|
|
|
extern crate irc;
|
|
|
|
|
|
|
|
use std::default::Default;
|
|
|
|
use irc::client::prelude::*;
|
|
|
|
|
|
|
|
// This example is meant to be a direct analogue to simple.rs using the reactor API.
|
|
|
|
fn main() {
|
|
|
|
let config = Config {
|
|
|
|
nickname: Some("pickles".to_owned()),
|
|
|
|
alt_nicks: Some(vec!["bananas".to_owned(), "apples".to_owned()]),
|
|
|
|
server: Some("irc.fyrechat.net".to_owned()),
|
|
|
|
channels: Some(vec!["#irc-crate".to_owned()]),
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
2018-01-28 02:00:04 +01:00
|
|
|
let mut reactor = IrcReactor::new().unwrap();
|
2018-06-08 21:00:49 +02:00
|
|
|
let client = reactor.prepare_client_and_connect(config).unwrap();
|
2018-01-28 02:16:50 +01:00
|
|
|
client.identify().unwrap();
|
2018-01-28 01:50:39 +01:00
|
|
|
|
2018-01-28 02:16:50 +01:00
|
|
|
reactor.register_client_with_handler(client, |client, message| {
|
2018-01-28 01:50:39 +01:00
|
|
|
print!("{}", message);
|
2018-01-28 02:00:04 +01:00
|
|
|
if let Command::PRIVMSG(ref target, ref msg) = message.command {
|
|
|
|
if msg.contains("pickles") {
|
2018-01-28 02:16:50 +01:00
|
|
|
client.send_privmsg(target, "Hi!")?;
|
2018-01-28 01:50:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
});
|
|
|
|
|
|
|
|
reactor.run().unwrap();
|
|
|
|
}
|