Added a response_target helper function (suggested in #44).
This commit is contained in:
parent
bd5253016e
commit
cfafb39ed9
1 changed files with 12 additions and 1 deletions
|
@ -5,7 +5,7 @@ use std::str::FromStr;
|
|||
|
||||
use error;
|
||||
use error::{Error, ErrorKind};
|
||||
use proto::Command;
|
||||
use proto::{Command, ChannelExt};
|
||||
|
||||
/// IRC Message data.
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
|
@ -60,6 +60,17 @@ impl Message {
|
|||
})
|
||||
}
|
||||
|
||||
/// Gets the likely intended place to respond to this message.
|
||||
/// If the type of the message is a `PRIVMSG` or `NOTICE` and the message is sent to a channel,
|
||||
/// the result will be that channel. In all other cases, this will call `source_nickname`.
|
||||
pub fn response_target(&self) -> Option<&str> {
|
||||
match self.command {
|
||||
Command::PRIVMSG(ref target, _) if target.is_channel_name() => Some(target),
|
||||
Command::NOTICE(ref target, _) if target.is_channel_name() => Some(target),
|
||||
_ => self.source_nickname()
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a Message into a String according to the IRC protocol.
|
||||
pub fn to_string(&self) -> String {
|
||||
// TODO: tags
|
||||
|
|
Loading…
Reference in a new issue