sharp-chat/SharpChat/Commands/SilenceRevokeCommand.cs

42 lines
1.5 KiB
C#
Raw Normal View History

using SharpChat.Packet;
using System;
using System.Linq;
namespace SharpChat.Commands {
public class SilenceRevokeCommand : IChatCommand {
public bool IsMatch(ChatCommandContext ctx) {
return ctx.NameEquals("unsilence");
}
public void Dispatch(ChatCommandContext ctx) {
if(!ctx.User.Can(ChatUserPermissions.SilenceUser)) {
ctx.User.Send(new LegacyCommandResponse(LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
return;
}
string unsilUserStr = ctx.Args.FirstOrDefault();
ChatUser unsilUser;
lock(ctx.Chat.UsersAccess)
if(string.IsNullOrWhiteSpace(unsilUserStr) || (unsilUser = ctx.Chat.Users.FirstOrDefault(u => u.NameEquals(unsilUserStr))) == null) {
ctx.User.Send(new LegacyCommandResponse(LCR.USER_NOT_FOUND, true, unsilUserStr ?? "User"));
return;
}
if(unsilUser.Rank >= ctx.User.Rank) {
ctx.User.Send(new LegacyCommandResponse(LCR.UNSILENCE_HIERARCHY));
return;
}
if(!unsilUser.IsSilenced) {
ctx.User.Send(new LegacyCommandResponse(LCR.NOT_SILENCED));
return;
}
unsilUser.SilencedUntil = DateTimeOffset.MinValue;
unsilUser.Send(new LegacyCommandResponse(LCR.UNSILENCED, false));
ctx.User.Send(new LegacyCommandResponse(LCR.TARGET_UNSILENCED, false, unsilUser.DisplayName));
}
}
}