fish-station/Content.Shared/_Sunrise/Messenger/EmojiSystem.cs
Vigers Ray 95d7d4d348
ыыыыы, месенжер макс, ихихяхя (#3789)
Co-authored-by: Daniel <77834935+Orvex07@users.noreply.github.com>
2026-01-26 22:44:54 +03:00

36 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Text.RegularExpressions;
using Robust.Shared.Prototypes;
namespace Content.Shared._Sunrise.Messenger;
/// <summary>
/// Система для работы с эмодзи в мессенджере
/// </summary>
public abstract class EmojiSystem : EntitySystem
{
[Dependency] protected readonly IPrototypeManager PrototypeManager = default!;
/// <summary>
/// Парсит текст сообщения и заменяет коды эмодзи на их представление в формате для RichTextLabel
/// </summary>
public string ParseEmojis(string text)
{
foreach (var emoji in PrototypeManager.EnumeratePrototypes<EmojiPrototype>())
{
var escapedCode = Regex.Escape(emoji.Code);
var pattern = $@"(?<![a-zA-Z0-9_]){escapedCode}(?![a-zA-Z0-9_])";
var replacement = $@"[emoji id=""{emoji.ID}""]";
text = Regex.Replace(text, pattern, replacement, RegexOptions.IgnoreCase);
}
return text;
}
/// <summary>
/// Получает все эмодзи
/// </summary>
public IEnumerable<EmojiPrototype> GetAllEmojis()
{
return PrototypeManager.EnumeratePrototypes<EmojiPrototype>();
}
}