diff --git a/src/proto/message.rs b/src/proto/message.rs index 13d968c..3b6ec90 100644 --- a/src/proto/message.rs +++ b/src/proto/message.rs @@ -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