Chat Filter (April Fools) (#14999)

This commit is contained in:
GoodWheatley 2023-04-01 17:47:21 -04:00 • committed by GitHub
parent 8ca2182a7c
commit 4434b3752c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 106 additions and 0 deletions

View file

@ -0,0 +1,9 @@
namespace Content.Server.Speech.Components;
// #####. ##### ### ###. #####? ### #####!
[RegisterComponent]
public sealed class ChatFilterAccentComponent : Component
{
}

View file

@ -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<string, string> 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<ChatFilterAccentComponent, AccentGetEvent>(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);
}
}

View file

@ -276,6 +276,12 @@ namespace Content.Shared.CCVar
public static readonly CVarDef<bool> GameTableBonk =
CVarDef.Create("game.table_bonk", false, CVar.SERVERONLY);
/// <summary>
/// Enables the Roblox chat filter. True by default.
/// </summary>
public static readonly CVarDef<bool> GameChatFilter =
CVarDef.Create("game.chat_filter", true, CVar.SERVERONLY);
#if EXCEPTION_TOLERANCE
/// <summary>
/// Amount of times round start must fail before the server is shut down.

View file

@ -396,3 +396,4 @@
interfaces:
- key: enum.HumanoidMarkingModifierKey.Key # sure, this can go here too
type: HumanoidMarkingModifierBoundUserInterface
- type: ChatFilterAccent