Add Spotify track support (#970)
* Initial Spotify support * Remove GameAsset#ToEntity - appId doesn't seem to be necessary, and Spotify Game doesn't return appId either. * Implement SpotifyGame details * Implement song Duration prop * Add album art CDN * Fix ActivityType * Remove payload debug * Add changes according to review + Make `ApplicationId` nullable + Move ctor after props
This commit is contained in:
@@ -4,6 +4,27 @@ namespace Discord.WebSocket
|
||||
{
|
||||
public static IActivity ToEntity(this API.Game model)
|
||||
{
|
||||
// Spotify Game
|
||||
if (model.SyncId.IsSpecified)
|
||||
{
|
||||
var assets = model.Assets.GetValueOrDefault()?.ToEntity();
|
||||
string albumText = assets?[1]?.Text;
|
||||
string albumArtId = assets?[1]?.ImageId?.Replace("spotify:","");
|
||||
var timestamps = model.Timestamps.IsSpecified ? model.Timestamps.Value.ToEntity() : null;
|
||||
return new SpotifyGame
|
||||
{
|
||||
Name = model.Name,
|
||||
SessionId = model.SessionId.GetValueOrDefault(),
|
||||
SyncId = model.SyncId.Value,
|
||||
AlbumTitle = albumText,
|
||||
TrackTitle = model.Details.GetValueOrDefault(),
|
||||
Artists = model.State.GetValueOrDefault()?.Split(';'),
|
||||
Duration = timestamps?.End - timestamps?.Start,
|
||||
AlbumArt = albumArtId != null ? $"https://i.scdn.co/image/{albumArtId}" : null,
|
||||
Type = ActivityType.Listening
|
||||
};
|
||||
}
|
||||
|
||||
// Rich Game
|
||||
if (model.ApplicationId.IsSpecified)
|
||||
{
|
||||
@@ -34,7 +55,7 @@ namespace Discord.WebSocket
|
||||
}
|
||||
|
||||
// (Small, Large)
|
||||
public static GameAsset[] ToEntity(this API.GameAssets model, ulong appId)
|
||||
public static GameAsset[] ToEntity(this API.GameAssets model, ulong? appId = null)
|
||||
{
|
||||
return new GameAsset[]
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user