diff options
author | Till Hoeppner | 2015-06-28 18:51:59 +0200 |
---|---|---|
committer | Till Hoeppner | 2015-06-28 18:51:59 +0200 |
commit | efaa1d0aa77d6a583f71d0cfa2787369cbf112a5 (patch) | |
tree | 98caa4c0c895d6e7442597221da04606ba607798 | |
parent | 3f109c73d709c5d7641cb3cee792a09d114b1248 (diff) | |
download | irsc-efaa1d0aa77d6a583f71d0cfa2787369cbf112a5.tar.gz irsc-efaa1d0aa77d6a583f71d0cfa2787369cbf112a5.tar.xz irsc-efaa1d0aa77d6a583f71d0cfa2787369cbf112a5.zip |
Add example for event API
-rw-r--r-- | examples/02.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/02.rs b/examples/02.rs new file mode 100644 index 0000000..69c9d0f --- /dev/null +++ b/examples/02.rs @@ -0,0 +1,40 @@ +extern crate irsc; +extern crate openssl; + +use irsc::*; +use irsc::Command::*; +use irsc::Reply::*; + +use openssl::ssl::{ Ssl, SslContext, SslMethod }; + +fn main() { + let mut s = OwnedClient::new(); + let ssl = Ssl::new(&SslContext::new(SslMethod::Tlsv1).unwrap()).unwrap(); + s.connect_ssl("irc.rizon.net", 6697, ssl); + s.register("irsc", "irsc", "Testing for kori", None); + + let mut shared = s.into_shared(); + let _ = shared.commands() + .map(|(mut cl, msg, c)| { + if let PRIVMSG(to, content) = c { + let from = msg.ident().unwrap(); + let response = format!("{} told me: {}", from.nickname, color::bold(&content)); + + // only send to global channels, to prevent recursion when we are pm'ed + // technically, there are other prefixes than '#', but ignoring them is fine + if to.starts_with("#") && content.starts_with("irsc") { + cl.msg(&to, &response); + } + } + }); + + let _b = shared.replies() + .map(|(mut cl, _msg, r)| { + if let RPL_WELCOME(_) = r { + cl.join("#meep!", None); + } + }); + + // Dedicate this thread to listening and event processing + shared.listen_with_events(); +} |