2024-05-20 23:40:34 +00:00
|
|
|
|
using SharpChat.SockChat.PacketsS2C;
|
2023-02-16 20:34:59 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2024-05-20 23:40:34 +00:00
|
|
|
|
namespace SharpChat.SockChat.Commands {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
public class ChannelJoinCommand : ISockChatClientCommand {
|
|
|
|
|
public bool IsMatch(SockChatClientCommandContext ctx) {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return ctx.NameEquals("join");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 23:00:47 +00:00
|
|
|
|
public void Dispatch(SockChatClientCommandContext ctx) {
|
2024-05-14 22:17:25 +00:00
|
|
|
|
string joinChanStr = ctx.Args.FirstOrDefault() ?? string.Empty;
|
2024-05-19 21:02:17 +00:00
|
|
|
|
ChannelInfo? joinChan = ctx.Chat.Channels.Get(joinChanStr, SockChatUtility.SanitiseChannelName);
|
2023-02-16 20:34:59 +00:00
|
|
|
|
|
|
|
|
|
if(joinChan == null) {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new ChannelNotFoundErrorS2CPacket(joinChanStr));
|
2023-02-16 22:33:48 +00:00
|
|
|
|
ctx.Chat.ForceChannel(ctx.User);
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.Chat.SwitchChannel(ctx.User, joinChan, string.Join(' ', ctx.Args.Skip(1)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|