Skip to content

Commit

Permalink
Potential fix for incorrectly parsed emotes when a message is offset …
Browse files Browse the repository at this point in the history
…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 <[email protected]>

---------

Co-authored-by: Isaac <[email protected]>
  • Loading branch information
mquin2003 and Zibbp authored Jul 14, 2024
1 parent 735c9f2 commit c513cfc
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/utils/tdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit c513cfc

Please sign in to comment.