Merge pull request #13 from whipsch/feature-nochanlists

Add nochanlists feature.
This commit is contained in:
Aaron Weiss 2015-01-11 00:50:50 -05:00
commit e7f148fa90
2 changed files with 31 additions and 20 deletions

View file

@ -16,6 +16,7 @@ default = ["ctcp", "encode", "ssl"]
ctcp = ["time"] ctcp = ["time"]
encode = ["encoding"] encode = ["encoding"]
ssl = ["openssl"] ssl = ["openssl"]
nochanlists = []
[dependencies.rustc-serialize] [dependencies.rustc-serialize]
rustc-serialize = "~0.2.7" rustc-serialize = "~0.2.7"

View file

@ -111,6 +111,7 @@ impl<T: IrcReader, U: IrcWriter> IrcServer<T, U> {
fn handle_message(&self, msg: &Message) { fn handle_message(&self, msg: &Message) {
if let Some(resp) = Response::from_message(msg) { if let Some(resp) = Response::from_message(msg) {
if resp == Response::RPL_NAMREPLY { if resp == Response::RPL_NAMREPLY {
if cfg!(not(feature = "nochanlists")) {
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(" ") {
@ -124,6 +125,7 @@ impl<T: IrcReader, U: IrcWriter> IrcServer<T, U> {
} }
} }
} }
}
} else if resp == Response::RPL_ENDOFMOTD || resp == Response::ERR_NOMOTD { } else if resp == Response::RPL_ENDOFMOTD || resp == Response::ERR_NOMOTD {
if self.config.nick_password() != "" { if self.config.nick_password() != "" {
self.send(NICKSERV( self.send(NICKSERV(
@ -153,6 +155,7 @@ impl<T: IrcReader, U: IrcWriter> IrcServer<T, U> {
Some(ref suffix) => &suffix[], Some(ref suffix) => &suffix[],
None => &msg.args[0][], None => &msg.args[0][],
}; };
if cfg!(not(feature = "nochanlists")) {
if let Some(vec) = self.chanlists.lock().unwrap().get_mut(&String::from_str(chan)) { if let Some(vec) = self.chanlists.lock().unwrap().get_mut(&String::from_str(chan)) {
if let Some(ref src) = msg.prefix { if let Some(ref src) = msg.prefix {
if let Some(i) = src.find('!') { if let Some(i) = src.find('!') {
@ -166,12 +169,15 @@ impl<T: IrcReader, U: IrcWriter> IrcServer<T, U> {
} }
} }
} }
}
} else if let ("MODE", [ref chan, ref mode, ref user]) = (&msg.command[], &msg.args[]) { } else if let ("MODE", [ref chan, ref mode, ref user]) = (&msg.command[], &msg.args[]) {
if cfg!(not(feature = "nochanlists")) {
if let Some(vec) = self.chanlists.lock().unwrap().get_mut(chan) { if let Some(vec) = self.chanlists.lock().unwrap().get_mut(chan) {
if let Some(n) = vec.as_slice().position_elem(&User::new(&user[])) { if let Some(n) = vec.as_slice().position_elem(&User::new(&user[])) {
vec[n].update_access_level(&mode[]); vec[n].update_access_level(&mode[]);
} }
} }
}
} else { } else {
self.handle_ctcp(msg); self.handle_ctcp(msg);
} }
@ -381,6 +387,7 @@ mod test {
assert_eq!(&get_server_value(server)[], "PRIVMSG #test :Hi there!\r\n"); assert_eq!(&get_server_value(server)[], "PRIVMSG #test :Hi there!\r\n");
} }
#[cfg(not(feature = "nochanlists"))]
#[test] #[test]
fn user_tracking_names() { fn user_tracking_names() {
let value = ":irc.test.net 353 test = #test :test ~owner &admin\r\n"; let value = ":irc.test.net 353 test = #test :test ~owner &admin\r\n";
@ -394,6 +401,7 @@ mod test {
vec![User::new("test"), User::new("~owner"), User::new("&admin")]) vec![User::new("test"), User::new("~owner"), User::new("&admin")])
} }
#[cfg(not(feature = "nochanlists"))]
#[test] #[test]
fn user_tracking_names_join() { fn user_tracking_names_join() {
let value = ":irc.test.net 353 test = #test :test ~owner &admin\r\n\ let value = ":irc.test.net 353 test = #test :test ~owner &admin\r\n\
@ -408,6 +416,7 @@ mod test {
vec![User::new("test"), User::new("~owner"), User::new("&admin"), User::new("test2")]) vec![User::new("test"), User::new("~owner"), User::new("&admin"), User::new("test2")])
} }
#[cfg(not(feature = "nochanlists"))]
#[test] #[test]
fn user_tracking_names_part() { fn user_tracking_names_part() {
let value = ":irc.test.net 353 test = #test :test ~owner &admin\r\n\ let value = ":irc.test.net 353 test = #test :test ~owner &admin\r\n\
@ -422,6 +431,7 @@ mod test {
vec![User::new("test"), User::new("&admin")]) vec![User::new("test"), User::new("&admin")])
} }
#[cfg(not(feature = "nochanlists"))]
#[test] #[test]
fn user_tracking_names_mode() { fn user_tracking_names_mode() {
let value = ":irc.test.net 353 test = #test :+test ~owner &admin\r\n\ let value = ":irc.test.net 353 test = #test :+test ~owner &admin\r\n\