Add XML docs to all public members

This commit is contained in:
Drew DeVault 2015-07-31 21:06:22 -04:00
parent 9540f3948c
commit b1edf96cbc
33 changed files with 694 additions and 54 deletions

View File

@ -5,6 +5,9 @@ using System.Linq;
namespace ChatSharp
{
/// <summary>
/// A collection of IRC channels a user is present in.
/// </summary>
public class ChannelCollection : IEnumerable<IrcChannel>
{
internal ChannelCollection()
@ -32,6 +35,9 @@ namespace ChatSharp
Channels.Remove(channel);
}
/// <summary>
/// Join the specified channel. Only applicable for your own user.
/// </summary>
public void Join(string name)
{
if (Client != null)
@ -40,11 +46,17 @@ namespace ChatSharp
throw new InvalidOperationException("Cannot make other users join channels.");
}
/// <summary>
/// Returns true if the channel by the given name, including channel prefix (i.e. '#'), is in this collection.
/// </summary>
public bool Contains(string name)
{
return Channels.Any(c => c.Name == name);
}
/// <summary>
/// Gets the channel at the given index.
/// </summary>
public IrcChannel this[int index]
{
get
@ -53,6 +65,9 @@ namespace ChatSharp
}
}
/// <summary>
/// Gets the channel by the given channel name, including channel prefix (i.e. '#')
/// </summary>
public IrcChannel this[string name]
{
get
@ -73,11 +88,17 @@ namespace ChatSharp
return channel;
}
/// <summary>
/// Gets an for the channels in this collection.
/// </summary>
public IEnumerator<IrcChannel> GetEnumerator()
{
return Channels.GetEnumerator();
}
/// <summary>
/// Gets an for the channels in this collection.
/// </summary>
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();

View File

@ -20,6 +20,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\ChatSharp.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>

View File

@ -1,8 +1,12 @@
namespace ChatSharp
{
/// <summary>
/// Customize the behavior of the ChatSharp client, including enabling or disabling
/// "helper" features.
/// </summary>
public class ClientSettings
{
public ClientSettings()
internal ClientSettings()
{
WhoIsOnConnect = true;
WhoIsOnJoin = false;
@ -25,6 +29,7 @@ namespace ChatSharp
/// <summary>
/// If true, the library will generate a random nick with alphanumerical characters if it
/// encounters a NICK error.
/// </summary>
public bool GenerateRandomNickIfRefused { get; set; }
/// <summary>
/// If true, the library will WHOIS everyone in a channel upon joining. This procedure can

View File

@ -2,11 +2,17 @@ using System;
namespace ChatSharp.Events
{
/// <summary>
/// Generic event args for events regarding channels.
/// </summary>
public class ChannelEventArgs : EventArgs
{
/// <summary>
/// The channel this event regards.
/// </summary>
public IrcChannel Channel { get; set; }
public ChannelEventArgs(IrcChannel channel)
internal ChannelEventArgs(IrcChannel channel)
{
Channel = channel;
}

View File

@ -2,13 +2,25 @@ using System;
namespace ChatSharp.Events
{
/// <summary>
/// Details of a channel topic event.
/// </summary>
public class ChannelTopicEventArgs : EventArgs
{
/// <summary>
/// The channel whose topic has changed.
/// </summary>
public IrcChannel Channel { get; set; }
/// <summary>
/// The new topic
/// </summary>
public string Topic { get; set; }
/// <summary>
/// The original topic.
/// </summary>
public string OldTopic { get; set; }
public ChannelTopicEventArgs(IrcChannel channel, string oldTopic, string topic)
internal ChannelTopicEventArgs(IrcChannel channel, string oldTopic, string topic)
{
Channel = channel;
Topic = topic;

View File

@ -2,12 +2,21 @@ using System;
namespace ChatSharp.Events
{
/// <summary>
/// Generic event args for events regarding users in channels.
/// </summary>
public class ChannelUserEventArgs : EventArgs
{
/// <summary>
/// The channel this event regards.
/// </summary>
public IrcChannel Channel { get; set; }
/// <summary>
/// The user this event regards.
/// </summary>
public IrcUser User { get; set; }
public ChannelUserEventArgs(IrcChannel channel, IrcUser user)
internal ChannelUserEventArgs(IrcChannel channel, IrcUser user)
{
Channel = channel;
User = user;

View File

@ -2,6 +2,9 @@ using System;
namespace ChatSharp.Events
{
/// <summary>
/// Describes an invalid nick event.
/// </summary>
public class ErronousNickEventArgs : EventArgs
{
private static Random random;
@ -17,11 +20,22 @@ namespace ChatSharp.Events
return new string(nick);
}
/// <summary>
/// The nick that was not accepted by the server.
/// </summary>
/// <value>The invalid nick.</value>
public string InvalidNick { get; set; }
/// <summary>
/// The nick ChatSharp intends to use instead.
/// </summary>
/// <value>The new nick.</value>
public string NewNick { get; set; }
/// <summary>
/// Set to true to instruct ChatSharp NOT to send a valid nick.
/// </summary>
public bool DoNotHandle { get; set; }
public ErronousNickEventArgs(string invalidNick)
internal ErronousNickEventArgs(string invalidNick)
{
InvalidNick = invalidNick;
NewNick = GenerateRandomNick();

View File

@ -2,13 +2,27 @@ using System;
namespace ChatSharp.Events
{
/// <summary>
/// Event describing an IRC notice.
/// </summary>
public class IrcNoticeEventArgs : EventArgs
{
/// <summary>
/// The IRC message that describes this NOTICE.
/// </summary>
/// <value>The message.</value>
public IrcMessage Message { get; set; }
/// <summary>
/// The text of the notice.
/// </summary>
public string Notice { get { return Message.Parameters[1]; } }
/// <summary>
/// The source of the notice (often a user).
/// </summary>
/// <value>The source.</value>
public string Source { get { return Message.Prefix; } }
public IrcNoticeEventArgs(IrcMessage message)
internal IrcNoticeEventArgs(IrcMessage message)
{
if (message.Parameters.Length != 2)
throw new IrcProtocolException("NOTICE was delivered in incorrect format");

View File

@ -2,9 +2,12 @@ using System;
namespace ChatSharp
{
/// <summary>
/// Raised when a user (possibly yourself) is kicked from a channel.
/// </summary>
public class KickEventArgs : EventArgs
{
public KickEventArgs(IrcChannel channel, IrcUser kicker, IrcUser kicked, string reason)
internal KickEventArgs(IrcChannel channel, IrcUser kicker, IrcUser kicked, string reason)
{
Channel = channel;
Kicker = kicker;
@ -12,9 +15,21 @@ namespace ChatSharp
Reason = reason;
}
/// <summary>
/// The channel the user was kicked from.
/// </summary>
public IrcChannel Channel { get; set; }
/// <summary>
/// The user who issued the kick.
/// </summary>
public IrcUser Kicker { get; set; }
/// <summary>
/// The user that was kicked.
/// </summary>
public IrcUser Kicked { get; set; }
/// <summary>
/// The reason provided for the kick (may be null).
/// </summary>
public string Reason { get; set; }
}
}

View File

@ -2,13 +2,26 @@ using System;
namespace ChatSharp.Events
{
/// <summary>
/// Describes a change to a channel or user mode.
/// </summary>
public class ModeChangeEventArgs : EventArgs
{
/// <summary>
/// The target of this change (a channel or user).
/// </summary>
/// <value>The target.</value>
public string Target { get; set; }
/// <summary>
/// The user who issued the change.
/// </summary>
public IrcUser User { get; set; }
/// <summary>
/// The mode change string.
/// </summary>
public string Change { get; set; }
public ModeChangeEventArgs(string target, IrcUser user, string change)
internal ModeChangeEventArgs(string target, IrcUser user, string change)
{
Target = target;
User = user;

View File

@ -2,10 +2,22 @@ using System;
namespace ChatSharp.Events
{
/// <summary>
/// Raised when a user has changed their nick.
/// </summary>
public class NickChangedEventArgs : EventArgs
{
/// <summary>
/// The user whose nick changed.
/// </summary>
public IrcUser User { get; set; }
/// <summary>
/// The original nick.
/// </summary>
public string OldNick { get; set; }
/// <summary>
/// The new nick.
/// </summary>
public string NewNick { get; set; }
}
}

View File

@ -2,12 +2,23 @@ using System;
namespace ChatSharp.Events
{
/// <summary>
/// Describes a private message we have received.
/// The term "private message" is misleading - this describes both messages sent user-to-user,
/// and messages sent to a channel.
/// </summary>
public class PrivateMessageEventArgs : EventArgs
{
/// <summary>
/// The IRC message received.
/// </summary>
public IrcMessage IrcMessage { get; set; }
/// <summary>
/// The private message received.
/// </summary>
public PrivateMessage PrivateMessage { get; set; }
public PrivateMessageEventArgs(IrcClient client, IrcMessage ircMessage, ServerInfo serverInfo)
internal PrivateMessageEventArgs(IrcClient client, IrcMessage ircMessage, ServerInfo serverInfo)
{
IrcMessage = ircMessage;
PrivateMessage = new PrivateMessage(client, IrcMessage, serverInfo);

View File

@ -2,12 +2,21 @@ using System;
namespace ChatSharp.Events
{
/// <summary>
/// Describes a raw IRC message we have sent or received.
/// </summary>
public class RawMessageEventArgs : EventArgs
{
/// <summary>
/// The text of the raw IRC message.
/// </summary>
public string Message { get; set; }
/// <summary>
/// True if this message is going from ChatSharp to the server.
/// </summary>
public bool Outgoing { get; set; }
public RawMessageEventArgs(string message, bool outgoing)
internal RawMessageEventArgs(string message, bool outgoing)
{
Message = message;
Outgoing = outgoing;

View File

@ -2,11 +2,17 @@ using System;
namespace ChatSharp.Events
{
/// <summary>
/// Raised when we have received the MOTD from the server.
/// </summary>
public class ServerMOTDEventArgs : EventArgs
{
/// <summary>
/// The message of the day.
/// </summary>
public string MOTD { get; set; }
public ServerMOTDEventArgs(string motd)
internal ServerMOTDEventArgs(string motd)
{
MOTD = motd;
}

View File

@ -3,11 +3,17 @@ using System.Net.Sockets;
namespace ChatSharp.Events
{
/// <summary>
/// Raised when a SocketError occurs.
/// </summary>
public class SocketErrorEventArgs : EventArgs
{
/// <summary>
/// The error that has occured.
/// </summary>
public SocketError SocketError { get; set; }
public SocketErrorEventArgs(SocketError socketError)
internal SocketErrorEventArgs(SocketError socketError)
{
SocketError = socketError;
}

View File

@ -2,11 +2,17 @@ using System;
namespace ChatSharp.Events
{
/// <summary>
/// Describes the features the server supports.
/// </summary>
public class SupportsEventArgs : EventArgs
{
/// <summary>
/// The server's supported featureset.
/// </summary>
public ServerInfo ServerInfo { get; set; }
public SupportsEventArgs(ServerInfo serverInfo)
internal SupportsEventArgs(ServerInfo serverInfo)
{
ServerInfo = serverInfo;
}

View File

@ -2,11 +2,17 @@
namespace ChatSharp.Events
{
/// <summary>
/// Generic event args that represent an event regarding a user.
/// </summary>
public class UserEventArgs : EventArgs
{
/// <summary>
/// The user this regards.
/// </summary>
public IrcUser User { get; set; }
public UserEventArgs(IrcUser user)
internal UserEventArgs(IrcUser user)
{
User = user;
}

View File

@ -2,15 +2,18 @@ using System;
namespace ChatSharp.Events
{
/// <summary>
/// Describes the response to a WHOIS query. Note that ChatSharp may generate WHOIS
/// queries that the consumer did not ask for.
/// </summary>
public class WhoIsReceivedEventArgs : EventArgs
{
public WhoIs WhoIsResponse
{
get;
set;
}
/// <summary>
/// The WHOIS response from the server.
/// </summary>
public WhoIs WhoIsResponse { get; set; }
public WhoIsReceivedEventArgs(WhoIs whoIsResponse)
internal WhoIsReceivedEventArgs(WhoIs whoIsResponse)
{
WhoIsResponse = whoIsResponse;
}

View File

@ -3,7 +3,7 @@ using System.Linq;
namespace ChatSharp.Handlers
{
public static class UserHandlers
internal static class UserHandlers
{
public static void HandleWhoIsUser(IrcClient client, IrcMessage message)
{

View File

@ -3,11 +3,17 @@ using System.Linq;
namespace ChatSharp
{
/// <summary>
/// An IRC channel.
/// </summary>
public class IrcChannel
{
private IrcClient Client { get; set; }
internal string _Topic;
/// <summary>
/// The channel topic. Will send a TOPIC command if set.
/// </summary>
public string Topic
{
get
@ -21,9 +27,22 @@ namespace ChatSharp
}
}
/// <summary>
/// The name, including the prefix (i.e. #), of this channel.
/// </summary>
/// <value>The name.</value>
public string Name { get; internal set; }
/// <summary>
/// The channel mode. May be null if we have not received the mode yet.
/// </summary>
public string Mode { get; internal set; }
/// <summary>
/// The users in this channel.
/// </summary>
public UserPoolView Users { get; private set; }
/// <summary>
/// Users in this channel, grouped by mode. Users with no special mode are grouped under null.
/// </summary>
public Dictionary<char?, UserPoolView> UsersByMode { get; set; }
internal IrcChannel(IrcClient client, string name)
@ -33,36 +52,57 @@ namespace ChatSharp
Users = new UserPoolView(client.Users.Where(u => u.Channels.Contains(this)));
}
/// <summary>
/// Invites a user to this channel.
/// </summary>
public void Invite(string nick)
{
Client.InviteUser(Name, nick);
}
/// <summary>
/// Kicks a user from this channel.
/// </summary>
public void Kick(string nick)
{
Client.KickUser(Name, nick);
}
/// <summary>
/// Kicks a user from this channel, giving a reason for the kick.
/// </summary>
public void Kick(string nick, string reason)
{
Client.KickUser(Name, nick, reason);
}
/// <summary>
/// Parts this channel.
/// </summary>
public void Part()
{
Client.PartChannel(Name);
}
/// <summary>
/// Parts this channel, giving a reason for your departure.
/// </summary>
public void Part(string reason)
{
Client.PartChannel(Name); // TODO
}
/// <summary>
/// Sends a PRIVMSG to this channel.
/// </summary>
public void SendMessage(string message)
{
Client.SendMessage(message, Name);
}
/// <summary>
/// Set the channel mode.
/// </summary>
public void ChangeMode(string change)
{
Client.ChangeMode(Name, change);

View File

@ -5,12 +5,18 @@ namespace ChatSharp
{
public partial class IrcClient
{
/// <summary>
/// Changes your nick.
/// </summary>
public void Nick(string newNick)
{
SendRawMessage("NICK {0}", newNick);
User.Nick = newNick;
}
/// <summary>
/// Sends a message to one or more destinations (channels or users).
/// </summary>
public void SendMessage(string message, params string[] destinations)
{
const string illegalCharacters = "\r\n\0";
@ -20,6 +26,9 @@ namespace ChatSharp
SendRawMessage("PRIVMSG {0} :{1}{2}", to, PrivmsgPrefix, message);
}
/// <summary>
/// Sends a CTCP action (i.e. "* SirCmpwn waves hello") to one or more destinations.
/// </summary>
public void SendAction(string message, params string[] destinations)
{
const string illegalCharacters = "\r\n\0";
@ -29,6 +38,9 @@ namespace ChatSharp
SendRawMessage("PRIVMSG {0} :\x0001ACTION {1}{2}\x0001", to, PrivmsgPrefix, message);
}
/// <summary>
/// Leaves the specified channel.
/// </summary>
public void PartChannel(string channel)
{
if (!Channels.Contains(channel))
@ -37,6 +49,9 @@ namespace ChatSharp
Channels.Remove(Channels[channel]);
}
/// <summary>
/// Leaves the specified channel, giving a reason for your departure.
/// </summary>
public void PartChannel(string channel, string reason)
{
if (!Channels.Contains(channel))
@ -45,6 +60,9 @@ namespace ChatSharp
Channels.Remove(Channels[channel]);
}
/// <summary>
/// Joins the specified channel.
/// </summary>
public void JoinChannel(string channel)
{
if (Channels.Contains(channel))
@ -52,6 +70,9 @@ namespace ChatSharp
SendRawMessage("JOIN {0}", channel);
}
/// <summary>
/// Sets the topic for the specified channel.
/// </summary>
public void SetTopic(string channel, string topic)
{
if (!Channels.Contains(channel))
@ -59,31 +80,50 @@ namespace ChatSharp
SendRawMessage("TOPIC {0} :{1}", channel, topic);
}
/// <summary>
/// Retrieves the topic for the specified channel.
/// </summary>
public void GetTopic(string channel)
{
SendRawMessage("TOPIC {0}", channel);
}
/// <summary>
/// Kicks the specified user from the specified channel.
/// </summary>
public void KickUser(string channel, string user)
{
SendRawMessage("KICK {0} {1} :{1}", channel, user);
}
/// <summary>
/// Kicks the specified user from the specified channel.
/// </summary>
public void KickUser(string channel, string user, string reason)
{
SendRawMessage("KICK {0} {1} :{2}", channel, user, reason);
}
/// <summary>
/// Invites the specified user to the specified channel.
/// </summary>
public void InviteUser(string channel, string user)
{
SendRawMessage("INVITE {1} {0}", channel, user);
}
/// <summary>
/// Sends a WHOIS query asking for information on the given nick.
/// </summary>
public void WhoIs(string nick)
{
WhoIs(nick, null);
}
/// <summary>
/// Sends a WHOIS query asking for information on the given nick, and a callback
/// to run when we have received the response.
/// </summary>
public void WhoIs(string nick, Action<WhoIs> callback)
{
var whois = new WhoIs();
@ -95,11 +135,17 @@ namespace ChatSharp
SendRawMessage("WHOIS {0}", nick);
}
/// <summary>
/// Requests the mode of a channel from the server.
/// </summary>
public void GetMode(string channel)
{
GetMode(channel, null);
}
/// <summary>
/// Requests the mode of a channel from the server, and passes it to a callback later.
/// </summary>
public void GetMode(string channel, Action<IrcChannel> callback)
{
RequestManager.QueueOperation("MODE " + channel, new RequestOperation(channel, ro =>
@ -111,11 +157,18 @@ namespace ChatSharp
SendRawMessage("MODE {0}", channel);
}
public void ChangeMode(string channel, string change)
/// <summary>
/// Sets the mode of a target.
/// </summary>
public void ChangeMode(string target, string change)
{
SendRawMessage("MODE {0} {1}", channel, change);
SendRawMessage("MODE {0} {1}", target, change);
}
/// <summary>
/// Gets a collection of masks from a channel by a mode. This can be used, for example,
/// to get a list of bans.
/// </summary>
public void GetModeList(string channel, char mode, Action<MaskCollection> callback)
{
RequestManager.QueueOperation("GETMODE " + mode + " " + channel, new RequestOperation(new MaskCollection(), ro =>

View File

@ -11,10 +11,21 @@ using System.Timers;
namespace ChatSharp
{
public partial class IrcClient
/// <summary>
/// An IRC client.
/// </summary>
public sealed partial class IrcClient
{
/// <summary>
/// A raw IRC message handler.
/// </summary>
public delegate void MessageHandler(IrcClient client, IrcMessage message);
private Dictionary<string, MessageHandler> Handlers { get; set; }
/// <summary>
/// Sets a custom handler for an IRC message. This applies to the low level IRC protocol,
/// not for private messages.
/// </summary>
public void SetHandler(string message, MessageHandler handler)
{
#if DEBUG
@ -43,8 +54,14 @@ namespace ChatSharp
private ConcurrentQueue<string> WriteQueue { get; set; }
private bool IsWriting { get; set; }
internal RequestManager RequestManager { get; set; }
internal string ServerNameFromPing { get; set; }
/// <summary>
/// The address this client is connected to, or will connect to. Setting this
/// after the client is connected will not cause a reconnect.
/// </summary>
public string ServerAddress
{
get
@ -64,18 +81,58 @@ namespace ChatSharp
}
}
/// <summary>
/// The low level TCP stream for this client.
/// </summary>
public Stream NetworkStream { get; set; }
/// <summary>
/// If true, SSL will be used to connect.
/// </summary>
public bool UseSSL { get; private set; }
/// <summary>
/// If true, invalid SSL certificates are ignored.
/// </summary>
public bool IgnoreInvalidSSL { get; set; }
/// <summary>
/// The character encoding to use for the connection. Defaults to UTF-8.
/// </summary>
/// <value>The encoding.</value>
public Encoding Encoding { get; set; }
/// <summary>
/// The user this client is logged in as.
/// </summary>
/// <value>The user.</value>
public IrcUser User { get; set; }
/// <summary>
/// The channels this user is joined to.
/// </summary>
public ChannelCollection Channels { get; private set; }
/// <summary>
/// Settings that control the behavior of ChatSharp.
/// </summary>
public ClientSettings Settings { get; set; }
public RequestManager RequestManager { get; set; }
/// <summary>
/// Information about the server we are connected to. Servers may not send us this information,
/// but it's required for ChatSharp to function, so by default this is a guess. Handle
/// IrcClient.ServerInfoRecieved if you'd like to know when it's populated with real information.
/// </summary>
public ServerInfo ServerInfo { get; set; }
/// <summary>
/// A string to prepend to all PRIVMSGs sent. Many IRC bots prefix their messages with \u200B, to
/// indicate to other bots that you are a bot.
/// </summary>
public string PrivmsgPrefix { get; set; }
/// <summary>
/// A list of users on this network that we are aware of.
/// </summary>
public UserPool Users { get; set; }
/// <summary>
/// Creates a new IRC client, but will not connect until ConnectAsync is called.
/// </summary>
/// <param name="serverAddress">Server address including port in the form of "hostname:port".</param>
/// <param name="user">The IRC user to connect as.</param>
/// <param name="useSSL">Connect with SSL if true.</param>
public IrcClient(string serverAddress, IrcUser user, bool useSSL = false)
{
if (serverAddress == null) throw new ArgumentNullException("serverAddress");
@ -91,11 +148,15 @@ namespace ChatSharp
RequestManager = new RequestManager();
UseSSL = useSSL;
WriteQueue = new ConcurrentQueue<string>();
ServerInfo = new ServerInfo();
PrivmsgPrefix = "";
Users = new UserPool();
Users.Add(User); // Add self to user pool
}
/// <summary>
/// Connects to the IRC server.
/// </summary>
public void ConnectAsync()
{
if (Socket != null && Socket.Connected) throw new InvalidOperationException("Socket is already connected to server.");
@ -122,11 +183,17 @@ namespace ChatSharp
Socket.BeginConnect(ServerHostname, ServerPort, ConnectComplete, null);
}
/// <summary>
/// Send a QUIT message and disconnect.
/// </summary>
public void Quit()
{
Quit(null);
}
/// <summary>
/// Send a QUIT message with a reason and disconnect.
/// </summary>
public void Quit(string reason)
{
if (reason == null)
@ -219,6 +286,9 @@ namespace ChatSharp
}
}
/// <summary>
/// Send a raw IRC message. Behaves like /quote in most IRC clients.
/// </summary>
public void SendRawMessage(string message, params object[] format)
{
if (NetworkStream == null)
@ -241,6 +311,9 @@ namespace ChatSharp
}
}
/// <summary>
/// Send a raw IRC message. Behaves like /quote in most IRC clients.
/// </summary>
public void SendIrcMessage(IrcMessage message)
{
SendRawMessage(message.RawMessage);
@ -283,108 +356,172 @@ namespace ChatSharp
}
}
/// <summary>
/// Raised for socket errors. ChatSharp does not automatically reconnect.
/// </summary>
public event EventHandler<SocketErrorEventArgs> NetworkError;
protected internal virtual void OnNetworkError(SocketErrorEventArgs e)
internal void OnNetworkError(SocketErrorEventArgs e)
{
if (NetworkError != null) NetworkError(this, e);
}
/// <summary>
/// Occurs when a raw message is sent.
/// </summary>
public event EventHandler<RawMessageEventArgs> RawMessageSent;
protected internal virtual void OnRawMessageSent(RawMessageEventArgs e)
internal void OnRawMessageSent(RawMessageEventArgs e)
{
if (RawMessageSent != null) RawMessageSent(this, e);
}
/// <summary>
/// Occurs when a raw message recieved.
/// </summary>
public event EventHandler<RawMessageEventArgs> RawMessageRecieved;
protected internal virtual void OnRawMessageRecieved(RawMessageEventArgs e)
internal void OnRawMessageRecieved(RawMessageEventArgs e)
{
if (RawMessageRecieved != null) RawMessageRecieved(this, e);
}
/// <summary>
/// Occurs when a notice recieved.
/// </summary>
public event EventHandler<IrcNoticeEventArgs> NoticeRecieved;
protected internal virtual void OnNoticeRecieved(IrcNoticeEventArgs e)
internal void OnNoticeRecieved(IrcNoticeEventArgs e)
{
if (NoticeRecieved != null) NoticeRecieved(this, e);
}
/// <summary>
/// Occurs when the server has sent us part of the MOTD.
/// </summary>
public event EventHandler<ServerMOTDEventArgs> MOTDPartRecieved;
protected internal virtual void OnMOTDPartRecieved(ServerMOTDEventArgs e)
internal void OnMOTDPartRecieved(ServerMOTDEventArgs e)
{
if (MOTDPartRecieved != null) MOTDPartRecieved(this, e);
}
/// <summary>
/// Occurs when the entire server MOTD has been recieved.
/// </summary>
public event EventHandler<ServerMOTDEventArgs> MOTDRecieved;
protected internal virtual void OnMOTDRecieved(ServerMOTDEventArgs e)
internal void OnMOTDRecieved(ServerMOTDEventArgs e)
{
if (MOTDRecieved != null) MOTDRecieved(this, e);
}
/// <summary>
/// Occurs when a private message recieved. This can be a channel OR a user message.
/// </summary>
public event EventHandler<PrivateMessageEventArgs> PrivateMessageRecieved;
protected internal virtual void OnPrivateMessageRecieved(PrivateMessageEventArgs e)
internal void OnPrivateMessageRecieved(PrivateMessageEventArgs e)
{
if (PrivateMessageRecieved != null) PrivateMessageRecieved(this, e);
}
/// <summary>
/// Occurs when a message is recieved in an IRC channel.
/// </summary>
public event EventHandler<PrivateMessageEventArgs> ChannelMessageRecieved;
protected internal virtual void OnChannelMessageRecieved(PrivateMessageEventArgs e)
internal void OnChannelMessageRecieved(PrivateMessageEventArgs e)
{
if (ChannelMessageRecieved != null) ChannelMessageRecieved(this, e);
}
/// <summary>
/// Occurs when a message is recieved from a user.
/// </summary>
public event EventHandler<PrivateMessageEventArgs> UserMessageRecieved;
protected internal virtual void OnUserMessageRecieved(PrivateMessageEventArgs e)
internal void OnUserMessageRecieved(PrivateMessageEventArgs e)
{
if (UserMessageRecieved != null) UserMessageRecieved(this, e);
}
/// <summary>
/// Raised if the nick you've chosen is in use. By default, ChatSharp will pick a
/// random nick to use instead. Set ErronousNickEventArgs.DoNotHandle to prevent this.
/// </summary>
public event EventHandler<ErronousNickEventArgs> NickInUse;
protected internal virtual void OnNickInUse(ErronousNickEventArgs e)
internal void OnNickInUse(ErronousNickEventArgs e)
{
if (NickInUse != null) NickInUse(this, e);
}
/// <summary>
/// Occurs when a user or channel mode is changed.
/// </summary>
public event EventHandler<ModeChangeEventArgs> ModeChanged;
protected internal virtual void OnModeChanged(ModeChangeEventArgs e)
internal void OnModeChanged(ModeChangeEventArgs e)
{
if (ModeChanged != null) ModeChanged(this, e);
}
/// <summary>
/// Occurs when a user joins a channel.
/// </summary>
public event EventHandler<ChannelUserEventArgs> UserJoinedChannel;
protected internal virtual void OnUserJoinedChannel(ChannelUserEventArgs e)
internal void OnUserJoinedChannel(ChannelUserEventArgs e)
{
if (UserJoinedChannel != null) UserJoinedChannel(this, e);
}
/// <summary>
/// Occurs when a user parts a channel.
/// </summary>
public event EventHandler<ChannelUserEventArgs> UserPartedChannel;
protected internal virtual void OnUserPartedChannel(ChannelUserEventArgs e)
internal void OnUserPartedChannel(ChannelUserEventArgs e)
{
if (UserPartedChannel != null) UserPartedChannel(this, e);
}
/// <summary>
/// Occurs when we have received the list of users present in a channel.
/// </summary>
public event EventHandler<ChannelEventArgs> ChannelListRecieved;
protected internal virtual void OnChannelListRecieved(ChannelEventArgs e)
internal void OnChannelListRecieved(ChannelEventArgs e)
{
if (ChannelListRecieved != null) ChannelListRecieved(this, e);
}
/// <summary>
/// Occurs when we have received the topic of a channel.
/// </summary>
public event EventHandler<ChannelTopicEventArgs> ChannelTopicReceived;
protected internal virtual void OnChannelTopicReceived(ChannelTopicEventArgs e)
internal void OnChannelTopicReceived(ChannelTopicEventArgs e)
{
if (ChannelTopicReceived != null) ChannelTopicReceived(this, e);
}
/// <summary>
/// Occurs when the IRC connection is established and it is safe to begin interacting with the server.
/// </summary>
public event EventHandler<EventArgs> ConnectionComplete;
protected internal virtual void OnConnectionComplete(EventArgs e)
internal void OnConnectionComplete(EventArgs e)
{
if (ConnectionComplete != null) ConnectionComplete(this, e);
}
/// <summary>
/// Occurs when we receive server info (such as max nick length).
/// </summary>
public event EventHandler<SupportsEventArgs> ServerInfoRecieved;
protected internal virtual void OnServerInfoRecieved(SupportsEventArgs e)
internal void OnServerInfoRecieved(SupportsEventArgs e)
{
if (ServerInfoRecieved != null) ServerInfoRecieved(this, e);
}
/// <summary>
/// Occurs when a user is kicked.
/// </summary>
public event EventHandler<KickEventArgs> UserKicked;
protected internal virtual void OnUserKicked(KickEventArgs e)
internal void OnUserKicked(KickEventArgs e)
{
if (UserKicked != null) UserKicked(this, e);
}
/// <summary>
/// Occurs when a WHOIS response is received.
/// </summary>
public event EventHandler<WhoIsReceivedEventArgs> WhoIsReceived;
protected internal virtual void OnWhoIsReceived(WhoIsReceivedEventArgs e)
internal void OnWhoIsReceived(WhoIsReceivedEventArgs e)
{
if (WhoIsReceived != null) WhoIsReceived(this, e);
}
/// <summary>
/// Occurs when a user has changed their nick.
/// </summary>
public event EventHandler<NickChangedEventArgs> NickChanged;
protected internal virtual void OnNickChanged(NickChangedEventArgs e)
internal void OnNickChanged(NickChangedEventArgs e)
{
if (NickChanged != null) NickChanged(this, e);
}
/// <summary>
/// Occurs when a user has quit.
/// </summary>
public event EventHandler<UserEventArgs> UserQuit;
protected internal virtual void OnUserQuit(UserEventArgs e)
internal void OnUserQuit(UserEventArgs e)
{
if (UserQuit != null) UserQuit(this, e);
}

View File

@ -3,13 +3,32 @@ using System.Linq;
namespace ChatSharp
{
/// <summary>
/// Represents a raw IRC message. This is a low-level construct - PrivateMessage is used
/// to represent messages sent from users.
/// </summary>
public class IrcMessage
{
/// <summary>
/// The unparsed message.
/// </summary>
public string RawMessage { get; private set; }
/// <summary>
/// The message prefix.
/// </summary>
public string Prefix { get; private set; }
/// <summary>
/// The message command.
/// </summary>
public string Command { get; private set; }
/// <summary>
/// Additional parameters supplied with the message.
/// </summary>
public string[] Parameters { get; private set; }
/// <summary>
/// Initializes and decodes an IRC message, given the raw message from the server.
/// </summary>
public IrcMessage(string rawMessage)
{
RawMessage = rawMessage;

View File

@ -2,13 +2,16 @@ using System;
namespace ChatSharp
{
/// <summary>
/// Raised when the server complains about IRC protocol errors.
/// </summary>
public class IrcProtocolException : Exception
{
public IrcProtocolException()
internal IrcProtocolException()
{
}
public IrcProtocolException(string message) : base(message)
internal IrcProtocolException(string message) : base(message)
{
}

View File

@ -4,6 +4,9 @@ using System.Collections.Generic;
namespace ChatSharp
{
/// <summary>
/// A user connected to IRC.
/// </summary>
public class IrcUser : IEquatable<IrcUser>
{
internal IrcUser()
@ -12,6 +15,9 @@ namespace ChatSharp
ChannelModes = new Dictionary<IrcChannel, char?>();
}
/// <summary>
/// Constructs an IrcUser given a hostmask or nick.
/// </summary>
public IrcUser(string host) : this()
{
if (!host.Contains("@") && !host.Contains("!"))
@ -32,6 +38,9 @@ namespace ChatSharp
}
}
/// <summary>
/// Constructs an IrcUser given a nick and user.
/// </summary>
public IrcUser(string nick, string user) : this()
{
Nick = nick;
@ -40,26 +49,60 @@ namespace ChatSharp
Mode = string.Empty;
}
/// <summary>
/// Constructs an IRC user given a nick, user, and password.
/// </summary>
public IrcUser(string nick, string user, string password) : this(nick, user)
{
Password = password;
}
/// <summary>
/// Constructs an IRC user given a nick, user, password, and real name.
/// </summary>
public IrcUser(string nick, string user, string password, string realName) : this(nick, user, password)
{
RealName = realName;
}
/// <summary>
/// The user's nick.
/// </summary>
public string Nick { get; internal set; }
/// <summary>
/// The user's user (an IRC construct, a string that identifies your username).
/// </summary>
public string User { get; internal set; }
/// <summary>
/// The user's password. Will not be set on anyone but your own user.
/// </summary>
public string Password { get; internal set; }
/// <summary>
/// The user's mode.
/// </summary>
/// <value>The mode.</value>
public string Mode { get; internal set; }
/// <summary>
/// The user's real name.
/// </summary>
/// <value>The name of the real.</value>
public string RealName { get; internal set; }
/// <summary>
/// The user's hostname.
/// </summary>
public string Hostname { get; internal set; }
/// <summary>
/// Channels this user is present in. Note that this only includes channels you are
/// also present in, even after a successful WHOIS.
/// </summary>
/// <value>The channels.</value>
public ChannelCollection Channels { get; set; }
internal Dictionary<IrcChannel, char?> ChannelModes { get; set; }
/// <summary>
/// This user's hostmask (nick!user@host).
/// </summary>
public string Hostmask
{
get
@ -68,6 +111,10 @@ namespace ChatSharp
}
}
/// <summary>
/// Returns true if the user matches the given mask. Can be used to check if a ban applies
/// to this user, for example.
/// </summary>
public bool Match(string mask)
{
if (mask.Contains("!") && mask.Contains("@"))
@ -81,6 +128,9 @@ namespace ChatSharp
return false;
}
/// <summary>
/// Checks if the given hostmask matches the given mask.
/// </summary>
public static bool Match(string mask, string value)
{
if (value == null)
@ -110,11 +160,17 @@ namespace ChatSharp
return i == mask.Length && j == value.Length;
}
/// <summary>
/// True if this user is equal to another (compares hostmasks).
/// </summary>
public bool Equals(IrcUser other)
{
return other.Hostmask == Hostmask;
}
/// <summary>
/// True if this user is equal to another (compares hostmasks).
/// </summary>
public override bool Equals(object obj)
{
if (obj is IrcUser)
@ -122,11 +178,17 @@ namespace ChatSharp
return false;
}
/// <summary>
/// Returns the hash code of the user's hostmask.
/// </summary>
public override int GetHashCode()
{
return Hostmask.GetHashCode();
}
/// <summary>
/// Returns the user's hostmask.
/// </summary>
public override string ToString()
{
return Hostmask;

View File

@ -2,17 +2,31 @@ using System;
namespace ChatSharp
{
/// <summary>
/// A mask that can be used to match against a user's hostmask in a channel list,
/// such as banned users.
/// </summary>
public class Mask
{
public Mask(string value, IrcUser creator, DateTime creationTime)
internal Mask(string value, IrcUser creator, DateTime creationTime)
{
Value = value;
Creator = creator;
CreationTime = creationTime;
}
/// <summary>
/// The user who created this mask.
/// </summary>
public IrcUser Creator { get; set; }
/// <summary>
/// The time this mask was added to the channel list.
/// </summary>
/// <value>The creation time.</value>
public DateTime CreationTime { get; set; }
/// <summary>
/// The mask string.
/// </summary>
public string Value { get; set; }
}
}

View File

@ -4,6 +4,9 @@ using System.Linq;
namespace ChatSharp
{
/// <summary>
/// A collection of masks from a channel list.
/// </summary>
public class MaskCollection : IEnumerable<Mask>
{
internal MaskCollection()
@ -13,26 +16,43 @@ namespace ChatSharp
private List<Mask> Masks { get; set; }
/// <summary>
/// Adds a mask to the collection. This only modifies the local mask list, changes are
/// not flushed to the server.
/// </summary>
public void Add(Mask mask)
{
Masks.Add(mask);
}
/// <summary>
/// Removes a mask from the collection. This only modifies the local mask list, changes are
/// not flushed to the server.
/// </summary>
public void Remove(Mask mask)
{
Masks.Remove(mask);
}
/// <summary>
/// True if this collection includes the given mask.
/// </summary>
public bool Contains(Mask mask)
{
return Masks.Contains(mask);
}
/// <summary>
/// True if this collection includes any masks that are equal to the given mask.
/// </summary>
public bool ContainsMask(Mask mask)
{
return Masks.Any(m => m.Value == mask.Value);
}
/// <summary>
/// Returns the mask at the requested index.
/// </summary>
public Mask this[int index]
{
get
@ -41,11 +61,17 @@ namespace ChatSharp
}
}
/// <summary>
/// True if any mask matches the given user.
/// </summary>
public bool ContainsMatch(IrcUser user)
{
return Masks.Any(m => user.Match(m.Value));
}
/// <summary>
/// Returns the mask that matches the given user.
/// </summary>
public Mask GetMatch(IrcUser user)
{
var match = Masks.FirstOrDefault(m => user.Match(m.Value));
@ -54,6 +80,9 @@ namespace ChatSharp
return match;
}
/// <summary>
/// Enumerates over the masks in this collection.
/// </summary>
public IEnumerator<Mask> GetEnumerator()
{
return Masks.GetEnumerator();

View File

@ -2,9 +2,12 @@ using System.Linq;
namespace ChatSharp
{
/// <summary>
/// Represents an IRC message sent from user-to-user or user-to-channel.
/// </summary>
public class PrivateMessage
{
public PrivateMessage(IrcClient client, IrcMessage message, ServerInfo serverInfo)
internal PrivateMessage(IrcClient client, IrcMessage message, ServerInfo serverInfo)
{
Source = message.Parameters[0];
Message = message.Parameters[1];
@ -16,9 +19,21 @@ namespace ChatSharp
Source = User.Nick;
}
/// <summary>
/// The user that sent this message.
/// </summary>
public IrcUser User { get; set; }
/// <summary>
/// The message text.
/// </summary>
public string Message { get; set; }
/// <summary>
/// The source of the message (a nick or a channel name).
/// </summary>
public string Source { get; set; }
/// <summary>
/// True if this message was posted to a channel.
/// </summary>
public bool IsChannelMessage { get; set; }
}
}

View File

@ -4,7 +4,7 @@ using System.Linq;
namespace ChatSharp
{
public class RequestManager
internal class RequestManager
{
public RequestManager()
{
@ -34,7 +34,7 @@ namespace ChatSharp
}
}
public class RequestOperation
internal class RequestOperation
{
public object State { get; set; }
public Action<RequestOperation> Callback { get; set; }

View File

@ -1,8 +1,11 @@
namespace ChatSharp
{
/// <summary>
/// Information provided by the server about its featureset.
/// </summary>
public class ServerInfo
{
public ServerInfo()
internal ServerInfo()
{
// Guess for some defaults
Prefixes = new[] { "ov", "@+" };
@ -82,6 +85,9 @@ namespace ChatSharp
/// </summary>
public int? MaxAwayLength { get; set; }
/// <summary>
/// Modes a server supports that are applicable to channels.
/// </summary>
public class ChannelModes
{
internal ChannelModes()
@ -94,13 +100,31 @@ namespace ChatSharp
ChannelUserModes = "vo"; // I have no idea what I'm doing here
}
/// <summary>
/// Modes that are used for lists (i.e. bans).
/// </summary>
public string ChannelLists { get; internal set; }
/// <summary>
/// Modes that can be set on a user of a channel (i.e. ops, voice, etc).
/// </summary>
public string ChannelUserModes { get; set; }
/// <summary>
/// Modes that take a parameter (i.e. +k).
/// </summary>
public string ParameterizedSettings { get; internal set; }
/// <summary>
/// Modes that take an optional parameter (i.e. +f).
/// </summary>
public string OptionallyParameterizedSettings { get; internal set; }
/// <summary>
/// Modes that change channel settings.
/// </summary>
public string Settings { get; internal set; }
}
/// <summary>
/// Limits imposed on channel lists, such as the maximum bans per channel.
/// </summary>
public class ModeListLimit
{
internal ModeListLimit(char mode, int maximum)
@ -109,7 +133,13 @@ namespace ChatSharp
Maximum = maximum;
}
/// <summary>
/// The mode character this applies to (i.e. 'b')
/// </summary>
public char Mode { get; internal set; }
/// <summary>
/// The maximum entries for this list.
/// </summary>
public int Maximum { get; internal set; }
}
}

View File

@ -4,6 +4,11 @@ using System.Linq;
namespace ChatSharp
{
/// <summary>
/// A pool of users the client is aware of on the network. IrcUser objects in this
/// pool are shared across the entire library (e.g. a PrivateMessage will reuse an
/// IrcUser object from this poll).
/// </summary>
public class UserPool : IEnumerable<IrcUser>
{
private List<IrcUser> Users { get; set; }
@ -13,6 +18,9 @@ namespace ChatSharp
Users = new List<IrcUser>();
}
/// <summary>
/// Gets the IrcUser with the specified nick.
/// </summary>
public IrcUser this[string nick]
{
get
@ -42,16 +50,27 @@ namespace ChatSharp
Users.Remove(this[nick]);
}
/// <summary>
/// Returns true if any user in the pool matches this mask. Note that not all users
/// in the user pool will be fully populated, even if you set ClientSettings.WhoIsOnJoin
/// to true (it takes time to whois everyone in your channels).
/// </summary>
public bool ContainsMask(string mask)
{
return Users.Any(u => u.Match(mask));
}
/// <summary>
/// Returns true if any user in the pool has the specified nick.
/// </summary>
public bool Contains(string nick)
{
return Users.Any(u => u.Nick == nick);
}
/// <summary>
/// Returns true if the given IrcUser is in the pool.
/// </summary>
public bool Contains(IrcUser user)
{
return Users.Any(u => u.Hostmask == user.Hostmask);
@ -81,6 +100,9 @@ namespace ChatSharp
throw new KeyNotFoundException();
}
/// <summary>
/// Enumerates over the users in this collection.
/// </summary>
public IEnumerator<IrcUser> GetEnumerator()
{
return Users.GetEnumerator();

View File

@ -4,6 +4,9 @@ using System.Linq;
namespace ChatSharp
{
/// <summary>
/// A filtered view of the user pool.
/// </summary>
public class UserPoolView : IEnumerable<IrcUser>
{
private UserPool Pool { get; set; }
@ -14,6 +17,9 @@ namespace ChatSharp
Users = users;
}
/// <summary>
/// Gets the IrcUser with the specified nick.
/// </summary>
public IrcUser this[string nick]
{
get
@ -33,21 +39,35 @@ namespace ChatSharp
}
}
/// <summary>
/// Returns true if any user in the pool matches this mask. Note that not all users
/// in the user pool will be fully populated, even if you set ClientSettings.WhoIsOnJoin
/// to true (it takes time to whois everyone in your channels).
/// </summary>
public bool ContainsMask(string mask)
{
return Users.Any(u => u.Match(mask));
}
/// <summary>
/// Returns true if any user in the pool has the specified nick.
/// </summary>
public bool Contains(string nick)
{
return Users.Any(u => u.Nick == nick);
}
/// <summary>
/// Returns true if the given IrcUser is in the pool.
/// </summary>
public bool Contains(IrcUser user)
{
return Users.Any(u => u.Hostmask == user.Hostmask);
}
/// <summary>
/// Enumerates over the users in this collection (with the filter applied).
/// </summary>
public IEnumerator<IrcUser> GetEnumerator()
{
return Users.GetEnumerator();

View File

@ -1,5 +1,9 @@
namespace ChatSharp
{
/// <summary>
/// The results of an IRC WHOIS query. Depending on the capabilities of the server you're connected to,
/// some of these fields may be null.
/// </summary>
public class WhoIs
{
internal WhoIs()
@ -9,12 +13,35 @@ namespace ChatSharp
Channels = new string[0];
}
/// <summary>
/// A fully populated IrcUser, including hostname, real name, etc.
/// </summary>
public IrcUser User { get; set; }
/// <summary>
/// A list of channels this user is joined to. Depending on the IRC network you connect to,
/// this may omit channels that you are not present in.
/// </summary>
public string[] Channels { get; set; }
/// <summary>
/// If true, the whois'd user is a network operator.
/// </summary>
public bool IrcOp { get; set; }
/// <summary>
/// Seconds since this user last interacted with IRC.
/// </summary>
public int SecondsIdle { get; set; }
/// <summary>
/// The server this user is connected to.
/// </summary>
public string Server { get; set; }
/// <summary>
/// Additional information about the server this user is connected to.
/// </summary>
/// <value>The server info.</value>
public string ServerInfo { get; set; }
/// <summary>
/// The nickserv account this user is logged into, if applicable.
/// </summary>
public string LoggedInAs { get; set; }
}
}