Trim punctuation marks in the chat emote system (#28612)
Co-authored-by: geraeumig <alfenos@proton.me>
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user