Using static Regex functions that take in a pattern is bad because the pattern constantly needs to be re-parsed. With https://github.com/space-wizards/RobustToolbox/pull/5107, the engine has an analyzer to warn for this practice now. This commit brings most of content up to snuff already, though some of the tricker code I left for somebody else.
29 lines
810 B
C#
29 lines
810 B
C#
using System.Text.RegularExpressions;
|
|
using Content.Server.Speech.Components;
|
|
|
|
namespace Content.Server.Speech.EntitySystems;
|
|
|
|
public sealed class MothAccentSystem : EntitySystem
|
|
{
|
|
private static readonly Regex RegexLowerBuzz = new Regex("z{1,3}");
|
|
private static readonly Regex RegexUpperBuzz = new Regex("Z{1,3}");
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<MothAccentComponent, AccentGetEvent>(OnAccent);
|
|
}
|
|
|
|
private void OnAccent(EntityUid uid, MothAccentComponent component, AccentGetEvent args)
|
|
{
|
|
var message = args.Message;
|
|
|
|
// buzzz
|
|
message = RegexLowerBuzz.Replace(message, "zzz");
|
|
// buZZZ
|
|
message = RegexUpperBuzz.Replace(message, "ZZZ");
|
|
|
|
args.Message = message;
|
|
}
|
|
}
|