SS14-17313 Chatfactor: Chat Censorship Systems (#25908)

* SS14-17313 Chat Censorship Systems

Adds some systems to manage chat censorship:

1. No-op: does nothing
2. SimpleCensor: a regex-free censor with a variety of rules to use
3. RegexCensor: a censor that uses regex.

This exposes a singleton backed by a builder pattern (ChatCensor) that
is set up, probably during the code init phase, and then globally available
for your censorship needs.

* Migrate to Shared

* Add a reset function to the builder.

* Resolve PJB's feedback; add unit tests
This commit is contained in:
Hannah Giovanna Dawson
2024-03-25 23:50:20 +00:00
committed by GitHub
parent bd58954d4e
commit bf98a6a8bb
4 changed files with 576 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
using System.Text.RegularExpressions;
namespace Content.Shared.Chat.V2.Moderation;
public sealed class RegexCensor(Regex censorInstruction) : IChatCensor
{
private readonly Regex _censorInstruction = censorInstruction;
public bool Censor(string input, out string output, char replaceWith = '*')
{
output = _censorInstruction.Replace(input, replaceWith.ToString());
return !string.Equals(input, output);
}
}