From cd60424bfca9f18fb3b7fef548c8dfcdba86331c Mon Sep 17 00:00:00 2001 From: Scrub <72096833+ScrubN@users.noreply.github.com> Date: Mon, 2 Sep 2024 23:52:11 -0400 Subject: [PATCH] Render continuing anonymous gift subs correctly (#1206) * Recognize continuing anonymous gifts separately from continuing regular gifts * Update tests * Render continuing anonymous gift subs correctly * Fix comment --- .../ToolTests/HighlightIconsTests.cs | 6 +++++- TwitchDownloaderCore/ChatRenderer.cs | 1 + TwitchDownloaderCore/Tools/HighlightIcons.cs | 10 ++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/TwitchDownloaderCore.Tests/ToolTests/HighlightIconsTests.cs b/TwitchDownloaderCore.Tests/ToolTests/HighlightIconsTests.cs index c47ccd45..1cd6f80b 100644 --- a/TwitchDownloaderCore.Tests/ToolTests/HighlightIconsTests.cs +++ b/TwitchDownloaderCore.Tests/ToolTests/HighlightIconsTests.cs @@ -98,8 +98,12 @@ private static Comment CreateCommentWithMessage(string viewerDisplayName, string // Special case, in separate method. // ContinuingGift [InlineData( - "{\"body\":\"viewer8 is continuing the Gift Sub they got from an anonymous user! \",\"bits_spent\":0,\"fragments\":[{\"text\":\"viewer8 is continuing the Gift Sub they got from an anonymous user! \",\"emoticon\":null}],\"user_badges\":[{\"_id\":\"subscriber\",\"version\":\"0\"}],\"user_color\":\"#8A2BE2\",\"emoticons\":[]}", + "{\"body\":\"viewer8 is continuing the Gift Sub they got from viewer9! \",\"bits_spent\":0,\"fragments\":[{\"text\":\"viewer8 is continuing the Gift Sub they got from viewer9! \",\"emoticon\":null}],\"user_badges\":[{\"_id\":\"subscriber\",\"version\":\"0\"}],\"user_color\":\"#8A2BE2\",\"emoticons\":[]}", HighlightType.ContinuingGift)] + // ContinuingAnonymousGift + [InlineData( + "{\"body\":\"viewer8 is continuing the Gift Sub they got from an anonymous user! \",\"bits_spent\":0,\"fragments\":[{\"text\":\"viewer8 is continuing the Gift Sub they got from an anonymous user! \",\"emoticon\":null}],\"user_badges\":[{\"_id\":\"subscriber\",\"version\":\"0\"}],\"user_color\":\"#8A2BE2\",\"emoticons\":[]}", + HighlightType.ContinuingAnonymousGift)] // PayingForward [InlineData( "{\"body\":\"viewer8 is paying forward the Gift they got from an anonymous gifter to the community! \",\"bits_spent\":0,\"fragments\":[{\"text\":\"viewer8 is paying forward the Gift they got from an anonymous gifter to the community! \",\"emoticon\":null}],\"user_badges\":[{\"_id\":\"subscriber\",\"version\":\"0\"},{\"_id\":\"bits\",\"version\":\"100\"}],\"user_color\":null,\"emoticons\":[]}", diff --git a/TwitchDownloaderCore/ChatRenderer.cs b/TwitchDownloaderCore/ChatRenderer.cs index 17861d91..9d8081e8 100644 --- a/TwitchDownloaderCore/ChatRenderer.cs +++ b/TwitchDownloaderCore/ChatRenderer.cs @@ -709,6 +709,7 @@ private void DrawAccentedMessage(Comment comment, List<(SKImageInfo info, SKBitm case HighlightType.GiftedMany: case HighlightType.GiftedSingle: case HighlightType.GiftedAnonymous: + case HighlightType.ContinuingAnonymousGift: DrawGiftMessage(comment, sectionImages, emotePositionList, ref drawPos, defaultPos, highlightIcon, iconPoint); break; case HighlightType.ChannelPointHighlight: diff --git a/TwitchDownloaderCore/Tools/HighlightIcons.cs b/TwitchDownloaderCore/Tools/HighlightIcons.cs index 1a986769..8e66cde1 100644 --- a/TwitchDownloaderCore/Tools/HighlightIcons.cs +++ b/TwitchDownloaderCore/Tools/HighlightIcons.cs @@ -17,6 +17,7 @@ public enum HighlightType GiftedMany, GiftedSingle, ContinuingGift, + ContinuingAnonymousGift, GiftedAnonymous, PayingForward, ChannelPointHighlight, @@ -104,8 +105,13 @@ public static HighlightType GetHighlightType(Comment comment) if (bodyWithoutName.StartsWith(" gifted a Tier")) return HighlightType.GiftedSingle; - if (bodyWithoutName.StartsWith(" is continuing the Gift Sub")) + if (bodyWithoutName.StartsWith(" is continuing the Gift Sub they got from")) + { + if (bodyWithoutName.EndsWith("from an anonymous user! ")) + return HighlightType.ContinuingAnonymousGift; + return HighlightType.ContinuingGift; + } if (bodyWithoutName.StartsWith(" is paying forward the Gift they got from")) return HighlightType.PayingForward; @@ -162,7 +168,7 @@ public SKImage GetHighlightIcon(HighlightType highlightType, SKColor textColor) HighlightType.SubscribedPrime => _subscribedPrimeIcon ??= GenerateSvgIcon(SUBSCRIBED_PRIME_ICON_SVG, _purple), HighlightType.GiftedSingle => _giftSingleIcon ??= GenerateSvgIcon(GIFTED_SINGLE_ICON_SVG, textColor), HighlightType.GiftedMany => _giftManyIcon ??= GenerateGiftedManyIcon(), - HighlightType.GiftedAnonymous => _giftAnonymousIcon ??= GenerateSvgIcon(GIFTED_ANONYMOUS_ICON_SVG, textColor), + HighlightType.GiftedAnonymous or HighlightType.ContinuingAnonymousGift => _giftAnonymousIcon ??= GenerateSvgIcon(GIFTED_ANONYMOUS_ICON_SVG, textColor), HighlightType.BitBadgeTierNotification => _bitBadgeTierNotificationIcon ??= GenerateSvgIcon(BIT_BADGE_TIER_NOTIFICATION_ICON_SVG, textColor), HighlightType.WatchStreak => _watchStreakIcon ??= GenerateSvgIcon(WATCH_STREAK_ICON_SVG, textColor), HighlightType.CharityDonation => _charityDonationIcon ??= GenerateSvgIcon(CHARITY_DONATION_ICON_SVG, textColor),