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()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let reactor = IrcReactor::new().unwrap();
|
let mut reactor = IrcReactor::new().unwrap();
|
||||||
let server = reactor.prepare_server_and_connect(&config).unwrap();
|
let server = reactor.prepare_server_and_connect(&config).unwrap();
|
||||||
server.identify().unwrap();
|
server.identify().unwrap();
|
||||||
|
|
||||||
reactor.register_server_with_handler(server, |message| {
|
reactor.register_server_with_handler(server, |server, message| {
|
||||||
print!("{}", message);
|
print!("{}", message);
|
||||||
match message.command {
|
if let Command::PRIVMSG(ref target, ref msg) = message.command {
|
||||||
Command::PRIVMSG(ref target, ref msg) => {
|
if msg.contains("pickles") {
|
||||||
if msg.contains("pickles") {
|
server.send_privmsg(target, "Hi!")?;
|
||||||
server.send_privmsg(target, "Hi!").unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
|
@ -46,15 +46,12 @@ fn main() {
|
||||||
|
|
||||||
fn process_msg(server: &IrcServer, message: Message) -> error::Result<()> {
|
fn process_msg(server: &IrcServer, message: Message) -> error::Result<()> {
|
||||||
print!("{}", message);
|
print!("{}", message);
|
||||||
match message.command {
|
if let Command::PRIVMSG(ref target, ref msg) = message.command {
|
||||||
Command::PRIVMSG(ref target, ref msg) => {
|
if msg.contains("pickles") {
|
||||||
if msg.contains("pickles") {
|
server.send_privmsg(target, "Hi!")?;
|
||||||
server.send_privmsg(target, "Hi!")?;
|
} else if msg.contains("quit") {
|
||||||
} else if msg.contains("quit") {
|
server.send_quit("bye")?;
|
||||||
server.send_quit("bye")?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,24 +20,21 @@ fn main() {
|
||||||
|
|
||||||
server.for_each_incoming(|message| {
|
server.for_each_incoming(|message| {
|
||||||
print!("{}", message);
|
print!("{}", message);
|
||||||
match message.command {
|
if let Command::PRIVMSG(ref target, ref msg) = message.command {
|
||||||
Command::PRIVMSG(ref target, ref msg) => {
|
if msg.starts_with(server.current_nickname()) {
|
||||||
if msg.starts_with(server.current_nickname()) {
|
let tokens: Vec<_> = msg.split(' ').collect();
|
||||||
let tokens: Vec<_> = msg.split(' ').collect();
|
if tokens.len() > 2 {
|
||||||
if tokens.len() > 2 {
|
let n = tokens[0].len() + tokens[1].len() + 2;
|
||||||
let n = tokens[0].len() + tokens[1].len() + 2;
|
if let Ok(count) = tokens[1].parse::<u8>() {
|
||||||
if let Ok(count) = tokens[1].parse::<u8>() {
|
for _ in 0..count {
|
||||||
for _ in 0..count {
|
server.send_privmsg(
|
||||||
server.send_privmsg(
|
message.response_target().unwrap_or(target),
|
||||||
message.response_target().unwrap_or(target),
|
&msg[n..]
|
||||||
&msg[n..]
|
).unwrap();
|
||||||
).unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}).unwrap()
|
}).unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,13 +17,10 @@ fn main() {
|
||||||
|
|
||||||
server.for_each_incoming(|message| {
|
server.for_each_incoming(|message| {
|
||||||
print!("{}", message);
|
print!("{}", message);
|
||||||
match message.command {
|
if let Command::PRIVMSG(ref target, ref msg) = message.command {
|
||||||
Command::PRIVMSG(ref target, ref msg) => {
|
if msg.contains("pickles") {
|
||||||
if msg.contains("pickles") {
|
server.send_privmsg(target, "Hi!").unwrap();
|
||||||
server.send_privmsg(target, "Hi!").unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}).unwrap()
|
}).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,13 +17,10 @@ fn main() {
|
||||||
|
|
||||||
server.for_each_incoming(|message| {
|
server.for_each_incoming(|message| {
|
||||||
print!("{}", message);
|
print!("{}", message);
|
||||||
match message.command {
|
if let Command::PRIVMSG(ref target, ref msg) = message.command {
|
||||||
Command::PRIVMSG(ref target, ref msg) => {
|
if msg.contains("pickles") {
|
||||||
if msg.contains("pickles") {
|
server.send_privmsg(target, "Hi!").unwrap();
|
||||||
server.send_privmsg(target, "Hi!").unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}).unwrap()
|
}).unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue