aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTill Hoeppner2015-05-04 20:09:59 +0200
committerTill Hoeppner2015-05-04 20:09:59 +0200
commite1d4270acbb12306f5e30927b4f05ff2ff6c6937 (patch)
tree364025d9a7b5378eee6b7cf37734cd35dec2f0d6 /examples
parent4a092fd5ecccd1822c33702663701ad63953aa54 (diff)
downloadirsc-e1d4270acbb12306f5e30927b4f05ff2ff6c6937.tar.gz
irsc-e1d4270acbb12306f5e30927b4f05ff2ff6c6937.tar.xz
irsc-e1d4270acbb12306f5e30927b4f05ff2ff6c6937.zip
Add SSL connections and use them in the example
Diffstat (limited to 'examples')
-rw-r--r--examples/01.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/examples/01.rs b/examples/01.rs
index 345adba..595bc70 100644
--- a/examples/01.rs
+++ b/examples/01.rs
@@ -1,4 +1,5 @@
extern crate irsc;
+extern crate env_logger;
use std::borrow::ToOwned;
use std::borrow::Cow::*;
@@ -20,7 +21,12 @@ fn callback(server: &mut Client, msg: &Message) {
MsgType::Irc => format!("{} wrote: {}", from.nickname, bold(&content)),
MsgType::Ctcp => format!("{} emoted: {}", from.nickname, bold(&content["ACTION ".len()..]))
};
- server.send(PRIVMSG(to, Owned(response))).unwrap();
+
+ // only send to channels, to prevent recursion when we are pm'ed
+ // technically, there are other prefixes than '#', but ignoring them is fine
+ if to.starts_with("#") {
+ server.send(PRIVMSG(to, Owned(response))).unwrap();
+ }
},
_ => ()
}
@@ -34,8 +40,13 @@ fn callback(server: &mut Client, msg: &Message) {
}
fn main() {
+ env_logger::init().unwrap();
let mut s = Client::new();
- s.connect("irc.mozilla.org".to_owned(), 6667).unwrap();
+ if cfg!(feature = "ssl") {
+ s.connect_ssl("irc.mozilla.org".to_owned(), 6697).unwrap();
+ } else {
+ s.connect("irc.mozilla.org".to_owned(), 6667).unwrap();
+ }
s.send(NICK(Borrowed(NAME))).unwrap();
s.send(USER(Borrowed(NAME), Borrowed("*"), Borrowed("*"), Borrowed(DESC))).unwrap();