2017-06-25 11:24:10 +02:00
|
|
|
extern crate irc;
|
|
|
|
|
|
|
|
use std::default::Default;
|
|
|
|
use irc::error;
|
|
|
|
use irc::client::prelude::*;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let cfg1 = Config {
|
|
|
|
nickname: Some("pickles".to_owned()),
|
2018-07-10 04:15:08 +02:00
|
|
|
server: Some("irc.mozilla.org".to_owned()),
|
|
|
|
channels: Some(vec!["#rust-spam".to_owned()]),
|
2017-06-25 11:24:10 +02:00
|
|
|
..Default::default()
|
|
|
|
};
|
2018-01-28 01:03:49 +01:00
|
|
|
|
2017-06-25 11:24:10 +02:00
|
|
|
let cfg2 = Config {
|
2018-01-28 01:03:49 +01:00
|
|
|
nickname: Some("bananas".to_owned()),
|
2018-07-10 04:15:08 +02:00
|
|
|
server: Some("irc.mozilla.org".to_owned()),
|
|
|
|
channels: Some(vec!["#rust-spam".to_owned()]),
|
2017-06-25 11:24:10 +02:00
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
2018-01-28 01:03:49 +01:00
|
|
|
let configs = vec![cfg1, cfg2];
|
|
|
|
|
|
|
|
let mut reactor = IrcReactor::new().unwrap();
|
|
|
|
|
|
|
|
for config in configs {
|
2018-01-28 03:19:05 +01:00
|
|
|
// Immediate errors like failure to resolve the server's domain or to establish any connection will
|
2018-01-28 02:16:50 +01:00
|
|
|
// manifest here in the result of prepare_client_and_connect.
|
|
|
|
let client = reactor.prepare_client_and_connect(&config).unwrap();
|
|
|
|
client.identify().unwrap();
|
|
|
|
// Here, we tell the reactor to setup this client for future handling (in run) using the specified
|
2018-01-28 01:03:49 +01:00
|
|
|
// handler function process_msg.
|
2018-01-28 02:16:50 +01:00
|
|
|
reactor.register_client_with_handler(client, process_msg);
|
2018-01-28 01:03:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Runtime errors like a dropped connection will manifest here in the result of run.
|
|
|
|
reactor.run().unwrap();
|
2017-06-25 11:24:10 +02:00
|
|
|
}
|
|
|
|
|
2018-01-28 02:16:50 +01:00
|
|
|
fn process_msg(client: &IrcClient, message: Message) -> error::Result<()> {
|
2017-06-25 11:24:10 +02:00
|
|
|
print!("{}", message);
|
|
|
|
match message.command {
|
|
|
|
Command::PRIVMSG(ref target, ref msg) => {
|
|
|
|
if msg.contains("pickles") {
|
2018-01-28 02:16:50 +01:00
|
|
|
client.send_privmsg(target, "Hi!")?;
|
2017-06-25 11:24:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|