Cleaned up a bunch of the examples.

This commit is contained in:
Aaron Weiss 2018-01-28 02:00:04 +01:00
parent d6786936fa
commit af72e57c5f
No known key found for this signature in database
GPG key ID: 047D32DF25DC22EF
5 changed files with 29 additions and 44 deletions

View file

@ -13,19 +13,16 @@ fn main() {
..Default::default()
};
let reactor = IrcReactor::new().unwrap();
let mut reactor = IrcReactor::new().unwrap();
let server = reactor.prepare_server_and_connect(&config).unwrap();
server.identify().unwrap();
reactor.register_server_with_handler(server, |message| {
reactor.register_server_with_handler(server, |server, message| {
print!("{}", message);
match message.command {
Command::PRIVMSG(ref target, ref msg) => {
if msg.contains("pickles") {
server.send_privmsg(target, "Hi!").unwrap();
}
if let Command::PRIVMSG(ref target, ref msg) = message.command {
if msg.contains("pickles") {
server.send_privmsg(target, "Hi!")?;
}
_ => (),
}
Ok(())
});

View file

@ -46,15 +46,12 @@ fn main() {
fn process_msg(server: &IrcServer, message: Message) -> error::Result<()> {
print!("{}", message);
match message.command {
Command::PRIVMSG(ref target, ref msg) => {
if msg.contains("pickles") {
server.send_privmsg(target, "Hi!")?;
} else if msg.contains("quit") {
server.send_quit("bye")?;
}
if let Command::PRIVMSG(ref target, ref msg) = message.command {
if msg.contains("pickles") {
server.send_privmsg(target, "Hi!")?;
} else if msg.contains("quit") {
server.send_quit("bye")?;
}
_ => (),
}
Ok(())
}

View file

@ -20,24 +20,21 @@ fn main() {
server.for_each_incoming(|message| {
print!("{}", message);
match message.command {
Command::PRIVMSG(ref target, ref msg) => {
if msg.starts_with(server.current_nickname()) {
let tokens: Vec<_> = msg.split(' ').collect();
if tokens.len() > 2 {
let n = tokens[0].len() + tokens[1].len() + 2;
if let Ok(count) = tokens[1].parse::<u8>() {
for _ in 0..count {
server.send_privmsg(
message.response_target().unwrap_or(target),
&msg[n..]
).unwrap();
}
if let Command::PRIVMSG(ref target, ref msg) = message.command {
if msg.starts_with(server.current_nickname()) {
let tokens: Vec<_> = msg.split(' ').collect();
if tokens.len() > 2 {
let n = tokens[0].len() + tokens[1].len() + 2;
if let Ok(count) = tokens[1].parse::<u8>() {
for _ in 0..count {
server.send_privmsg(
message.response_target().unwrap_or(target),
&msg[n..]
).unwrap();
}
}
}
}
_ => (),
}
}).unwrap()
}

View file

@ -17,13 +17,10 @@ fn main() {
server.for_each_incoming(|message| {
print!("{}", message);
match message.command {
Command::PRIVMSG(ref target, ref msg) => {
if msg.contains("pickles") {
server.send_privmsg(target, "Hi!").unwrap();
}
if let Command::PRIVMSG(ref target, ref msg) = message.command {
if msg.contains("pickles") {
server.send_privmsg(target, "Hi!").unwrap();
}
_ => (),
}
}).unwrap()
}).unwrap();
}

View file

@ -17,13 +17,10 @@ fn main() {
server.for_each_incoming(|message| {
print!("{}", message);
match message.command {
Command::PRIVMSG(ref target, ref msg) => {
if msg.contains("pickles") {
server.send_privmsg(target, "Hi!").unwrap();
}
if let Command::PRIVMSG(ref target, ref msg) = message.command {
if msg.contains("pickles") {
server.send_privmsg(target, "Hi!").unwrap();
}
_ => (),
}
}).unwrap()
}).unwrap();
}