Added a response_target helper function (suggested in #44).

This commit is contained in:
Aaron Weiss 2017-06-25 04:47:45 -04:00
parent bd5253016e
commit cfafb39ed9
No known key found for this signature in database
GPG key ID: 0237035D9BF03AE2

View file

@ -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