Skip to content

Commit

Permalink
chore: chage icon assets and refactor color and icon handling in Disc…
Browse files Browse the repository at this point in the history
…ordService

- Add static fields for color and icon URLs in the `DiscordService` class
- Update the color and icon URL in the code to use the static fields
- Remove unnecessary code related to stream owner checks
- Update the color and icon URL for a specific scenario in the `CreateLiveChatPaidMessageEmbed` method
- Update the color and icon URL for a specific scenario in the `CreateLiveChatPaidStickerEmbed` method
- Simplify the logic for setting the membership background color in the `CreateLiveChatMembershipEmbed` method
- Update the color and icon URL for a specific scenario in the `CreateLiveChatPurchaseSponsorshipsGiftEmbed` method
- Add a new `gift.png` image file

Signed-off-by: 陳鈞 <[email protected]>
  • Loading branch information
jim60105 committed Dec 14, 2023
1 parent 019fcab commit 25fb046
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions Services/DiscordService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public class DiscordService
private readonly ILogger<DiscordService> _logger;
private readonly string _id;
private readonly DiscordWebhookClient _client;
private static readonly Color _ownerColor = new(0xffd600);
private static readonly Color _sponsorColor = new(0x0f9d58);
private static readonly string _crownIcon = "https://raw.githubusercontent.com/jim60105/YoutubeLiveChatToDiscord/master/assets/crown.png";
private static readonly string _walletIcon = "https://raw.githubusercontent.com/jim60105/YoutubeLiveChatToDiscord/master/assets/wallet.png";
private static readonly string _giftIcon = "https://raw.githubusercontent.com/jim60105/YoutubeLiveChatToDiscord/master/assets/gift.png";

public DiscordService(
ILogger<DiscordService> logger,
Expand Down Expand Up @@ -173,11 +178,10 @@ private static EmbedBuilder BuildNormalMessage(ref EmbedBuilder eb, LiveChatText
.WithIconUrl(authorBadgeUrl);

// From Stream Owner
//if (liveChatTextMessage.authorBadges?[0].liveChatAuthorBadgeRenderer?.icon?.iconType == "OWNER")
if (liveChatTextMessage.authorExternalChannelId == Environment.GetEnvironmentVariable("CHANNEL_ID"))
{
eb.WithColor(Color.Gold);
ft.WithIconUrl("https://raw.githubusercontent.com/jim60105/YoutubeLiveChatToDiscord/master/assets/crown.png");
eb.WithColor(_ownerColor);
ft.WithIconUrl(_crownIcon);
}

eb.WithFooter(ft);
Expand Down Expand Up @@ -209,13 +213,13 @@ private static EmbedBuilder BuildSuperChatMessage(ref EmbedBuilder eb, LiveChatP
ft.WithText(DateTimeOffset.FromUnixTimeMilliseconds(timeStamp)
.LocalDateTime
.ToString("yyyy/MM/dd HH:mm:ss"))
.WithIconUrl("https://raw.githubusercontent.com/jim60105/YoutubeLiveChatToDiscord/master/assets/wallet.png");
.WithIconUrl(_walletIcon);

// From Stream Owner
if (liveChatPaidMessage.authorExternalChannelId == Environment.GetEnvironmentVariable("CHANNEL_ID"))
{
eb.WithColor(Color.Gold);
ft.WithIconUrl("https://raw.githubusercontent.com/jim60105/YoutubeLiveChatToDiscord/master/assets/crown.png");
//eb.WithColor(_ownerColor);
ft.WithIconUrl(_crownIcon);
}

eb.WithFooter(ft);
Expand Down Expand Up @@ -249,13 +253,13 @@ private static EmbedBuilder BuildSuperChatStickerMessage(ref EmbedBuilder eb, Li
ft.WithText(DateTimeOffset.FromUnixTimeMilliseconds(timeStamp)
.LocalDateTime
.ToString("yyyy/MM/dd HH:mm:ss"))
.WithIconUrl("https://raw.githubusercontent.com/jim60105/YoutubeLiveChatToDiscord/master/assets/wallet.png");
.WithIconUrl(_walletIcon);

// From Stream Owner
if (liveChatPaidSticker.authorExternalChannelId == Environment.GetEnvironmentVariable("CHANNEL_ID"))
{
eb.WithColor(Color.Gold);
ft.WithIconUrl("https://raw.githubusercontent.com/jim60105/YoutubeLiveChatToDiscord/master/assets/crown.png");
//eb.WithColor(_ownerColor);
ft.WithIconUrl(_crownIcon);
}

eb.WithFooter(ft);
Expand Down Expand Up @@ -293,8 +297,7 @@ private static EmbedBuilder BuildMemberShipMessage(ref EmbedBuilder eb, LiveChat
.WithIconUrl(authorPhoto));

// Membership Background Color
Color sponsorColor = (Color)System.Drawing.ColorTranslator.FromHtml("#0F9D58");
eb.WithColor(sponsorColor);
eb.WithColor(_sponsorColor);

// Timestamp
long timeStamp = long.TryParse(liveChatMembershipItemRenderer.timestampUsec, out long l) ? l / 1000 : 0;
Expand All @@ -305,14 +308,6 @@ private static EmbedBuilder BuildMemberShipMessage(ref EmbedBuilder eb, LiveChat
.ToString("yyyy/MM/dd HH:mm:ss"))
.WithIconUrl(authorBadgeUrl);

// From Stream Owner
// I'm not sure if stream owner can join his own membership?
if (liveChatMembershipItemRenderer.authorExternalChannelId == Environment.GetEnvironmentVariable("CHANNEL_ID"))
{
//eb.WithColor(Color.Gold);
ft.WithIconUrl("https://raw.githubusercontent.com/jim60105/YoutubeLiveChatToDiscord/master/assets/crown.png");
}

eb.WithFooter(ft);
return eb;
}
Expand All @@ -332,8 +327,7 @@ private static EmbedBuilder BuildPurchaseSponsorshipsGiftMessage(ref EmbedBuilde
eb.WithFields(new EmbedFieldBuilder[] { new EmbedFieldBuilder().WithName("Amount").WithValue(header?.primaryText?.runs?[1].text) });

// Gift Background Color
Color sponsorColor = (Color)System.Drawing.ColorTranslator.FromHtml("#0F9D58");
eb.WithColor(sponsorColor);
eb.WithColor(_sponsorColor);

// Gift Picture
string? giftThumbUrl = header?.image?.thumbnails?.LastOrDefault()?.url;
Expand All @@ -345,13 +339,13 @@ private static EmbedBuilder BuildPurchaseSponsorshipsGiftMessage(ref EmbedBuilde
ft.WithText(DateTimeOffset.FromUnixTimeMilliseconds(timeStamp)
.LocalDateTime
.ToString("yyyy/MM/dd HH:mm:ss"))
.WithIconUrl("https://raw.githubusercontent.com/jim60105/YoutubeLiveChatToDiscord/master/assets/wallet.png");
.WithIconUrl(_giftIcon);

// From Stream Owner
if (liveChatPurchaseSponsorshipsGift?.authorExternalChannelId == Environment.GetEnvironmentVariable("CHANNEL_ID"))
{
//eb.WithColor(Color.Gold);
ft.WithIconUrl("https://raw.githubusercontent.com/jim60105/YoutubeLiveChatToDiscord/master/assets/crown.png");
//eb.WithColor(_ownerColor);
ft.WithIconUrl(_crownIcon);
}

eb.WithFooter(ft);
Expand Down
Binary file modified assets/crown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/gift.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/wallet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 25fb046

Please sign in to comment.