cf3209e1d0
Quick fix for PowerShell IE use Makes date readable for target player Resolved translation string inconsistencies Minor code cleanups Initial commit from review Cleaned up code & amended a few checks Comment typo Fix infinite unmuting Removed unnecessary checks (Unmuting an already unmuted player will not trigger MuteStateMeta creation (if already doesn't exist)) Resolved !listmutes showing expired mutes Committing before refactor Refactor from review Removed reference to AdditionalProperty Fix check for meta state when unmuting Continued request solves main problem Handle potential failed command execution Missed CommandExecuted onJoin Fix another PS Reference to Invoke-WebRequest Fixes review issues & Cleaned up code Adds support for Intercepting Commands via Plugin (Credit: @RaidMax) Comparing Revert formatting changes Removing MuteList for Penalty Added Mute, TempMute & Unmute Penalty Fixed reference in Mute.csproj & Removed ListMutesCommand.cs
68 lines
2.3 KiB
C#
68 lines
2.3 KiB
C#
using System.Text.RegularExpressions;
|
|
using Data.Models.Client;
|
|
using SharedLibraryCore;
|
|
using SharedLibraryCore.Commands;
|
|
using SharedLibraryCore.Configuration;
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
namespace Mute.Commands;
|
|
|
|
public class TempMuteCommand : Command
|
|
{
|
|
private const string TempBanRegex = @"([0-9]+\w+)\ (.+)";
|
|
|
|
public TempMuteCommand(CommandConfiguration config, ITranslationLookup translationLookup) : base(config,
|
|
translationLookup)
|
|
{
|
|
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)
|
|
{
|
|
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();
|
|
|
|
if (await Plugin.MuteManager.Mute(gameEvent.Owner, gameEvent.Origin, gameEvent.Target, expiration, reason))
|
|
{
|
|
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"]);
|
|
}
|
|
}
|