Fix Message::source_nickname
This commit is contained in:
parent
54cb41a616
commit
022b4af86c
1 changed files with 6 additions and 4 deletions
|
@ -34,12 +34,14 @@ impl Message {
|
|||
|
||||
/// Gets the nickname of the message source, if it exists.
|
||||
pub fn source_nickname(&self) -> Option<&str> {
|
||||
// <prefix> ::= <servername> | <nick> [ '!' <user> ] [ '@' <host> ]
|
||||
// <servername> ::= <host>
|
||||
self.prefix.as_ref().and_then(|s|
|
||||
match (s.find('!'), s.find('@'), s.find('.')) {
|
||||
(_, _, Some(_)) => None,
|
||||
(Some(i), _, None) => Some(&s[..i]),
|
||||
(None, Some(i), None) => Some(&s[..i]),
|
||||
(None, None, None) => Some(&s)
|
||||
(Some(i), _, _) => Some(&s[..i]), // nick!user
|
||||
(None, Some(i), _) => Some(&s[..i]), // nick@host
|
||||
(None, None, None) => Some(&s), // nick
|
||||
_ => None // server.name
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue