2005-01-15 19:27:25 +00:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace TechBot.IRCLibrary
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// IRC user.
|
|
|
|
/// </summary>
|
|
|
|
public class IrcUser
|
|
|
|
{
|
|
|
|
#region Private fields
|
|
|
|
|
2005-02-16 22:38:49 +00:00
|
|
|
private IrcClient owner;
|
2005-01-15 19:27:25 +00:00
|
|
|
private string nickname;
|
|
|
|
private string decoratedNickname;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Public properties
|
|
|
|
|
2005-02-16 22:38:49 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Owner of this channel.
|
|
|
|
/// </summary>
|
|
|
|
public IrcClient Owner
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return owner;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-15 19:27:25 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Nickname of user.
|
|
|
|
/// </summary>
|
|
|
|
public string Nickname
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return nickname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Decorated nickname of user.
|
|
|
|
/// </summary>
|
|
|
|
public string DecoratedNickname
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return decoratedNickname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Wether user is channel operator.
|
|
|
|
/// </summary>
|
|
|
|
public bool Operator
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return decoratedNickname.StartsWith("@");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Wether user has voice.
|
|
|
|
/// </summary>
|
|
|
|
public bool Voice
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return decoratedNickname.StartsWith("+");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Constructor.
|
|
|
|
/// </summary>
|
2005-02-16 22:38:49 +00:00
|
|
|
/// <param name="owner">Owner of this channel.</param>
|
2005-01-15 19:27:25 +00:00
|
|
|
/// <param name="nickname">Nickname (possibly decorated) of user.</param>
|
2005-02-16 22:38:49 +00:00
|
|
|
public IrcUser(IrcClient owner,
|
|
|
|
string nickname)
|
2005-01-15 19:27:25 +00:00
|
|
|
{
|
2005-02-16 22:38:49 +00:00
|
|
|
if (owner == null)
|
|
|
|
{
|
|
|
|
throw new ArgumentNullException("owner", "Owner cannot be null.");
|
|
|
|
}
|
|
|
|
this.owner = owner;
|
2005-01-15 19:27:25 +00:00
|
|
|
this.decoratedNickname = nickname.Trim();
|
|
|
|
this.nickname = StripDecoration(decoratedNickname);
|
|
|
|
}
|
|
|
|
|
2005-02-16 22:38:49 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Talk to the user.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="text">Text to send to the user.</param>
|
|
|
|
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)));
|
|
|
|
}
|
|
|
|
|
2005-01-15 19:27:25 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Strip docoration of nickname.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nickname">Possible decorated nickname.</param>
|
|
|
|
/// <returns>Undecorated nickname.</returns>
|
|
|
|
public static string StripDecoration(string decoratedNickname)
|
|
|
|
{
|
|
|
|
if (decoratedNickname.StartsWith("@"))
|
|
|
|
{
|
|
|
|
return decoratedNickname.Substring(1);
|
|
|
|
}
|
|
|
|
else if (decoratedNickname.StartsWith("+"))
|
|
|
|
{
|
|
|
|
return decoratedNickname.Substring(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return decoratedNickname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|