Skip to content

Commit

Permalink
feat: add lower bumper functionality
Browse files Browse the repository at this point in the history
- Add a lower bumper to the `DiscordService` class
- Add a `AppendLowerBumper` method to handle appending the lower bumper to an `EmbedBuilder`
- Use the `AppendLowerBumper` method to add a lower bumper to the `eb` variable in the `DiscordService` class

Signed-off-by: 陳鈞 <[email protected]>
  • Loading branch information
jim60105 committed Dec 14, 2023
1 parent 25fb046 commit 71a4b41
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 7 deletions.
153 changes: 146 additions & 7 deletions Models/Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class Image
{
public List<Thumbnail> thumbnails { get; set; }
public Accessibility accessibility { get; set; }
public List<Source> sources { get; set; }
}

public class Emoji
Expand Down Expand Up @@ -178,12 +179,20 @@ public class LiveChatPaidMessageRenderer
public long timestampColor { get; set; }
public ContextMenuAccessibility contextMenuAccessibility { get; set; }
public string trackingParams { get; set; }
public HeaderOverlayImage headerOverlayImage { get; set; }
public int textInputBackgroundColor { get; set; }
public LowerBumper lowerBumper { get; set; }
public CreatorHeartButton creatorHeartButton { get; set; }
public bool isV2Style { get; set; }
public PdgPurchasedNoveltyLoggingDirectives pdgPurchasedNoveltyLoggingDirectives { get; set; }
}

public class Text
{
public string simpleText { get; set; }
public List<Run> runs { get; set; }
public string content { get; set; }
public List<StyleRun> styleRuns { get; set; }
}

public class UrlEndpoint
Expand Down Expand Up @@ -260,6 +269,13 @@ public class LiveChatPaidStickerRenderer
public long backgroundColor { get; set; }
public long authorNameTextColor { get; set; }
public string trackingParams { get; set; }
// Actually I doesn't find the 1st purchase sticker. These properties are copied from the LiveChatPaidMessageRenderer
public HeaderOverlayImage headerOverlayImage { get; set; }
public int textInputBackgroundColor { get; set; }
public LowerBumper lowerBumper { get; set; }
public CreatorHeartButton creatorHeartButton { get; set; }
public bool isV2Style { get; set; }
public PdgPurchasedNoveltyLoggingDirectives pdgPurchasedNoveltyLoggingDirectives { get; set; }
}

public class LiveChatMembershipItemRenderer
Expand Down Expand Up @@ -496,13 +512,15 @@ public class RemoveChatItemAction
public class ReplayChatItemAction
{
public List<Action> actions { get; set; }
public string videoOffsetTimeMsec { get; set; }
}

#pragma warning disable CS8981 // 類型名稱只包含小寫的 ASCII 字元。此類名稱可能保留供此語言使用。
public class chat
#pragma warning restore CS8981 // 類型名稱只包含小寫的 ASCII 字元。此類名稱可能保留供此語言使用。
{
public ReplayChatItemAction replayChatItemAction { get; set; }
public string clickTrackingParams { get; set; }
public string videoOffsetTimeMsec { get; set; }
public bool isLive { get; set; }
}
Expand All @@ -516,13 +534,6 @@ public class LiveChatModeChangeMessageRenderer
public Subtext subtext { get; set; }
}

public class Root
{
public ReplayChatItemAction replayChatItemAction { get; set; }
public string videoOffsetTimeMsec { get; set; }
public bool isLive { get; set; }
}

public class Subtext
{
public List<Run> runs { get; set; }
Expand Down Expand Up @@ -666,4 +677,132 @@ public class Thumbnail
public int width { get; set; }
public string resolution { get; set; }
}

public class BorderImageProcessor
{
public ImageTint imageTint { get; set; }
}

public class BumperUserEduContentViewModel
{
public Text text { get; set; }
public string trackingParams { get; set; }
public Image image { get; set; }
}

public class ClientResource
{
public string imageName { get; set; }
public long imageColor { get; set; }
}

public class Content
{
public BumperUserEduContentViewModel bumperUserEduContentViewModel { get; set; }
}

public class CreatorHeartButton
{
public CreatorHeartViewModel creatorHeartViewModel { get; set; }
}

public class CreatorHeartViewModel
{
public CreatorThumbnail creatorThumbnail { get; set; }
public HeartedIcon heartedIcon { get; set; }
public UnheartedIcon unheartedIcon { get; set; }
public string heartedHoverText { get; set; }
public string heartedAccessibilityLabel { get; set; }
public string unheartedAccessibilityLabel { get; set; }
public string engagementStateKey { get; set; }
public Gradient gradient { get; set; }
public LoggingDirectives loggingDirectives { get; set; }
}

public class CreatorThumbnail
{
public List<Source> sources { get; set; }
}

public class Gradient
{
public List<Source> sources { get; set; }
public Processor processor { get; set; }
}

public class HeaderOverlayImage
{
public List<Thumbnail> thumbnails { get; set; }
}

public class HeartedIcon
{
public List<Source> sources { get; set; }
}

public class ImageTint
{
public long color { get; set; }
}

public class LiveChatItemBumperViewModel
{
public Content content { get; set; }
public PdgPurchasedBumperLoggingDirectives pdgPurchasedBumperLoggingDirectives { get; set; }
}

public class LoggingDirectives
{
public string trackingParams { get; set; }
public Visibility visibility { get; set; }
public bool enableDisplayloggerExperiment { get; set; }
}

public class LowerBumper
{
public LiveChatItemBumperViewModel liveChatItemBumperViewModel { get; set; }
}

public class PdgPurchasedBumperLoggingDirectives
{
public LoggingDirectives loggingDirectives { get; set; }
}

public class PdgPurchasedNoveltyLoggingDirectives
{
public LoggingDirectives loggingDirectives { get; set; }
}

public class Processor
{
public BorderImageProcessor borderImageProcessor { get; set; }
}

public class Source
{
public ClientResource clientResource { get; set; }
public string url { get; set; }
}

public class StyleRun
{
public int startIndex { get; set; }
public int length { get; set; }
}

public class TimestampText
{
public string simpleText { get; set; }
}

public class UnheartedIcon
{
public List<Source> sources { get; set; }
public Processor processor { get; set; }
}

public class Visibility
{
public string types { get; set; }
}
}
13 changes: 13 additions & 0 deletions Services/DiscordService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ private static EmbedBuilder BuildSuperChatMessage(ref EmbedBuilder eb, LiveChatP
Color bgColor = (Color)System.Drawing.ColorTranslator.FromHtml(Helper.YoutubeColorConverter(liveChatPaidMessage.bodyBackgroundColor));
eb.WithColor(bgColor);

// Lower Bumper
eb = AppendLowerBumper(ref eb, liveChatPaidMessage.lowerBumper);

// Timestamp
long timeStamp = long.TryParse(liveChatPaidMessage.timestampUsec, out long l) ? l / 1000 : 0;
EmbedFooterBuilder ft = new();
Expand Down Expand Up @@ -247,6 +250,9 @@ private static EmbedBuilder BuildSuperChatStickerMessage(ref EmbedBuilder eb, Li
string stickerThumbUrl = Helper.GetOriginalImage("https:" + liveChatPaidSticker.sticker?.thumbnails?.LastOrDefault()?.url);
eb.WithThumbnailUrl(stickerThumbUrl);

// Lower Bumper
eb = AppendLowerBumper(ref eb, liveChatPaidSticker.lowerBumper);

// Timestamp
long timeStamp = long.TryParse(liveChatPaidSticker.timestampUsec, out long l) ? l / 1000 : 0;
EmbedFooterBuilder ft = new();
Expand Down Expand Up @@ -352,6 +358,13 @@ private static EmbedBuilder BuildPurchaseSponsorshipsGiftMessage(ref EmbedBuilde
return eb;
}

private static EmbedBuilder AppendLowerBumper(ref EmbedBuilder eb, LowerBumper lowerBumper)
=> eb.WithFields(new EmbedFieldBuilder[]
{
new EmbedFieldBuilder().WithName("LowerBumper")
.WithValue(lowerBumper.liveChatItemBumperViewModel.content.bumperUserEduContentViewModel.text.content)
});

private async Task SendMessage(EmbedBuilder eb, string author, CancellationToken cancellationToken)
{
_logger.LogDebug("Sending Request to Discord: {author}: {message}", author, eb.Description);
Expand Down

0 comments on commit 71a4b41

Please sign in to comment.