28 lines
1.1 KiB
C#
28 lines
1.1 KiB
C#
using SharpChat.Packet;
|
|
using System.Linq;
|
|
|
|
namespace SharpChat.Commands {
|
|
public class RankChannelCommand : IChatCommand {
|
|
public bool IsMatch(ChatCommandContext ctx) {
|
|
return ctx.NameEquals("rank")
|
|
|| ctx.NameEquals("privilege")
|
|
|| ctx.NameEquals("priv");
|
|
}
|
|
|
|
public void Dispatch(ChatCommandContext ctx) {
|
|
if(!ctx.User.Can(ChatUserPermissions.SetChannelHierarchy) || ctx.Channel.Owner != ctx.User) {
|
|
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
|
return;
|
|
}
|
|
|
|
if(!ctx.Args.Any() || !int.TryParse(ctx.Args.First(), out int chanHierarchy) || chanHierarchy > ctx.User.Rank) {
|
|
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(LCR.INSUFFICIENT_HIERARCHY));
|
|
return;
|
|
}
|
|
|
|
lock(ctx.Chat.ChannelsAccess)
|
|
ctx.Chat.UpdateChannel(ctx.Channel, hierarchy: chanHierarchy);
|
|
ctx.Chat.SendTo(ctx.User, new LegacyCommandResponse(LCR.CHANNEL_HIERARCHY_CHANGED, false));
|
|
}
|
|
}
|
|
}
|