23 lines
801 B
C#
23 lines
801 B
C#
using SharpChat.Packet;
|
|
using System.Linq;
|
|
|
|
namespace SharpChat.Commands {
|
|
public class ChannelJoinCommand : IUserCommand {
|
|
public bool IsMatch(UserCommandContext ctx) {
|
|
return ctx.NameEquals("join");
|
|
}
|
|
|
|
public void Dispatch(UserCommandContext ctx) {
|
|
string joinChanStr = ctx.Args.FirstOrDefault() ?? string.Empty;
|
|
ChannelInfo? joinChan = ctx.Chat.Channels.Get(joinChanStr, SockChatUtility.SanitiseChannelName);
|
|
|
|
if(joinChan == null) {
|
|
ctx.Chat.SendTo(ctx.User, new ChannelNotFoundErrorPacket(joinChanStr));
|
|
ctx.Chat.ForceChannel(ctx.User);
|
|
return;
|
|
}
|
|
|
|
ctx.Chat.SwitchChannel(ctx.User, joinChan, string.Join(' ', ctx.Args.Skip(1)));
|
|
}
|
|
}
|
|
}
|