using Content.Server.Speech.Components; using System.Text.RegularExpressions; namespace Content.Server.Speech.EntitySystems; /// /// System that gives the speaker a faux-French accent. /// public sealed class FrenchAccentSystem : EntitySystem { [Dependency] private readonly ReplacementAccentSystem _replacement = default!; private static readonly Regex RegexTh = new(@"th", RegexOptions.IgnoreCase); private static readonly Regex RegexStartH = new(@"(?(OnAccentGet); } public string Accentuate(string message, FrenchAccentComponent component) { var msg = message; msg = _replacement.ApplyReplacements(msg, "french"); // replaces th with z msg = RegexTh.Replace(msg, "'z"); // replaces h with ' at the start of words. msg = RegexStartH.Replace(msg, "'"); // spaces out ! ? : and ;. msg = RegexSpacePunctuation.Replace(msg, " $&"); return msg; } private void OnAccentGet(EntityUid uid, FrenchAccentComponent component, AccentGetEvent args) { args.Message = Accentuate(args.Message, component); } }