sharp-chat/SharpChat/Commands/ChannelDeleteCommand.cs

37 lines
1.3 KiB
C#
Raw Normal View History

using SharpChat.Packet;
using System.Linq;
namespace SharpChat.Commands {
public class ChannelDeleteCommand : IUserCommand {
public bool IsMatch(UserCommandContext ctx) {
return ctx.NameEquals("delchan") || (
ctx.NameEquals("delete")
&& ctx.Args.FirstOrDefault()?.All(char.IsDigit) == false
);
}
public void Dispatch(UserCommandContext ctx) {
if(!ctx.Args.Any() || string.IsNullOrWhiteSpace(ctx.Args.FirstOrDefault())) {
ctx.Chat.SendTo(ctx.User, new CommandFormatErrorPacket());
return;
}
string delChanName = string.Join('_', ctx.Args);
2024-05-19 21:02:17 +00:00
ChannelInfo? delChan = ctx.Chat.Channels.Get(delChanName, SockChatUtility.SanitiseChannelName);
if(delChan == null) {
2024-05-14 22:17:25 +00:00
ctx.Chat.SendTo(ctx.User, new ChannelNotFoundErrorPacket(delChanName));
return;
}
if(!ctx.User.Permissions.HasFlag(UserPermissions.DeleteChannel) || !delChan.IsOwner(ctx.User)) {
2024-05-14 22:17:25 +00:00
ctx.Chat.SendTo(ctx.User, new ChannelDeleteNotAllowedErrorPacket(delChan.Name));
return;
}
2023-02-19 22:27:08 +00:00
ctx.Chat.RemoveChannel(delChan);
2024-05-14 22:17:25 +00:00
ctx.Chat.SendTo(ctx.User, new ChannelDeleteResponsePacket(delChan.Name));
}
}
}