Merge pull request #13 from whipsch/feature-nochanlists
Add nochanlists feature.
This commit is contained in:
commit
e7f148fa90
2 changed files with 31 additions and 20 deletions
|
@ -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"
|
||||||
|
|
|
@ -111,15 +111,17 @@ 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 let Some(users) = msg.suffix.clone() {
|
if cfg!(not(feature = "nochanlists")) {
|
||||||
if let [_, _, ref chan] = &msg.args[] {
|
if let Some(users) = msg.suffix.clone() {
|
||||||
for user in users.split_str(" ") {
|
if let [_, _, ref chan] = &msg.args[] {
|
||||||
if match self.chanlists.lock().unwrap().get_mut(chan) {
|
for user in users.split_str(" ") {
|
||||||
Some(vec) => { vec.push(User::new(user)); false },
|
if match self.chanlists.lock().unwrap().get_mut(chan) {
|
||||||
None => true,
|
Some(vec) => { vec.push(User::new(user)); false },
|
||||||
} {
|
None => true,
|
||||||
self.chanlists.lock().unwrap().insert(chan.clone(),
|
} {
|
||||||
vec!(User::new(user)));
|
self.chanlists.lock().unwrap().insert(chan.clone(),
|
||||||
|
vec!(User::new(user)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,23 +155,27 @@ 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 let Some(vec) = self.chanlists.lock().unwrap().get_mut(&String::from_str(chan)) {
|
if cfg!(not(feature = "nochanlists")) {
|
||||||
if let Some(ref src) = msg.prefix {
|
if let Some(vec) = self.chanlists.lock().unwrap().get_mut(&String::from_str(chan)) {
|
||||||
if let Some(i) = src.find('!') {
|
if let Some(ref src) = msg.prefix {
|
||||||
if &msg.command[] == "JOIN" {
|
if let Some(i) = src.find('!') {
|
||||||
vec.push(User::new(&src[..i]));
|
if &msg.command[] == "JOIN" {
|
||||||
} else {
|
vec.push(User::new(&src[..i]));
|
||||||
if let Some(n) = vec.as_slice().position_elem(&User::new(&src[..i])) {
|
} else {
|
||||||
vec.swap_remove(n);
|
if let Some(n) = vec.as_slice().position_elem(&User::new(&src[..i])) {
|
||||||
|
vec.swap_remove(n);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} 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 let Some(vec) = self.chanlists.lock().unwrap().get_mut(chan) {
|
if cfg!(not(feature = "nochanlists")) {
|
||||||
if let Some(n) = vec.as_slice().position_elem(&User::new(&user[])) {
|
if let Some(vec) = self.chanlists.lock().unwrap().get_mut(chan) {
|
||||||
vec[n].update_access_level(&mode[]);
|
if let Some(n) = vec.as_slice().position_elem(&User::new(&user[])) {
|
||||||
|
vec[n].update_access_level(&mode[]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -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\
|
||||||
|
|
Loading…
Reference in a new issue