diff --git a/Helper.cs b/Helper.cs index 95462bb..c12aa8e 100644 --- a/Helper.cs +++ b/Helper.cs @@ -75,4 +75,19 @@ public static string GetOriginalImage(string? url) return url; } + + public static string YoutubeColorConverter(long color) + { + color &= 16777215; + long[] temp = [(color & 16711680) >> 16, (color & 65280) >> 8, color & 255]; + int r = (int)temp[0]; + int g = (int)temp[1]; + int b = (int)temp[2]; + + if (r != (r & 255) || g != (g & 255) || b != (b & 255)) + throw new Exception($"\"({r},{g},{b})\" is not a valid RGB color"); + + int hex = r << 16 | g << 8 | b; + return r < 16 ? "#" + (16777216 | hex).ToString("X")[1..] : "#" + hex.ToString("X"); + } } diff --git a/Models/Chat.cs b/Models/Chat.cs index ef7e233..bb54466 100644 --- a/Models/Chat.cs +++ b/Models/Chat.cs @@ -163,14 +163,14 @@ public class LiveChatPaidMessageRenderer public AuthorPhoto authorPhoto { get; set; } public PurchaseAmountText purchaseAmountText { get; set; } public Message message { get; set; } - public object headerBackgroundColor { get; set; } - public object headerTextColor { get; set; } - public object bodyBackgroundColor { get; set; } - public object bodyTextColor { get; set; } + public long headerBackgroundColor { get; set; } + public long headerTextColor { get; set; } + public long bodyBackgroundColor { get; set; } + public long bodyTextColor { get; set; } public string authorExternalChannelId { get; set; } - public object authorNameTextColor { get; set; } + public long authorNameTextColor { get; set; } public ContextMenuEndpoint contextMenuEndpoint { get; set; } - public object timestampColor { get; set; } + public long timestampColor { get; set; } public ContextMenuAccessibility contextMenuAccessibility { get; set; } public string trackingParams { get; set; } } diff --git a/Services/DiscordService.cs b/Services/DiscordService.cs index a33af64..b522ff6 100644 --- a/Services/DiscordService.cs +++ b/Services/DiscordService.cs @@ -200,7 +200,7 @@ private static EmbedBuilder BuildSuperChatMessage(ref EmbedBuilder eb, LiveChatP eb.WithFields(new EmbedFieldBuilder[] { new EmbedFieldBuilder().WithName("Amount").WithValue(liveChatPaidMessage.purchaseAmountText?.simpleText) }); // Super Chat Background Color - Color bgColor = (Color)System.Drawing.ColorTranslator.FromHtml(string.Format("#{0:X}", liveChatPaidMessage.bodyBackgroundColor)); + Color bgColor = (Color)System.Drawing.ColorTranslator.FromHtml(Helper.YoutubeColorConverter(liveChatPaidMessage.bodyBackgroundColor)); eb.WithColor(bgColor); // Timestamp @@ -236,7 +236,7 @@ private static EmbedBuilder BuildSuperChatStickerMessage(ref EmbedBuilder eb, Li eb.WithFields(new EmbedFieldBuilder[] { new EmbedFieldBuilder().WithName("Amount").WithValue(liveChatPaidSticker.purchaseAmountText?.simpleText) }); // Super Chat Background Color - Color bgColor = (Color)System.Drawing.ColorTranslator.FromHtml(string.Format("#{0:X}", liveChatPaidSticker.backgroundColor)); + Color bgColor = (Color)System.Drawing.ColorTranslator.FromHtml(Helper.YoutubeColorConverter(liveChatPaidSticker.backgroundColor)); eb.WithColor(bgColor); // Super Chat Sticker Picture