Skip to content

Commit

Permalink
irc-proto: allow empty mode
Browse files Browse the repository at this point in the history
irc clients can query what modes a channel has by sending an empty mode
command
  • Loading branch information
martinetd committed Dec 4, 2020
1 parent d77696b commit 010c167
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions irc-proto/src/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,8 @@ where
})
}
None => {
return Err(InvalidModeString {
string: pieces.join(" ").to_owned(),
cause: MissingModeModifier,
})
// No modifier
return Ok(res);
}
};

Expand Down Expand Up @@ -318,9 +316,32 @@ where

Ok(res)
} else {
Err(InvalidModeString {
string: pieces.join(" ").to_owned(),
cause: MissingModeModifier,
})
// No modifier
Ok(res)
}
}

#[cfg(test)]
mod test {
use super::{ChannelMode, Mode};
use crate::Command;
use crate::Message;

#[test]
fn parse_channel_mode() {
let cmd = "MODE #foo +r".parse::<Message>().unwrap().command;
assert_eq!(
Command::ChannelMODE(
"#foo".to_string(),
vec![Mode::Plus(ChannelMode::RegisteredOnly, None)]
),
cmd
);
}

#[test]
fn parse_no_mode() {
let cmd = "MODE #foo".parse::<Message>().unwrap().command;
assert_eq!(Command::ChannelMODE("#foo".to_string(), vec![]), cmd);
}
}

0 comments on commit 010c167

Please sign in to comment.