diff --git a/src/protos/irc/client.rs b/src/protos/irc/client.rs index a0accd0..7d73c87 100644 --- a/src/protos/irc/client.rs +++ b/src/protos/irc/client.rs @@ -1,5 +1,7 @@ use super::*; +use nom::combinator::opt; + /// Client-to-server command. #[derive(Clone, Debug, PartialEq, Eq)] pub enum ClientMessage { @@ -121,8 +123,12 @@ fn client_message_user(input: &str) -> IResult<&str, ClientMessage> { let (input, _) = receiver(input)?; let (input, _) = tag(" ")(input)?; let (input, _) = receiver(input)?; - let (input, _) = tag(" :")(input)?; - let (input, realname) = token(input)?; + let (input, _) = tag(" ")(input)?; + let (input, r) = opt(tag(":"))(input)?; + let (input, realname) = match r { + Some(_) => token(input)?, + None => receiver(input)?, + }; Ok(( input, @@ -156,8 +162,12 @@ fn client_message_who(input: &str) -> IResult<&str, ClientMessage> { fn client_message_topic(input: &str) -> IResult<&str, ClientMessage> { let (input, _) = tag("TOPIC ")(input)?; let (input, chan) = chan(input)?; - let (input, _) = tag(" :")(input)?; - let (input, topic) = token(input)?; + let (input, _) = tag(" ")(input)?; + let (input, r) = opt(tag(":"))(input)?; + let (input, topic) = match r { + Some(_) => token(input)?, + None => receiver(input)?, + }; let topic = topic.into(); Ok((input, ClientMessage::Topic { chan, topic })) @@ -166,8 +176,12 @@ fn client_message_topic(input: &str) -> IResult<&str, ClientMessage> { fn client_message_part(input: &str) -> IResult<&str, ClientMessage> { let (input, _) = tag("PART ")(input)?; let (input, chan) = chan(input)?; - let (input, _) = tag(" :")(input)?; - let (input, message) = token(input)?; + let (input, _) = tag(" ")(input)?; + let (input, r) = opt(tag(":"))(input)?; + let (input, message) = match r { + Some(_) => token(input)?, + None => receiver(input)?, + }; let message = message.into(); Ok((input, ClientMessage::Part { chan, message })) @@ -176,8 +190,12 @@ fn client_message_part(input: &str) -> IResult<&str, ClientMessage> { fn client_message_privmsg(input: &str) -> IResult<&str, ClientMessage> { let (input, _) = tag("PRIVMSG ")(input)?; let (input, recipient) = recipient(input)?; - let (input, _) = tag(" :")(input)?; - let (input, body) = token(input)?; + let (input, _) = tag(" ")(input)?; + let (input, r) = opt(tag(":"))(input)?; + let (input, body) = match r { + Some(_) => token(input)?, + None => receiver(input)?, + }; let body = body.into(); Ok((input, ClientMessage::PrivateMessage { recipient, body }))