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.
|
/// Gets the nickname of the message source, if it exists.
|
||||||
pub fn source_nickname(&self) -> Option<&str> {
|
pub fn source_nickname(&self) -> Option<&str> {
|
||||||
|
// <prefix> ::= <servername> | <nick> [ '!' <user> ] [ '@' <host> ]
|
||||||
|
// <servername> ::= <host>
|
||||||
self.prefix.as_ref().and_then(|s|
|
self.prefix.as_ref().and_then(|s|
|
||||||
match (s.find('!'), s.find('@'), s.find('.')) {
|
match (s.find('!'), s.find('@'), s.find('.')) {
|
||||||
(_, _, Some(_)) => None,
|
(Some(i), _, _) => Some(&s[..i]), // nick!user
|
||||||
(Some(i), _, None) => Some(&s[..i]),
|
(None, Some(i), _) => Some(&s[..i]), // nick@host
|
||||||
(None, Some(i), None) => Some(&s[..i]),
|
(None, None, None) => Some(&s), // nick
|
||||||
(None, None, None) => Some(&s)
|
_ => None // server.name
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue