Closed Hampo closed 11 months ago
Version tested on was 4.0.0-preview-bb8afa27cfa09f9d3c221969879b0adb43809afa
Looking into it some, it appears Twitch uses multibyte encoding (UTF-16 maybe) and those are the indexes provided. The issue is the network traffic is decoded as UTF-8. You can use StringInfo
's SubstringByTextElements
to correctly parse the string. Example working code to remove emotes from a ChatMessage
:
static string RemoveEmotes(ChatMessage msg)
{
StringBuilder parsed = new(msg.Message.Length);
StringInfo rawInfo = new(msg.Message);
int startIndex = 0;
foreach (Emote emote in msg.EmoteSet.Emotes.OrderBy(x => x.StartIndex))
{
parsed.Append(rawInfo.SubstringByTextElements(startIndex, emote.StartIndex - startIndex));
parsed.Replace(" ", " ");
startIndex = emote.EndIndex + 1;
}
if (startIndex < rawInfo.LengthInTextElements)
{
parsed.Append(rawInfo.SubstringByTextElements(startIndex));
parsed.Replace(" ", " ");
}
return parsed.ToString();
}
Fixed #260
Sent the message
One 😂 Two Kappa Three
in Twitch:Set a breakpoint on the first
Emote
in theEmoteSet
:You can see the
emote.Name
isKapp
instead ofKappa
. Best guess isEmoteExtractor
not respecting multi-byte characters, like emoji.