sharp-chat/SharpChat/Commands/ChannelJoinCommand.cs

24 lines
801 B
C#
Raw Normal View History

using SharpChat.Packet;
using System.Linq;
namespace SharpChat.Commands {
2024-05-14 22:17:25 +00:00
public class ChannelJoinCommand : IChatCommand {
public bool IsMatch(ChatCommandContext ctx) {
return ctx.NameEquals("join");
}
public void Dispatch(ChatCommandContext ctx) {
2024-05-14 22:17:25 +00:00
string joinChanStr = ctx.Args.FirstOrDefault() ?? string.Empty;
ChatChannel? joinChan = ctx.Chat.Channels.Values.FirstOrDefault(c => c.NameEquals(joinChanStr));
if(joinChan == null) {
2024-05-14 22:17:25 +00:00
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)));
}
}
}