2025-04-26 22:47:57 +00:00
|
|
|
using SharpChat.SockChat.S2CPackets;
|
2023-02-16 21:34:59 +01:00
|
|
|
|
2025-04-26 23:15:54 +00:00
|
|
|
namespace SharpChat.ClientCommands;
|
2023-02-16 21:34:59 +01:00
|
|
|
|
2025-04-26 23:15:54 +00:00
|
|
|
public class RankChannelClientCommand : ClientCommand {
|
|
|
|
public bool IsMatch(ClientCommandContext ctx) {
|
|
|
|
return ctx.NameEquals("rank")
|
|
|
|
|| ctx.NameEquals("privilege")
|
|
|
|
|| ctx.NameEquals("priv");
|
|
|
|
}
|
2025-04-25 20:05:55 +00:00
|
|
|
|
2025-04-26 23:15:54 +00:00
|
|
|
public async Task Dispatch(ClientCommandContext ctx) {
|
|
|
|
long msgId = ctx.Chat.RandomSnowflake.Next();
|
2023-02-16 21:34:59 +01:00
|
|
|
|
2025-04-26 23:15:54 +00:00
|
|
|
if(!ctx.User.Can(UserPermissions.SetChannelHierarchy) || ctx.Channel.IsOwner(ctx.User)) {
|
|
|
|
await ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
|
|
|
return;
|
|
|
|
}
|
2023-02-16 21:34:59 +01:00
|
|
|
|
2025-04-26 23:15:54 +00:00
|
|
|
if(ctx.Args.Length < 1 || !int.TryParse(ctx.Args.First(), out int chanHierarchy) || chanHierarchy > ctx.User.Rank) {
|
|
|
|
await ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.INSUFFICIENT_HIERARCHY));
|
|
|
|
return;
|
2023-02-16 21:34:59 +01:00
|
|
|
}
|
2025-04-26 23:15:54 +00:00
|
|
|
|
|
|
|
await ctx.Chat.UpdateChannel(ctx.Channel, hierarchy: chanHierarchy);
|
|
|
|
await ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.CHANNEL_HIERARCHY_CHANGED, false));
|
2023-02-16 21:34:59 +01:00
|
|
|
}
|
|
|
|
}
|