chatsharp/ChatSharp/IrcClient.Commands.cs

120 lines
4.0 KiB
C#
Raw Normal View History

2013-04-10 05:53:54 +00:00
using ChatSharp.Handlers;
using System;
2013-04-09 23:24:50 +00:00
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ChatSharp
{
public partial class IrcClient
{
public void Nick(string newNick)
{
SendRawMessage("NICK {0}", newNick);
User.Nick = newNick;
}
2013-04-09 23:31:06 +00:00
public void SendMessage(string message, params string[] destinations)
{
const string illegalCharacters = "\r\n\0";
2013-04-09 23:31:06 +00:00
if (!destinations.Any()) throw new InvalidOperationException("Message must have at least one target.");
if (illegalCharacters.Any(message.Contains)) throw new ArgumentException("Illegal characters are present in message.", "message");
2013-04-09 23:31:06 +00:00
string to = string.Join(",", destinations);
SendRawMessage("PRIVMSG {0} :{1}", to, message);
}
public void PartChannel(string channel)
{
if (!Channels.Contains(channel))
throw new InvalidOperationException("Client is not present in channel.");
SendRawMessage("PART {0}", channel);
Channels.Remove(Channels[channel]);
}
public void PartChannel(string channel, string reason)
{
if (!Channels.Contains(channel))
throw new InvalidOperationException("Client is not present in channel.");
SendRawMessage("PART {0} :{1}", channel, reason);
Channels.Remove(Channels[channel]);
}
2013-04-10 17:26:20 +00:00
public void JoinChannel(string channel)
{
2013-04-10 17:26:20 +00:00
if (Channels.Contains(channel))
throw new InvalidOperationException("Client is not already present in channel.");
2013-04-10 17:26:20 +00:00
SendRawMessage("JOIN {0}", channel);
}
2013-04-10 17:26:20 +00:00
public void SetTopic(string channel, string topic)
{
2013-04-10 17:26:20 +00:00
if (!Channels.Contains(channel))
throw new InvalidOperationException("Client is not present in channel.");
2013-04-10 17:26:20 +00:00
SendRawMessage("TOPIC {0} :{1}", channel, topic);
}
2013-04-10 05:53:54 +00:00
2013-06-01 22:38:57 +00:00
public void KickUser(string channel, string user)
{
SendRawMessage("KICK {0} {1} :{1}", channel, user);
}
public void KickUser(string channel, string user, string reason)
{
SendRawMessage("KICK {0} {1} :{2}", channel, user, reason);
}
public void InviteUser(string channel, string user)
{
SendRawMessage("INVITE {1} {0}", channel, user);
}
2013-04-11 01:54:49 +00:00
public void WhoIs(string nick)
{
WhoIs(nick, null);
}
2013-04-10 05:53:54 +00:00
public void WhoIs(string nick, Action<WhoIs> callback)
{
var whois = new WhoIs();
RequestManager.QueueOperation("WHOIS " + nick, new RequestOperation(whois, ro =>
{
if (callback != null)
callback((WhoIs)ro.State);
}));
2013-04-10 05:53:54 +00:00
SendRawMessage("WHOIS {0}", nick);
}
2013-04-10 17:26:20 +00:00
2013-04-11 01:54:49 +00:00
public void GetMode(string channel)
{
GetMode(channel, null);
}
2013-04-10 17:26:20 +00:00
public void GetMode(string channel, Action<IrcChannel> callback)
{
RequestManager.QueueOperation("MODE " + channel, new RequestOperation(channel, ro =>
{
var c = Channels[(string)ro.State];
if (callback != null)
callback(c);
}));
2013-04-10 17:26:20 +00:00
SendRawMessage("MODE {0}", channel);
}
2013-05-20 01:58:02 +00:00
public void ChangeMode(string channel, string change)
{
SendRawMessage("MODE {0} {1}", channel, change);
}
2013-06-02 21:11:48 +00:00
public void GetModeList(string channel, char mode, Action<MaskCollection> callback)
{
RequestManager.QueueOperation("GETMODE " + mode + " " + channel, new RequestOperation(new MaskCollection(), ro =>
{
var c = (MaskCollection)ro.State;
if (callback != null)
callback(c);
}));
SendRawMessage("MODE {0} {1}", channel, mode);
}
2013-04-09 23:24:50 +00:00
}
}