Updated handle_message(...) to use Response everywhere as needed.

This commit is contained in:
Aaron Weiss 2014-12-01 16:12:19 -05:00
parent 4a48093905
commit da30e4bccd

View file

@ -117,14 +117,8 @@ impl<T> IrcServer<T> where T: IrcStream {
/// Handles messages internally for basic bot functionality. /// Handles messages internally for basic bot functionality.
#[experimental] #[experimental]
fn handle_message(&self, msg: &Message) { fn handle_message(&self, msg: &Message) {
if msg.command[] == "PING" { if let Some(resp) = Response::from_message(msg) {
self.send(PONG(msg.suffix.as_ref().unwrap()[], None)).unwrap(); if resp == Response::RPL_NAMREPLY {
} else if msg.command[] == "376" || msg.command[] == "422" {
for chan in self.config.channels.iter() {
self.send(JOIN(chan[], None)).unwrap();
}
}
else if let Some(Response::RPL_NAMREPLY) = Response::from_message(msg) {
if let Some(users) = msg.suffix.clone() { if let Some(users) = msg.suffix.clone() {
if let [_, _, ref chan] = msg.args[] { if let [_, _, ref chan] = msg.args[] {
for user in users.split_str(" ") { for user in users.split_str(" ") {
@ -137,6 +131,15 @@ impl<T> IrcServer<T> where T: IrcStream {
} }
} }
} }
} else if resp == Response::RPL_ENDOFMOTD || resp == Response::ERR_NOMOTD {
for chan in self.config.channels.iter() {
self.send(JOIN(chan[], None)).unwrap();
}
}
return
}
if msg.command[] == "PING" {
self.send(PONG(msg.suffix.as_ref().unwrap()[], None)).unwrap();
} else if msg.command[] == "JOIN" || msg.command[] == "PART" { } else if msg.command[] == "JOIN" || msg.command[] == "PART" {
let chan = match msg.suffix { let chan = match msg.suffix {
Some(ref suffix) => suffix[], Some(ref suffix) => suffix[],