Trim punctuation marks in the chat emote system (#28612)

Co-authored-by: geraeumig <alfenos@proton.me>
This commit is contained in:
geraeumig
2024-08-19 00:49:07 +02:00
committed by GitHub
parent 3cb67a3564
commit c48a96ac15
2 changed files with 20 additions and 148 deletions

View File

@@ -161,14 +161,32 @@ public partial class ChatSystem
/// <param name="textInput"></param>
private void TryEmoteChatInput(EntityUid uid, string textInput)
{
var actionLower = textInput.ToLower();
if (!_wordEmoteDict.TryGetValue(actionLower, out var emote))
var actionTrimmedLower = TrimPunctuation(textInput.ToLower());
if (!_wordEmoteDict.TryGetValue(actionTrimmedLower, out var emote))
return;
if (!AllowedToUseEmote(uid, emote))
return;
InvokeEmoteEvent(uid, emote);
return;
static string TrimPunctuation(string textInput)
{
var trimEnd = textInput.Length;
while (trimEnd > 0 && char.IsPunctuation(textInput[trimEnd - 1]))
{
trimEnd--;
}
var trimStart = 0;
while (trimStart < trimEnd && char.IsPunctuation(textInput[trimStart]))
{
trimStart++;
}
return textInput[trimStart..trimEnd];
}
}
/// <summary>
/// Checks if we can use this emote based on the emotes whitelist, blacklist, and availibility to the entity.