From 4434b3752c844d6744a7ddee8e958ee3bb31d179 Mon Sep 17 00:00:00 2001 From: GoodWheatley <109803540+GoodWheatley@users.noreply.github.com> Date: Sat, 1 Apr 2023 17:47:21 -0400 Subject: [PATCH] Chat Filter (April Fools) (#14999) --- .../Components/ChatFilterAccentComponent.cs | 9 ++ .../EntitySystems/ChatFilterAccentSystem.cs | 90 +++++++++++++++++++ Content.Shared/CCVar/CCVars.cs | 6 ++ .../Prototypes/Entities/Mobs/Species/base.yml | 1 + 4 files changed, 106 insertions(+) create mode 100644 Content.Server/Speech/Components/ChatFilterAccentComponent.cs create mode 100644 Content.Server/Speech/EntitySystems/ChatFilterAccentSystem.cs diff --git a/Content.Server/Speech/Components/ChatFilterAccentComponent.cs b/Content.Server/Speech/Components/ChatFilterAccentComponent.cs new file mode 100644 index 0000000000..e2f1a92f0c --- /dev/null +++ b/Content.Server/Speech/Components/ChatFilterAccentComponent.cs @@ -0,0 +1,9 @@ +namespace Content.Server.Speech.Components; + +// #####. ##### ### ###. #####? ### #####! + +[RegisterComponent] +public sealed class ChatFilterAccentComponent : Component +{ + +} diff --git a/Content.Server/Speech/EntitySystems/ChatFilterAccentSystem.cs b/Content.Server/Speech/EntitySystems/ChatFilterAccentSystem.cs new file mode 100644 index 0000000000..89b83e0e1f --- /dev/null +++ b/Content.Server/Speech/EntitySystems/ChatFilterAccentSystem.cs @@ -0,0 +1,90 @@ +using System.Text.RegularExpressions; +using Content.Server.Speech.Components; +using Content.Shared.CCVar; +using Robust.Shared.Configuration; + +namespace Content.Server.Speech.EntitySystems; + +public sealed class ChatFilterAccentSystem : EntitySystem +{ + [Dependency] private readonly IConfigurationManager _cfg = default!; + + private static readonly Dictionary DirectReplacements = new() + { + { "fuck", "####" }, + { "shit", "####" }, + { "ass", "###" }, + { "dick", "####" }, + { "bitch", "#####" }, + { "piss", "####" }, + { "damn", "####" }, + { "kill", "####" }, + { "hurt", "####" }, + { "god", "###" }, + { "hell", "####" }, + { "nuke", "####" }, + { "dang", "####" }, + { "lol", "###" }, + { "nukies", "#####" }, + { "nukie", "#####" }, + { "gun", "###" }, + { "ammo", "####" }, + { "bridge", "#####" }, + { "med", "###" }, + { "clown", "#####" }, + { "admin", "#####" }, + { "badmin", "######" }, + { "admeme", "######" }, + { "badmeme", "######" }, + { "centcom", "#######" }, + { "singulo", "#######" }, + { "singuloose", "##########" }, + { "sword", "#####" }, + { "dead", "####" }, + { "died", "####" }, + { "sus", "###" }, + { "aos", "###" }, + { "kos", "###" }, + { "anomaly", "#######" }, + { "shuttle", "#######" }, + { "hos", "###" }, + { "drunk", "#####" }, + { "bar", "###" }, + { "arrest", "#####" }, + { "bomb", "####" }, + { "I", "#" }, + { "traitor", "#######" }, + { "tator", "#####" }, + { "bad", "###" }, + }; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnAccentGet); + } + + public string Accentuate(string message) + { + var msg = message; + + if (_cfg.GetCVar(CCVars.GameChatFilter) == true) + { + + foreach (var (first, replace) in DirectReplacements) + { + msg = Regex.Replace(msg, $@"{first}", replace, RegexOptions.IgnoreCase); + } + + return msg; + } + + return msg; + } + + private void OnAccentGet(EntityUid uid, ChatFilterAccentComponent component, AccentGetEvent args) + { + args.Message = Accentuate(args.Message); + } +} diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index d589d555e5..b1606def37 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -276,6 +276,12 @@ namespace Content.Shared.CCVar public static readonly CVarDef GameTableBonk = CVarDef.Create("game.table_bonk", false, CVar.SERVERONLY); + /// + /// Enables the Roblox chat filter. True by default. + /// + public static readonly CVarDef GameChatFilter = + CVarDef.Create("game.chat_filter", true, CVar.SERVERONLY); + #if EXCEPTION_TOLERANCE /// /// Amount of times round start must fail before the server is shut down. diff --git a/Resources/Prototypes/Entities/Mobs/Species/base.yml b/Resources/Prototypes/Entities/Mobs/Species/base.yml index 3c9b8eb85f..94c374e50c 100644 --- a/Resources/Prototypes/Entities/Mobs/Species/base.yml +++ b/Resources/Prototypes/Entities/Mobs/Species/base.yml @@ -396,3 +396,4 @@ interfaces: - key: enum.HumanoidMarkingModifierKey.Key # sure, this can go here too type: HumanoidMarkingModifierBoundUserInterface + - type: ChatFilterAccent