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:
committed by
GitHub
parent
bd58954d4e
commit
bf98a6a8bb
15
Content.Shared/Chat/V2/Moderation/RegexCensor.cs
Normal file
15
Content.Shared/Chat/V2/Moderation/RegexCensor.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user