Cleaned up a bunch of the examples.
This commit is contained in:
parent
d6786936fa
commit
af72e57c5f
5 changed files with 29 additions and 44 deletions
|
@ -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(())
|
||||
});
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue