From c4defacabc17806eeec5c07cdbb0b90ab72197f1 Mon Sep 17 00:00:00 2001 From: Ayymoss Date: Tue, 16 Jul 2024 23:57:45 +0100 Subject: [PATCH] Refactor the ProfanityDetermentConfiguration class into ProfanityDetermentSettings The class ProfanityDetermentConfiguration has been renamed to ProfanityDetermentSettings to better reflect its purpose. The unnecessary namespace declaration has been removed, along with the generation method that has been replaced with direct property initializations. Modifications have also been made to reflect these changes in the Plugin class. --- Plugins/ProfanityDeterment/Plugin.cs | 6 +-- .../ProfanityDetermentConfiguration.cs | 51 ------------------- .../ProfanityDetermentSettings.cs | 40 +++++++++++++++ 3 files changed, 43 insertions(+), 54 deletions(-) delete mode 100644 Plugins/ProfanityDeterment/ProfanityDetermentConfiguration.cs create mode 100644 Plugins/ProfanityDeterment/ProfanityDetermentSettings.cs diff --git a/Plugins/ProfanityDeterment/Plugin.cs b/Plugins/ProfanityDeterment/Plugin.cs index a7a3abac..6941087c 100644 --- a/Plugins/ProfanityDeterment/Plugin.cs +++ b/Plugins/ProfanityDeterment/Plugin.cs @@ -22,9 +22,9 @@ public class Plugin : IPluginV2 private const string ProfanityKey = "_profanityInfringements"; - private readonly ProfanityDetermentConfiguration _configuration; + private readonly ProfanityDetermentSettings _configuration; - public Plugin(ProfanityDetermentConfiguration configuration) + public Plugin(ProfanityDetermentSettings configuration) { _configuration = configuration; @@ -44,7 +44,7 @@ public class Plugin : IPluginV2 public static void RegisterDependencies(IServiceCollection serviceProvider) { - serviceProvider.AddConfiguration("ProfanityDetermentSettings"); + serviceProvider.AddConfiguration("ProfanityDetermentSettings", new ProfanityDetermentSettings()); } private Task GameEventSubscriptionsOnClientMessaged(ClientMessageEvent clientEvent, CancellationToken token) diff --git a/Plugins/ProfanityDeterment/ProfanityDetermentConfiguration.cs b/Plugins/ProfanityDeterment/ProfanityDetermentConfiguration.cs deleted file mode 100644 index d66e8a57..00000000 --- a/Plugins/ProfanityDeterment/ProfanityDetermentConfiguration.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System.Collections.Generic; -using SharedLibraryCore; -using SharedLibraryCore.Interfaces; - -namespace IW4MAdmin.Plugins.ProfanityDeterment -{ - public class ProfanityDetermentConfiguration : IBaseConfiguration - { - public List OffensiveWords { get; set; } = []; - public bool EnableProfanityDeterment { get; set; } - public required string ProfanityWarningMessage { get; set; } - public required string ProfanityKickMessage { get; set; } - public int KickAfterInfringementCount { get; set; } - public bool KickOnInfringingName { get; set; } = true; - - public IBaseConfiguration Generate() - { - OffensiveWords = new List() - { - @"(ph|f)[a@]g[s\$]?", - @"(ph|f)[a@]gg[i1]ng", - @"(ph|f)[a@]gg?[o0][t\+][s\$]?", - @"(ph|f)[a@]gg[s\$]", - @"(ph|f)[e3][l1][l1]?[a@][t\+][i1][o0]", - @"(ph|f)u(c|k|ck|q)", - @"(ph|f)u(c|k|ck|q)[s\$]?", - @"(c|k|ck|q)un[t\+][l1][i1](c|k|ck|q)", - @"(c|k|ck|q)un[t\+][l1][i1](c|k|ck|q)[e3]r", - @"(c|k|ck|q)un[t\+][l1][i1](c|k|ck|q)[i1]ng", - @"b[i1][t\+]ch[s\$]?", - @"b[i1][t\+]ch[e3]r[s\$]?", - @"b[i1][t\+]ch[e3][s\$]", - @"b[i1][t\+]ch[i1]ng?", - @"n[i1]gg?[e3]r[s\$]?", - @"[s\$]h[i1][t\+][s\$]?", - @"[s\$][l1]u[t\+][s\$]?" - }; - - var loc = Utilities.CurrentLocalization.LocalizationIndex; - - EnableProfanityDeterment = Utilities.PromptBool(loc["PLUGINS_PROFANITY_SETUP_ENABLE"]); - ProfanityWarningMessage = loc["PLUGINS_PROFANITY_WARNMSG"]; - ProfanityKickMessage = loc["PLUGINS_PROFANITY_KICKMSG"]; - KickAfterInfringementCount = 2; - - return this; - } - - public string Name() => "ProfanityDetermentSettings"; - } -} diff --git a/Plugins/ProfanityDeterment/ProfanityDetermentSettings.cs b/Plugins/ProfanityDeterment/ProfanityDetermentSettings.cs new file mode 100644 index 00000000..03fe0aa3 --- /dev/null +++ b/Plugins/ProfanityDeterment/ProfanityDetermentSettings.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using SharedLibraryCore; + +namespace IW4MAdmin.Plugins.ProfanityDeterment; + +public class ProfanityDetermentSettings +{ + public List OffensiveWords { get; set; } = + [ + @"(ph|f)[a@]g[s\$]?", + @"(ph|f)[a@]gg[i1]ng", + @"(ph|f)[a@]gg?[o0][t\+][s\$]?", + @"(ph|f)[a@]gg[s\$]", + @"(ph|f)[e3][l1][l1]?[a@][t\+][i1][o0]", + @"(ph|f)u(c|k|ck|q)", + @"(ph|f)u(c|k|ck|q)[s\$]?", + @"(c|k|ck|q)un[t\+][l1][i1](c|k|ck|q)", + @"(c|k|ck|q)un[t\+][l1][i1](c|k|ck|q)[e3]r", + @"(c|k|ck|q)un[t\+][l1][i1](c|k|ck|q)[i1]ng", + @"b[i1][t\+]ch[s\$]?", + @"b[i1][t\+]ch[e3]r[s\$]?", + @"b[i1][t\+]ch[e3][s\$]", + @"b[i1][t\+]ch[i1]ng?", + @"n[i1]gg?[e3]r[s\$]?", + @"[s\$]h[i1][t\+][s\$]?", + @"[s\$][l1]u[t\+][s\$]?" + ]; + + public bool EnableProfanityDeterment { get; set; } = + Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_PROFANITY_SETUP_ENABLE"].PromptBool(); + + public string ProfanityWarningMessage { get; set; } = + Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_PROFANITY_WARNMSG"]; + + public string ProfanityKickMessage { get; set; } = + Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_PROFANITY_KICKMSG"]; + + public int KickAfterInfringementCount { get; set; } = 2; + public bool KickOnInfringingName { get; set; } = true; +}