2022-10-05 16:29:31 -04:00
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using Data.Models.Client;
|
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Commands;
|
|
|
|
|
using SharedLibraryCore.Configuration;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
|
2023-02-11 21:48:31 -05:00
|
|
|
|
namespace IW4MAdmin.Plugins.Mute.Commands;
|
2022-10-05 16:29:31 -04:00
|
|
|
|
|
|
|
|
|
public class TempMuteCommand : Command
|
|
|
|
|
{
|
2023-02-11 21:48:31 -05:00
|
|
|
|
private readonly MuteManager _muteManager;
|
2022-10-05 16:29:31 -04:00
|
|
|
|
private const string TempBanRegex = @"([0-9]+\w+)\ (.+)";
|
|
|
|
|
|
2023-02-11 21:48:31 -05:00
|
|
|
|
public TempMuteCommand(CommandConfiguration config, ITranslationLookup translationLookup, MuteManager muteManager) : base(config,
|
2022-10-05 16:29:31 -04:00
|
|
|
|
translationLookup)
|
|
|
|
|
{
|
2023-02-11 21:48:31 -05:00
|
|
|
|
_muteManager = muteManager;
|
2022-10-05 16:29:31 -04:00
|
|
|
|
Name = "tempmute";
|
|
|
|
|
Description = translationLookup["PLUGINS_MUTE_COMMANDS_TEMPMUTE_DESC"];
|
|
|
|
|
Alias = "tm";
|
|
|
|
|
Permission = EFClient.Permission.Moderator;
|
|
|
|
|
RequiresTarget = true;
|
|
|
|
|
SupportedGames = Plugin.SupportedGames;
|
|
|
|
|
Arguments = new[]
|
|
|
|
|
{
|
|
|
|
|
new CommandArgument
|
|
|
|
|
{
|
|
|
|
|
Name = translationLookup["COMMANDS_ARGS_PLAYER"],
|
|
|
|
|
Required = true
|
|
|
|
|
},
|
|
|
|
|
new CommandArgument
|
|
|
|
|
{
|
|
|
|
|
Name = translationLookup["COMMANDS_ARGS_DURATION"],
|
|
|
|
|
Required = true
|
|
|
|
|
},
|
|
|
|
|
new CommandArgument
|
|
|
|
|
{
|
|
|
|
|
Name = translationLookup["COMMANDS_ARGS_REASON"],
|
|
|
|
|
Required = true
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override async Task ExecuteAsync(GameEvent gameEvent)
|
|
|
|
|
{
|
2022-10-24 19:58:12 -04:00
|
|
|
|
if (gameEvent.Origin.ClientId == gameEvent.Target.ClientId)
|
|
|
|
|
{
|
|
|
|
|
gameEvent.Origin.Tell(_translationLookup["COMMANDS_DENY_SELF_TARGET"]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-05 16:29:31 -04:00
|
|
|
|
var match = Regex.Match(gameEvent.Data, TempBanRegex);
|
|
|
|
|
if (match.Success)
|
|
|
|
|
{
|
|
|
|
|
var expiration = DateTime.UtcNow + match.Groups[1].ToString().ParseTimespan();
|
|
|
|
|
var reason = match.Groups[2].ToString();
|
|
|
|
|
|
2023-02-11 21:48:31 -05:00
|
|
|
|
if (await _muteManager.Mute(gameEvent.Owner, gameEvent.Origin, gameEvent.Target, expiration, reason))
|
2022-10-05 16:29:31 -04:00
|
|
|
|
{
|
|
|
|
|
gameEvent.Origin.Tell(_translationLookup["PLUGINS_MUTE_COMMANDS_TEMPMUTE_TEMPMUTED"]
|
|
|
|
|
.FormatExt(gameEvent.Target.CleanedName));
|
|
|
|
|
gameEvent.Target.Tell(_translationLookup["PLUGINS_MUTE_COMMANDS_TEMPMUTE_TARGET_TEMPMUTED"]
|
|
|
|
|
.FormatExt(expiration.HumanizeForCurrentCulture(), reason));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gameEvent.Origin.Tell(_translationLookup["PLUGINS_MUTE_COMMANDS_MUTE_NOT_UNMUTED"]
|
|
|
|
|
.FormatExt(gameEvent.Target.CleanedName));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gameEvent.Origin.Tell(_translationLookup["PLUGINS_MUTE_COMMANDS_TEMPMUTE_BAD_FORMAT"]);
|
|
|
|
|
}
|
|
|
|
|
}
|