using System;
namespace TechBot.IRCLibrary
{
///
/// IRC user.
///
public class IrcUser
{
#region Private fields
private IrcClient owner;
private string nickname;
private string decoratedNickname;
#endregion
#region Public properties
///
/// Owner of this channel.
///
public IrcClient Owner
{
get
{
return owner;
}
}
///
/// Nickname of user.
///
public string Nickname
{
get
{
return nickname;
}
}
///
/// Decorated nickname of user.
///
public string DecoratedNickname
{
get
{
return decoratedNickname;
}
}
///
/// Wether user is channel operator.
///
public bool Operator
{
get
{
return decoratedNickname.StartsWith("@");
}
}
///
/// Wether user has voice.
///
public bool Voice
{
get
{
return decoratedNickname.StartsWith("+");
}
}
#endregion
///
/// Constructor.
///
/// Owner of this channel.
/// Nickname (possibly decorated) of user.
public IrcUser(IrcClient owner,
string nickname)
{
if (owner == null)
{
throw new ArgumentNullException("owner", "Owner cannot be null.");
}
this.owner = owner;
this.decoratedNickname = nickname.Trim();
this.nickname = StripDecoration(decoratedNickname);
}
///
/// Talk to the user.
///
/// Text to send to the user.
public void Talk(string text)
{
if (text == null)
{
throw new ArgumentNullException("text", "Text cannot be null.");
}
owner.SendMessage(new IrcMessage(IRC.PRIVMSG,
String.Format("{0} :{1}",
nickname,
text)));
}
///
/// Strip docoration of nickname.
///
/// Possible decorated nickname.
/// Undecorated nickname.
public static string StripDecoration(string decoratedNickname)
{
if (decoratedNickname.StartsWith("@"))
{
return decoratedNickname.Substring(1);
}
else if (decoratedNickname.StartsWith("+"))
{
return decoratedNickname.Substring(1);
}
else
{
return decoratedNickname;
}
}
}
}