Files
tbd-station-14/Content.Shared/Chat/V2/Moderation/RegexCensor.cs
Hannah Giovanna Dawson bf98a6a8bb 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
2024-03-26 10:50:20 +11:00

16 lines
446 B
C#

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);
}
}