protected IIrcMessageTarget GetMessageTarget(string targetName)
{
if (targetName == null)
throw new ArgumentNullException("targetName");
if (targetName.Length == 0)
throw new ArgumentException(Resources.MessageValueCannotBeEmptyString, "targetName");
// Check whether target name represents channel, user, or target mask.
var targetNameMatch = Regex.Match(targetName, regexMessageTarget);
var channelName = targetNameMatch.Groups["channel"].GetValue();
var nickName = targetNameMatch.Groups["nick"].GetValue();
var userName = targetNameMatch.Groups["user"].GetValue();
var hostName = targetNameMatch.Groups["host"].GetValue();
var serverName = targetNameMatch.Groups["server"].GetValue();
var targetMask = targetNameMatch.Groups["targetMask"].GetValue();
if (channelName != null)
{
return GetChannelFromName(channelName);
}
if (nickName != null)
{
// Find user by nick name. If no user exists in list, create it and set its properties.
var user = GetUserFromNickName(nickName, true);
if (user.UserName == null)
user.UserName = userName;
if (user.HostName == null)
user.HostName = hostName;
return user;
}
if (userName != null)
{
// Find user by user name. If no user exists in list, create it and set its properties.
var user = GetUserFromNickName(nickName, true);
if (user.HostName == null)
user.HostName = hostName;
return user;
}
if (targetMask != null)
{
return new IrcTargetMask(targetMask);
}
throw new ArgumentException(string.Format(
Resources.MessageInvalidSource, targetName), "targetName");
}