1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 15:20:48 -05:00

Refactor MuteManager constructor and clean up code (#329)

The MuteManager constructor within the Mute plugin has been refactored for better dependency injection. This change simplifies the class construction by directly initializing fields in the constructor parameters. Additionally, several minor code improvements have been made, including spelling corrections and replacing some conditional checks for readability. Other arrays or methods in the plugin are also revised for better maintainability and readability of the code.
This commit is contained in:
Amos
2024-06-30 03:50:00 +01:00
committed by GitHub
parent 40f912542b
commit ba633be034
7 changed files with 89 additions and 71 deletions

View File

@ -20,8 +20,8 @@ public class MuteCommand : Command
Permission = EFClient.Permission.Moderator;
RequiresTarget = true;
SupportedGames = Plugin.SupportedGames;
Arguments = new[]
{
Arguments =
[
new CommandArgument
{
Name = translationLookup["COMMANDS_ARGS_PLAYER"],
@ -32,7 +32,7 @@ public class MuteCommand : Command
Name = translationLookup["COMMANDS_ARGS_REASON"],
Required = true
}
};
];
}
public override async Task ExecuteAsync(GameEvent gameEvent)

View File

@ -21,14 +21,14 @@ public class MuteInfoCommand : Command
Permission = EFClient.Permission.Moderator;
RequiresTarget = true;
SupportedGames = Plugin.SupportedGames;
Arguments = new[]
{
Arguments =
[
new CommandArgument
{
Name = translationLookup["COMMANDS_ARGS_PLAYER"],
Required = true
}
};
];
}
public override async Task ExecuteAsync(GameEvent gameEvent)

View File

@ -7,10 +7,9 @@ using SharedLibraryCore.Interfaces;
namespace IW4MAdmin.Plugins.Mute.Commands;
public class TempMuteCommand : Command
public partial class TempMuteCommand : Command
{
private readonly MuteManager _muteManager;
private const string TempBanRegex = @"([0-9]+\w+)\ (.+)";
public TempMuteCommand(CommandConfiguration config, ITranslationLookup translationLookup, MuteManager muteManager) : base(config,
translationLookup)
@ -22,8 +21,8 @@ public class TempMuteCommand : Command
Permission = EFClient.Permission.Moderator;
RequiresTarget = true;
SupportedGames = Plugin.SupportedGames;
Arguments = new[]
{
Arguments =
[
new CommandArgument
{
Name = translationLookup["COMMANDS_ARGS_PLAYER"],
@ -39,7 +38,7 @@ public class TempMuteCommand : Command
Name = translationLookup["COMMANDS_ARGS_REASON"],
Required = true
}
};
];
}
public override async Task ExecuteAsync(GameEvent gameEvent)
@ -49,8 +48,8 @@ public class TempMuteCommand : Command
gameEvent.Origin.Tell(_translationLookup["COMMANDS_DENY_SELF_TARGET"]);
return;
}
var match = Regex.Match(gameEvent.Data, TempBanRegex);
var match = TempBanRegex().Match(gameEvent.Data);
if (match.Success)
{
var expiration = DateTime.UtcNow + match.Groups[1].ToString().ParseTimespan();
@ -72,4 +71,7 @@ public class TempMuteCommand : Command
gameEvent.Origin.Tell(_translationLookup["PLUGINS_MUTE_COMMANDS_TEMPMUTE_BAD_FORMAT"]);
}
[GeneratedRegex(@"([0-9]+\w+)\ (.+)")]
private static partial Regex TempBanRegex();
}

View File

@ -20,8 +20,8 @@ public class UnmuteCommand : Command
Permission = EFClient.Permission.Moderator;
RequiresTarget = true;
SupportedGames = Plugin.SupportedGames;
Arguments = new[]
{
Arguments =
[
new CommandArgument
{
Name = translationLookup["COMMANDS_ARGS_PLAYER"],
@ -32,7 +32,7 @@ public class UnmuteCommand : Command
Name = translationLookup["COMMANDS_ARGS_REASON"],
Required = true
}
};
];
}
public override async Task ExecuteAsync(GameEvent gameEvent)