Skip to content

Commit

Permalink
Merge pull request #6 from Smalls1652/update/add-soundcloud-button
Browse files Browse the repository at this point in the history
[Update] Add SoundCloud button
  • Loading branch information
Smalls1652 authored Jul 23, 2023
2 parents 4a563e1 + 83b7046 commit 641633f
Showing 1 changed file with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ private ComponentBuilder GenerateMusicShareComponent(MusicEntityItem entityItem)
spotifyLink = null;
}

// Attempt to get the Spotify link for the music item.
PlatformEntityLink? soundcloudLink;
try
{
soundcloudLink = entityItem.LinksByPlatform!["soundcloud"];
}
catch
{
_logger.LogWarning("No SoundCloud link found for {url}", entityItem.PageUrl);
soundcloudLink = null;
}

// Create the YouTube button component.
ButtonBuilder youtubeButton;
if (youtubeLink is not null)
Expand Down Expand Up @@ -115,6 +127,29 @@ private ComponentBuilder GenerateMusicShareComponent(MusicEntityItem entityItem)
);
}

// Create the SoundCloud button component.
ButtonBuilder soundcloudButton;
if (soundcloudLink is not null)
{
// If the SoundCloud link is not null, create a button component with the link.
soundcloudButton = new(
label: "SoundCloud",
style: ButtonStyle.Link,
url: spotifyLink.Url!.ToString()
);
}
else
{
// If the SoundCloud link is null, create a button component with a disabled label.
soundcloudButton = new(
label: "SoundCloud",
style: ButtonStyle.Secondary,
isDisabled: true,
emote: new Emoji("🚫"),
customId: $"{entityItem.EntityUniqueId}-soundcloud-disabled"
);
}

// Create the "More links" button component.
ButtonBuilder moreLinksButton = new(
label: "More links",
Expand All @@ -132,11 +167,12 @@ private ComponentBuilder GenerateMusicShareComponent(MusicEntityItem entityItem)

// Create the component builder from the button components.
ComponentBuilder linksComponentBuilder = new ComponentBuilder()
.WithButton(youtubeButton)
.WithButton(appleMusicButton)
.WithButton(spotifyButton)
.WithButton(moreLinksButton)
.WithButton(refreshButton);
.WithButton(youtubeButton, 0)
.WithButton(appleMusicButton, 0)
.WithButton(spotifyButton, 0)
.WithButton(soundcloudButton, 0)
.WithButton(moreLinksButton, 1)
.WithButton(refreshButton, 1);

return linksComponentBuilder;
}
Expand Down

0 comments on commit 641633f

Please sign in to comment.