27 lines
1 KiB
C#
27 lines
1 KiB
C#
using SharpChat.Packet;
|
|
using System.Linq;
|
|
|
|
namespace SharpChat.Commands {
|
|
public class ChannelRankCommand : 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.IsOwner(ctx.User)) {
|
|
ctx.Chat.SendTo(ctx.User, new CommandNotAllowedErrorPacket(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 ChannelRankTooHighErrorPacket());
|
|
return;
|
|
}
|
|
|
|
ctx.Chat.UpdateChannel(ctx.Channel, minRank: chanHierarchy);
|
|
ctx.Chat.SendTo(ctx.User, new ChannelRankChangedResponsePacket());
|
|
}
|
|
}
|
|
}
|