IW4M-Admin/Plugins/Mute/Commands/MuteInfoCommand.cs
Amos cf51b83cdd Fix Threading Duplicate for Mute Penalty & Added !MuteInfo & Fix PM (#269)
* Resolve duplicate migration
Resolve unmuting state double penalties

* Change order of operation

* Added MuteInfoCommand.cs

* Resolve !pm and @broadcast permanently being disabled
2022-10-14 08:47:01 -05:00

51 lines
1.9 KiB
C#

using Data.Models.Client;
using Humanizer;
using SharedLibraryCore;
using SharedLibraryCore.Commands;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces;
namespace Mute.Commands;
public class MuteInfoCommand : Command
{
public MuteInfoCommand(CommandConfiguration config, ITranslationLookup translationLookup) : base(config,
translationLookup)
{
Name = "muteinfo";
Description = translationLookup["PLUGINS_MUTE_COMMANDS_MUTEINFO_DESC"];
Alias = "mi";
Permission = EFClient.Permission.Moderator;
RequiresTarget = true;
SupportedGames = Plugin.SupportedGames;
Arguments = new[]
{
new CommandArgument
{
Name = translationLookup["COMMANDS_ARGS_PLAYER"],
Required = true
}
};
}
public override async Task ExecuteAsync(GameEvent gameEvent)
{
var currentMuteMeta = await Plugin.MuteManager.GetCurrentMuteState(gameEvent.Target);
switch (currentMuteMeta.MuteState)
{
case MuteState.Muted when currentMuteMeta.Expiration is null:
gameEvent.Origin.Tell(_translationLookup["PLUGINS_MUTE_COMMANDS_MUTEINFO_SUCCESS"]
.FormatExt(gameEvent.Target.Name, currentMuteMeta.Reason));
return;
case MuteState.Muted when currentMuteMeta.Expiration.HasValue && currentMuteMeta.Expiration.Value > DateTime.UtcNow:
var remainingTime = (currentMuteMeta.Expiration.Value - DateTime.UtcNow).HumanizeForCurrentCulture();
gameEvent.Origin.Tell(_translationLookup["PLUGINS_MUTE_COMMANDS_MUTEINFO_TM_SUCCESS"]
.FormatExt(gameEvent.Target.Name, currentMuteMeta.Reason, remainingTime));
return;
default:
gameEvent.Origin.Tell(_translationLookup["PLUGINS_MUTE_COMMANDS_MUTEINFO_NONE"]);
break;
}
}
}