Updated examples with ServerExt change.
This commit is contained in:
parent
27839902ad
commit
8cf7471af2
7 changed files with 13 additions and 26 deletions
|
@ -19,8 +19,7 @@ extern crate irc;
|
|||
use irc::client::prelude::*;
|
||||
|
||||
fn main() {
|
||||
let irc_server = IrcServer::new("config.json").unwrap();
|
||||
let server = Wrapper::new(&irc_server);
|
||||
let server = IrcServer::new("config.json").unwrap();
|
||||
server.identify().unwrap();
|
||||
for message in server.iter() {
|
||||
// Do message processing.
|
||||
|
|
|
@ -12,11 +12,10 @@ fn main() {
|
|||
channels: Some(vec![format!("#vana")]),
|
||||
.. Default::default()
|
||||
};
|
||||
let irc_server = Arc::new(IrcServer::from_config(config).unwrap());
|
||||
irc_server.conn().set_keepalive(Some(5)).unwrap();
|
||||
// The wrapper provides us with methods like send_privmsg(...) and identify(...)
|
||||
let server = Arc::new(IrcServer::from_config(config).unwrap());
|
||||
server.conn().set_keepalive(Some(5)).unwrap();
|
||||
let server = server.clone();
|
||||
let _ = spawn(move || {
|
||||
let server = Wrapper::new(&*irc_server);
|
||||
server.identify().unwrap();
|
||||
loop {
|
||||
let mut quit = false;
|
||||
|
@ -36,7 +35,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
if quit { break }
|
||||
irc_server.reconnect().unwrap();
|
||||
server.reconnect().unwrap();
|
||||
server.identify().unwrap();
|
||||
}
|
||||
}).join();
|
||||
|
|
|
@ -12,12 +12,9 @@ fn main() {
|
|||
channels: Some(vec![format!("#vana")]),
|
||||
.. Default::default()
|
||||
};
|
||||
let irc_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);
|
||||
let server = Arc::new(IrcServer::from_config(config).unwrap());
|
||||
server.identify().unwrap();
|
||||
let server = irc_server.clone();
|
||||
// We won't use a wrapper here because we don't need the added functionality.
|
||||
let server = server.clone();
|
||||
let _ = spawn(move || {
|
||||
for msg in server.iter() {
|
||||
print!("{}", msg.unwrap().into_string());
|
||||
|
|
|
@ -11,9 +11,7 @@ fn main() {
|
|||
channels: Some(vec![format!("#vana")]),
|
||||
.. Default::default()
|
||||
};
|
||||
let irc_server = IrcServer::from_config(config).unwrap();
|
||||
// The wrapper provides us with methods like send_privmsg(...) and identify(...)
|
||||
let server = Wrapper::new(&irc_server);
|
||||
let server = IrcServer::from_config(config).unwrap();
|
||||
server.identify().unwrap();
|
||||
for message in server.iter() {
|
||||
let message = message.unwrap(); // We'll just panic if there's an error.
|
||||
|
|
|
@ -11,9 +11,7 @@ fn main() {
|
|||
channels: Some(vec![format!("#vana")]),
|
||||
.. Default::default()
|
||||
};
|
||||
let irc_server = IrcServer::from_config(config).unwrap();
|
||||
// The wrapper provides us with methods like send_privmsg(...) and identify(...)
|
||||
let server = Wrapper::new(&irc_server);
|
||||
let server = IrcServer::from_config(config).unwrap();
|
||||
server.identify().unwrap();
|
||||
for command in server.iter_cmd() {
|
||||
// Use of unwrap() on the results of iter_cmd() is currently discouraged on servers where
|
||||
|
|
|
@ -12,9 +12,7 @@ fn main() {
|
|||
use_ssl: Some(true),
|
||||
.. Default::default()
|
||||
};
|
||||
let irc_server = IrcServer::from_config(config).unwrap();
|
||||
// The wrapper provides us with methods like send_privmsg(...) and identify(...)
|
||||
let server = Wrapper::new(&irc_server);
|
||||
let server = IrcServer::from_config(config).unwrap();
|
||||
server.identify().unwrap();
|
||||
for message in server.iter() {
|
||||
let message = message.unwrap(); // We'll just panic if there's an error.
|
||||
|
|
|
@ -15,14 +15,12 @@ fn main() {
|
|||
channels: Some(vec![format!("#vana")]),
|
||||
.. Default::default()
|
||||
};
|
||||
let irc_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);
|
||||
let server = Arc::new(IrcServer::from_config(config).unwrap());
|
||||
server.identify().unwrap();
|
||||
let server2 = server.clone();
|
||||
// Let's set up a loop that just prints the messages.
|
||||
spawn(move || {
|
||||
irc_server.iter().map(|m| print!("{}", m.unwrap().into_string())).count();
|
||||
server2.iter().map(|m| print!("{}", m.unwrap().into_string())).count();
|
||||
});
|
||||
loop {
|
||||
server.send_privmsg("#vana", "TWEET TWEET").unwrap();
|
||||
|
|
Loading…
Reference in a new issue