mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-10-01 00:27:59 +00:00
* 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
(cherry picked from commit bf98a6a8bb)
16 lines
446 B
C#
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);
|
|
}
|
|
}
|