2023-02-16 20:34:59 +00:00
|
|
|
|
using SharpChat.Packet;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace SharpChat.Commands {
|
2024-05-14 22:17:25 +00:00
|
|
|
|
public class ChannelRankCommand : IChatCommand {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
public bool IsMatch(ChatCommandContext ctx) {
|
|
|
|
|
return ctx.NameEquals("rank")
|
|
|
|
|
|| ctx.NameEquals("privilege")
|
|
|
|
|
|| ctx.NameEquals("priv");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispatch(ChatCommandContext ctx) {
|
2024-05-17 23:50:22 +00:00
|
|
|
|
if(!ctx.User.Permissions.HasFlag(ChatUserPermissions.SetChannelHierarchy) || !ctx.Channel.IsOwner(ctx.User)) {
|
2024-05-14 19:11:09 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new CommandNotAllowedErrorPacket(ctx.Name));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
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());
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-10 18:29:48 +00:00
|
|
|
|
ctx.Chat.UpdateChannel(ctx.Channel, minRank: chanHierarchy);
|
2024-05-14 22:17:25 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new ChannelRankChangedResponsePacket());
|
2023-02-16 20:34:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|