25 lines
869 B
C#
25 lines
869 B
C#
using SharpChat.Packet;
|
|
using System.Linq;
|
|
|
|
namespace SharpChat.Commands {
|
|
public class JoinChannelCommand : IChatCommand {
|
|
public bool IsMatch(ChatCommandContext ctx) {
|
|
return ctx.NameEquals("join");
|
|
}
|
|
|
|
public void Dispatch(ChatCommandContext ctx) {
|
|
string joinChanStr = ctx.Args.FirstOrDefault();
|
|
ChatChannel joinChan;
|
|
lock(ctx.Chat.ChannelsAccess)
|
|
joinChan = ctx.Chat.Channels.FirstOrDefault(c => c.NameEquals(joinChanStr));
|
|
|
|
if(joinChan == null) {
|
|
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(LCR.CHANNEL_NOT_FOUND, true, joinChanStr));
|
|
ctx.Chat.ForceChannel(ctx.User);
|
|
return;
|
|
}
|
|
|
|
ctx.Chat.SwitchChannel(ctx.User, joinChan, string.Join(' ', ctx.Args.Skip(1)));
|
|
}
|
|
}
|
|
}
|