Skip to content

Commit

Permalink
refactor: BuildMemberShipMessage
Browse files Browse the repository at this point in the history
- Add a new class `HeaderPrimaryText` in `Models/Chat.cs`
- Add a new property `headerPrimaryText` in the `Chat` class in `Models/Chat.cs`
- Add a new property `message` in the `Chat` class in `Models/Chat.cs`
- Modify the `BuildMemberShipMessage` method in `DiscordService.cs` to handle nullable properties
- Add a check for `null` in the `BuildMemberShipMessage` method in `DiscordService.cs`
- Modify the `BuildMemberShipMessage` method in `DiscordService.cs` to include fields in the embed if `message` is not null
- Modify the `BuildMemberShipMessage` method in `DiscordService.cs` to include fields in the embed if `header` is not null

Signed-off-by: 陳鈞 <[email protected]>
  • Loading branch information
jim60105 committed Dec 13, 2023
1 parent 6c22e18 commit 4183f54
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Models/Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public class Message
public List<Run> runs { get; set; }
}

public class HeaderPrimaryText
{
public List<Run> runs { get; set; }
}

public class HeaderSubtext
{
public List<Run> runs { get; set; }
Expand Down Expand Up @@ -262,7 +267,9 @@ public class LiveChatMembershipItemRenderer
public string id { get; set; }
public string timestampUsec { get; set; }
public string authorExternalChannelId { get; set; }
public HeaderPrimaryText headerPrimaryText { get; set; }
public HeaderSubtext headerSubtext { get; set; }
public Message message { get; set; }
public AuthorName authorName { get; set; }
public AuthorPhoto authorPhoto { get; set; }
public List<AuthorBadge> authorBadges { get; set; }
Expand Down
24 changes: 21 additions & 3 deletions Services/DiscordService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,31 @@ private static EmbedBuilder BuildSuperChatStickerMessage(ref EmbedBuilder eb, Li

private static EmbedBuilder BuildMemberShipMessage(ref EmbedBuilder eb, LiveChatMembershipItemRenderer liveChatMembershipItemRenderer, out string author)
{
List<Run> runs = liveChatMembershipItemRenderer.headerSubtext?.runs ?? new List<Run>();
List<Run>? header = liveChatMembershipItemRenderer.headerPrimaryText?.runs
?? liveChatMembershipItemRenderer.headerSubtext?.runs;
List<Run>? message = liveChatMembershipItemRenderer.message?.runs;

author = liveChatMembershipItemRenderer.authorName?.simpleText ?? "";
string authorPhoto = Helper.GetOriginalImage(liveChatMembershipItemRenderer.authorPhoto?.thumbnails?.LastOrDefault()?.url);

eb.WithDescription(string.Join("", runs.Select(p => p.text ?? (p.emoji?.searchTerms?.FirstOrDefault()))))
.WithAuthor(new EmbedAuthorBuilder().WithName(author)
if (null != message)
{
eb.WithDescription(string.Join("", (message ?? []).Select(p => p.text ?? (p.emoji?.searchTerms?.FirstOrDefault()))));
if (null != header)
{
eb.WithFields(new EmbedFieldBuilder[]
{
new EmbedFieldBuilder().WithName("Header")
.WithValue(string.Join("", header.Select(p => p.text ?? (p.emoji?.searchTerms?.FirstOrDefault()))))
});
}
}
else if (null != header)
{
eb.WithDescription(string.Join("", (header ?? []).Select(p => p.text ?? (p.emoji?.searchTerms?.FirstOrDefault()))));
}

eb.WithAuthor(new EmbedAuthorBuilder().WithName(author)
.WithUrl($"https://www.youtube.com/channel/{liveChatMembershipItemRenderer.authorExternalChannelId}")
.WithIconUrl(authorPhoto));

Expand Down

0 comments on commit 4183f54

Please sign in to comment.