Updated examples with ServerExt change.

This commit is contained in:
Aaron Weiss 2015-02-24 10:14:44 -05:00
parent 27839902ad
commit 8cf7471af2
7 changed files with 13 additions and 26 deletions

View file

@ -19,8 +19,7 @@ extern crate irc;
use irc::client::prelude::*; use irc::client::prelude::*;
fn main() { fn main() {
let irc_server = IrcServer::new("config.json").unwrap(); let server = IrcServer::new("config.json").unwrap();
let server = Wrapper::new(&irc_server);
server.identify().unwrap(); server.identify().unwrap();
for message in server.iter() { for message in server.iter() {
// Do message processing. // Do message processing.

View file

@ -12,11 +12,10 @@ fn main() {
channels: Some(vec![format!("#vana")]), channels: Some(vec![format!("#vana")]),
.. Default::default() .. Default::default()
}; };
let irc_server = Arc::new(IrcServer::from_config(config).unwrap()); let server = Arc::new(IrcServer::from_config(config).unwrap());
irc_server.conn().set_keepalive(Some(5)).unwrap(); server.conn().set_keepalive(Some(5)).unwrap();
// The wrapper provides us with methods like send_privmsg(...) and identify(...) let server = server.clone();
let _ = spawn(move || { let _ = spawn(move || {
let server = Wrapper::new(&*irc_server);
server.identify().unwrap(); server.identify().unwrap();
loop { loop {
let mut quit = false; let mut quit = false;
@ -36,7 +35,7 @@ fn main() {
} }
} }
if quit { break } if quit { break }
irc_server.reconnect().unwrap(); server.reconnect().unwrap();
server.identify().unwrap(); server.identify().unwrap();
} }
}).join(); }).join();

View file

@ -12,12 +12,9 @@ fn main() {
channels: Some(vec![format!("#vana")]), channels: Some(vec![format!("#vana")]),
.. Default::default() .. Default::default()
}; };
let irc_server = Arc::new(IrcServer::from_config(config).unwrap()); let server = Arc::new(IrcServer::from_config(config).unwrap());
// The wrapper provides us with methods like send_privmsg(...) and identify(...)
let server = Wrapper::new(&*irc_server);
server.identify().unwrap(); server.identify().unwrap();
let server = irc_server.clone(); let server = server.clone();
// We won't use a wrapper here because we don't need the added functionality.
let _ = spawn(move || { let _ = spawn(move || {
for msg in server.iter() { for msg in server.iter() {
print!("{}", msg.unwrap().into_string()); print!("{}", msg.unwrap().into_string());

View file

@ -11,9 +11,7 @@ fn main() {
channels: Some(vec![format!("#vana")]), channels: Some(vec![format!("#vana")]),
.. Default::default() .. Default::default()
}; };
let irc_server = IrcServer::from_config(config).unwrap(); let server = IrcServer::from_config(config).unwrap();
// The wrapper provides us with methods like send_privmsg(...) and identify(...)
let server = Wrapper::new(&irc_server);
server.identify().unwrap(); server.identify().unwrap();
for message in server.iter() { for message in server.iter() {
let message = message.unwrap(); // We'll just panic if there's an error. let message = message.unwrap(); // We'll just panic if there's an error.

View file

@ -11,9 +11,7 @@ fn main() {
channels: Some(vec![format!("#vana")]), channels: Some(vec![format!("#vana")]),
.. Default::default() .. Default::default()
}; };
let irc_server = IrcServer::from_config(config).unwrap(); let server = IrcServer::from_config(config).unwrap();
// The wrapper provides us with methods like send_privmsg(...) and identify(...)
let server = Wrapper::new(&irc_server);
server.identify().unwrap(); server.identify().unwrap();
for command in server.iter_cmd() { for command in server.iter_cmd() {
// Use of unwrap() on the results of iter_cmd() is currently discouraged on servers where // Use of unwrap() on the results of iter_cmd() is currently discouraged on servers where

View file

@ -12,9 +12,7 @@ fn main() {
use_ssl: Some(true), use_ssl: Some(true),
.. Default::default() .. Default::default()
}; };
let irc_server = IrcServer::from_config(config).unwrap(); let server = IrcServer::from_config(config).unwrap();
// The wrapper provides us with methods like send_privmsg(...) and identify(...)
let server = Wrapper::new(&irc_server);
server.identify().unwrap(); server.identify().unwrap();
for message in server.iter() { for message in server.iter() {
let message = message.unwrap(); // We'll just panic if there's an error. let message = message.unwrap(); // We'll just panic if there's an error.

View file

@ -15,14 +15,12 @@ fn main() {
channels: Some(vec![format!("#vana")]), channels: Some(vec![format!("#vana")]),
.. Default::default() .. Default::default()
}; };
let irc_server = Arc::new(IrcServer::from_config(config).unwrap()); let server = Arc::new(IrcServer::from_config(config).unwrap());
let irc_server2 = irc_server.clone();
// The wrapper provides us with methods like send_privmsg(...) and identify(...)
let server = Wrapper::new(&*irc_server2);
server.identify().unwrap(); server.identify().unwrap();
let server2 = server.clone();
// Let's set up a loop that just prints the messages. // Let's set up a loop that just prints the messages.
spawn(move || { spawn(move || {
irc_server.iter().map(|m| print!("{}", m.unwrap().into_string())).count(); server2.iter().map(|m| print!("{}", m.unwrap().into_string())).count();
}); });
loop { loop {
server.send_privmsg("#vana", "TWEET TWEET").unwrap(); server.send_privmsg("#vana", "TWEET TWEET").unwrap();