diff options
author | Till Hoeppner | 2015-04-18 16:45:34 +0200 |
---|---|---|
committer | Till Hoeppner | 2015-04-18 16:45:34 +0200 |
commit | daa65ad3a74873ba5db2c8fe7f3290e12f616efe (patch) | |
tree | 6c9e276ecb858acaffb78d850ee92ae62970f310 /src | |
parent | 984d479f2c1686c1bcfac44a2d0f23f8ba010b1b (diff) | |
download | irsc-daa65ad3a74873ba5db2c8fe7f3290e12f616efe.tar.gz irsc-daa65ad3a74873ba5db2c8fe7f3290e12f616efe.tar.xz irsc-daa65ad3a74873ba5db2c8fe7f3290e12f616efe.zip |
Strip \u{1} from CTCP messages for easier processing by user
Diffstat (limited to 'src')
-rw-r--r-- | src/message.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/message.rs b/src/message.rs index 50baaaf..31bd8a7 100644 --- a/src/message.rs +++ b/src/message.rs @@ -77,10 +77,14 @@ impl<'a> FromStr for Message<'a> { .and_then(|s| s.chars().next()) == Some('\u{1}') { MsgType::Ctcp } else { MsgType::Irc }; command.map(move |c| - Ok(Message::new(prefix.map(|p| Cow::Owned(p)), + Ok(Message::new(prefix.map(Cow::Owned), c.unwrap(), content, - suffix.map(|s| Cow::Owned(s)), + // strip \{1} if CTCP message + match msg_type { + MsgType::Irc => suffix.map(Cow::Owned), + MsgType::Ctcp => suffix.map(|s| s[1..s.len() - 1].to_string()).map(Cow::Owned) + }, msg_type )) ).unwrap() @@ -107,11 +111,12 @@ impl<'a> ToString for Message<'a> { if let Some(ref p) = self.suffix { s.push(':'); + if let MsgType::Ctcp = self.msg_type { s.push('\u{1}') } s.push_str(&p); + if let MsgType::Ctcp = self.msg_type { s.push('\u{1}') } } s - } } @@ -1198,7 +1203,7 @@ mod test { Some(Cow::Owned("d".to_owned())), Cow::Owned("PRIVMSG".to_owned()), vec![Cow::Owned("You".to_owned())], - Some(Cow::Owned("\u{1}ACTION sends you funny pictures of cats!\u{1}".to_owned())), + Some(Cow::Owned("ACTION sends you funny pictures of cats!".to_owned())), MsgType::Ctcp ); assert_eq!(b.parse::<Message>().unwrap(), b2.clone()); |