mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-18 05:59:03 +03:00
## Mirror of PR #25908: [SS14-17313 Chatfactor: Chat Censorship Systems](https://github.com/space-wizards/space-station-14/pull/25908) from <img src="https://avatars.githubusercontent.com/u/10567778?v=4" alt="space-wizards" width="22"/> [space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14) ###### `bf98a6a8bb2a57fb149459d6b053eaaf6abc8cd7` PR opened by <img src="https://avatars.githubusercontent.com/u/732532?v=4" width="16"/><a href="https://github.com/FairlySadPanda"> FairlySadPanda</a> at 2024-03-07 12:13:16 UTC - merged at 2024-03-25 23:50:20 UTC --- PR changed 4 files with 576 additions and 0 deletions. The PR had the following labels: - Status: Needs Review --- <details open="true"><summary><h1>Original Body</h1></summary> > <!-- Please read these guidelines before opening your PR: https://docs.spacestation14.io/en/getting-started/pr-guideline --> > <!-- The text between the arrows are comments - they will not be visible on your PR. --> > > ## About the PR > 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. > > ## Why / Balance > Partial fulfilment of #17313 > > ## Technical details > CE wants regex, CE gets regex > > Otherwise SimpleCensor is designed to be usable by people who don't want to faff with regex. > > This would be setup during server or client init, so would be driven by Cvars. > > ## Media > <!-- > PRs which make ingame changes (adding clothing, items, new features, etc) are required to have media attached that showcase the changes. > Small fixes/refactors are exempt. > Any media may be used in SS14 progress reports, with clear credit given. > > If you're unsure whether your PR will require media, ask a maintainer. > > Check the box below to confirm that you have in fact seen this (put an X in the brackets, like [X]): > --> > > - [x] I have added screenshots/videos to this PR showcasing its changes ingame, **or** this PR does not require an ingame showcase > > ## Breaking changes > nope > **Changelog** > nope </details> Co-authored-by: SimpleStation14 <Unknown>
60 lines
1.4 KiB
C#
60 lines
1.4 KiB
C#
using System.Linq;
|
|
|
|
namespace Content.Shared.Chat.V2.Moderation;
|
|
|
|
public interface IChatCensor
|
|
{
|
|
public bool Censor(string input, out string output, char replaceWith = '*');
|
|
}
|
|
|
|
public sealed class CompoundChatCensor(IEnumerable<IChatCensor> censors) : IChatCensor
|
|
{
|
|
public bool Censor(string input, out string output, char replaceWith = '*')
|
|
{
|
|
var censored = false;
|
|
|
|
foreach (var censor in censors)
|
|
{
|
|
if (censor.Censor(input, out output, replaceWith))
|
|
{
|
|
censored = true;
|
|
}
|
|
}
|
|
|
|
output = input;
|
|
|
|
return censored;
|
|
}
|
|
}
|
|
|
|
public sealed class ChatCensorFactory
|
|
{
|
|
private List<IChatCensor> _censors = new();
|
|
|
|
public void With(IChatCensor censor)
|
|
{
|
|
_censors.Add(censor);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Builds a ChatCensor that combines all the censors that have been added to this.
|
|
/// </summary>
|
|
public IChatCensor Build()
|
|
{
|
|
return new CompoundChatCensor(_censors.ToArray());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resets the build state to zero, allowing for different rules to be provided to the next censor(s) built.
|
|
/// </summary>
|
|
/// <returns>True if the builder had any setup prior to the reset.</returns>
|
|
public bool Reset()
|
|
{
|
|
var notEmpty = _censors.Count > 0;
|
|
|
|
_censors = new List<IChatCensor>();
|
|
|
|
return notEmpty;
|
|
}
|
|
}
|