From c513cfc0f988ad90d24483736bff0ca568521a5f Mon Sep 17 00:00:00 2001 From: Manuel Date: Sun, 14 Jul 2024 10:48:57 -0400 Subject: [PATCH] Potential fix for incorrectly parsed emotes when a message is offset due to unicode characters. (#467) * Update tdl.go Updated for scenarios where a live comment may be offset due to the presence of unicode characters. * Apply suggestions from code review Applied Zibbp's suggestions. Thank you! Co-authored-by: Isaac --------- Co-authored-by: Isaac --- internal/utils/tdl.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/utils/tdl.go b/internal/utils/tdl.go index c0a09777..6a3aac19 100644 --- a/internal/utils/tdl.go +++ b/internal/utils/tdl.go @@ -179,6 +179,10 @@ func ConvertTwitchLiveChatToTDLChat(path string, channelName string, videoID str Emoticon: nil, }) + // set default offset value for this live comment + + message_is_offset := false + // parse emotes, creating fragments with positions emoteFragments := []Fragment{} if liveComment.Emotes != nil { @@ -198,8 +202,9 @@ func ConvertTwitchLiveChatToTDLChat(path string, channelName string, videoID str // ensure that the sliced string equals the emote // sometimes the output of chat-downloader will not include a unicode character when calculating positions causing an offset in positions - if slicedEmote != liveCommentEmote.Name { + if slicedEmote != liveCommentEmote.Name || message_is_offset { log.Debug().Str("message_id", liveComment.MessageID).Msg("emote position mismatch detected while converting chat") + message_is_offset = true // attempt to get emote position in comment message pos1, pos2, found := findSubstringPositions(liveComment.Message, liveCommentEmote.Name, i+1)