From 3c67868beaf33a19e003b2a3e07c000ac7434071 Mon Sep 17 00:00:00 2001 From: LtLi0n Date: Sun, 10 Nov 2019 23:40:31 +0200 Subject: [PATCH] Added StartedAt and EndsAt timespans for SpotifyGame. They make it possible to expose track's Elapsed and Remaining properties. --- .../Entities/Activities/SpotifyGame.cs | 35 ++++++++++++++++++- .../Extensions/EntityExtensions.cs | 3 +- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Activities/SpotifyGame.cs b/src/Discord.Net.Core/Entities/Activities/SpotifyGame.cs index 23f88687d..2cde168c5 100644 --- a/src/Discord.Net.Core/Entities/Activities/SpotifyGame.cs +++ b/src/Discord.Net.Core/Entities/Activities/SpotifyGame.cs @@ -31,13 +31,46 @@ namespace Discord /// A string containing the name of the song (e.g. Lonely Together (feat. Rita Ora)). /// public string TrackTitle { get; internal set; } + + /// + /// Gets the date the track began playing at. + /// + /// + /// A containing the start timestamp of the song. + /// + public DateTimeOffset? StartedAt { get; internal set; } + + /// + /// Gets the date the track will stop playing at. + /// + /// + /// A containing the finish timestamp of the song. + /// + public DateTimeOffset? EndsAt { get; internal set; } + /// /// Gets the duration of the song. /// /// /// A containing the duration of the song. /// - public TimeSpan? Duration { get; internal set; } + public TimeSpan? Duration => EndsAt - StartedAt; + + /// + /// Gets the elapsed duration of the song. + /// + /// + /// A containing the elapsed duration of the song. + /// + public TimeSpan? Elapsed => DateTimeOffset.UtcNow - StartedAt; + + /// + /// Gets the remaining duration of the song. + /// + /// + /// A containing the remaining duration of the song. + /// + public TimeSpan? Remaining => EndsAt - DateTimeOffset.UtcNow; /// /// Gets the track ID of the song. diff --git a/src/Discord.Net.WebSocket/Extensions/EntityExtensions.cs b/src/Discord.Net.WebSocket/Extensions/EntityExtensions.cs index bad72aaea..093097cf9 100644 --- a/src/Discord.Net.WebSocket/Extensions/EntityExtensions.cs +++ b/src/Discord.Net.WebSocket/Extensions/EntityExtensions.cs @@ -38,7 +38,8 @@ namespace Discord.WebSocket AlbumTitle = albumText, TrackTitle = model.Details.GetValueOrDefault(), Artists = model.State.GetValueOrDefault()?.Split(';').Select(x=>x?.Trim()).ToImmutableArray(), - Duration = timestamps?.End - timestamps?.Start, + StartedAt = timestamps?.Start, + EndsAt = timestamps?.End, AlbumArtUrl = albumArtId != null ? CDN.GetSpotifyAlbumArtUrl(albumArtId) : null, Type = ActivityType.Listening, Flags = model.Flags.GetValueOrDefault(),