27 lines
1 KiB
C#
27 lines
1 KiB
C#
using SharpChat.Packet;
|
|
using System.Linq;
|
|
|
|
namespace SharpChat.Commands {
|
|
public class ChannelRankCommand : IUserCommand {
|
|
public bool IsMatch(UserCommandContext ctx) {
|
|
return ctx.NameEquals("rank")
|
|
|| ctx.NameEquals("privilege")
|
|
|| ctx.NameEquals("priv");
|
|
}
|
|
|
|
public void Dispatch(UserCommandContext ctx) {
|
|
if(!ctx.User.Permissions.HasFlag(UserPermissions.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());
|
|
}
|
|
}
|
|
}
|