sharp-chat/SharpChat/Commands/ChannelRankCommand.cs

28 lines
1 KiB
C#
Raw Normal View History

using SharpChat.Packet;
using System.Linq;
namespace SharpChat.Commands {
2024-05-14 22:17:25 +00:00
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.Permissions.HasFlag(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) {
2024-05-14 22:17:25 +00:00
ctx.Chat.SendTo(ctx.User, new ChannelRankTooHighErrorPacket());
return;
}
ctx.Chat.UpdateChannel(ctx.Channel, minRank: chanHierarchy);
2024-05-14 22:17:25 +00:00
ctx.Chat.SendTo(ctx.User, new ChannelRankChangedResponsePacket());
}
}
}