2024-05-20 23:00:47 +00:00
|
|
|
|
using SharpChat.PacketsS2C;
|
2023-02-16 20:34:59 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace SharpChat.Commands {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
public class ChannelDeleteCommand : ISockChatClientCommand {
|
|
|
|
|
public bool IsMatch(SockChatClientCommandContext ctx) {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return ctx.NameEquals("delchan") || (
|
|
|
|
|
ctx.NameEquals("delete")
|
|
|
|
|
&& ctx.Args.FirstOrDefault()?.All(char.IsDigit) == false
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 23:00:47 +00:00
|
|
|
|
public void Dispatch(SockChatClientCommandContext ctx) {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
if(!ctx.Args.Any() || string.IsNullOrWhiteSpace(ctx.Args.FirstOrDefault())) {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new CommandFormatErrorS2CPacket());
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string delChanName = string.Join('_', ctx.Args);
|
2024-05-19 21:02:17 +00:00
|
|
|
|
ChannelInfo? delChan = ctx.Chat.Channels.Get(delChanName, SockChatUtility.SanitiseChannelName);
|
2023-02-16 20:34:59 +00:00
|
|
|
|
|
|
|
|
|
if(delChan == null) {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new ChannelNotFoundErrorS2CPacket(delChanName));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-19 02:17:51 +00:00
|
|
|
|
if(!ctx.User.Permissions.HasFlag(UserPermissions.DeleteChannel) || !delChan.IsOwner(ctx.User)) {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new ChannelDeleteNotAllowedErrorS2CPacket(delChan.Name));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-19 22:27:08 +00:00
|
|
|
|
ctx.Chat.RemoveChannel(delChan);
|
2024-05-20 23:00:47 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new ChannelDeleteResponseS2CPacket(delChan.Name));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|