Updated examples after Command redesign.
This commit is contained in:
parent
2eb0e63d59
commit
b6ce088693
4 changed files with 17 additions and 42 deletions
|
@ -16,12 +16,11 @@ fn main() {
|
|||
for message in server.iter() {
|
||||
let message = message.unwrap(); // We'll just panic if there's an error.
|
||||
print!("{}", message.into_string());
|
||||
if &message.command[..] == "PRIVMSG" {
|
||||
if let Some(msg) = message.suffix {
|
||||
if msg.contains("pickles") {
|
||||
server.send_privmsg(&message.args[0], "Hi!").unwrap();
|
||||
}
|
||||
}
|
||||
match message.command {
|
||||
Command::PRIVMSG(ref target, ref msg) => if msg.contains("pickles") {
|
||||
server.send_privmsg(target, "Hi!").unwrap();
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
extern crate irc;
|
||||
|
||||
use std::default::Default;
|
||||
use irc::client::prelude::*;
|
||||
|
||||
fn main() {
|
||||
let config = Config {
|
||||
nickname: Some(format!("pickles")),
|
||||
alt_nicks: Some(vec![format!("bananas"), format!("apples")]),
|
||||
server: Some(format!("irc.fyrechat.net")),
|
||||
channels: Some(vec![format!("#vana")]),
|
||||
.. Default::default()
|
||||
};
|
||||
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 discouraged since response codes will be
|
||||
// received as parsing errors when using this type of iterator.
|
||||
if let Ok(Command::PRIVMSG(chan, msg)) = command { // Ignore errors.
|
||||
if msg.contains("pickles") {
|
||||
server.send_privmsg(&chan, "Hi!").unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,12 +17,11 @@ fn main() {
|
|||
for message in server.iter() {
|
||||
let message = message.unwrap(); // We'll just panic if there's an error.
|
||||
print!("{}", message.into_string());
|
||||
if &message.command[..] == "PRIVMSG" {
|
||||
if let Some(msg) = message.suffix {
|
||||
if msg.contains("pickles") {
|
||||
server.send_privmsg(&message.args[0], "Hi!").unwrap();
|
||||
}
|
||||
}
|
||||
match message.command {
|
||||
Command::PRIVMSG(ref target, ref msg) => if msg.contains("pickles") {
|
||||
server.send_privmsg(target, "Hi!").unwrap();
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -138,18 +138,20 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn get_source_nickname() {
|
||||
assert_eq!(Message::new(None, "PING", vec![], None).unwrap().get_source_nickname(), None);
|
||||
assert_eq!(Message::new(
|
||||
Some("irc.test.net"), "PING", vec![], None
|
||||
None, "PING", vec![], Some("data")
|
||||
).unwrap().get_source_nickname(), None);
|
||||
assert_eq!(Message::new(
|
||||
Some("test!test@test"), "PING", vec![], None
|
||||
Some("irc.test.net"), "PING", vec![], Some("data")
|
||||
).unwrap().get_source_nickname(), None);
|
||||
assert_eq!(Message::new(
|
||||
Some("test!test@test"), "PING", vec![], Some("data")
|
||||
).unwrap().get_source_nickname(), Some("test"));
|
||||
assert_eq!(Message::new(
|
||||
Some("test@test"), "PING", vec![], None
|
||||
Some("test@test"), "PING", vec![], Some("data")
|
||||
).unwrap().get_source_nickname(), Some("test"));
|
||||
assert_eq!(Message::new(
|
||||
Some("test"), "PING", vec![], None
|
||||
Some("test"), "PING", vec![], Some("data")
|
||||
).unwrap().get_source_nickname(), Some("test"));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue