From 2bba324143063f39b46bad92563bec068a4b35cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saulius=20=C5=A0altenis?= <31516441+LtLi0n@users.noreply.github.com> Date: Sat, 30 Nov 2019 05:11:48 +0200 Subject: [PATCH] feature: add StartedAt, EndsAt, Elapsed and Remaining to SpotifyGame. (#1414) * Fixed GetUsersAsync to use MaxUsersPerBatch const as limit instead of MaxMessagesPerBatch. Requests are now returning up to 1000 guild user entities instead of the previous 100. * Added StartedAt and EndsAt timespans for SpotifyGame. They make it possible to expose track's Elapsed and Remaining properties. * Moved Duration to be initialized within model construction. * Updated StartedAt and EndsAt comments. --- .../Entities/Activities/SpotifyGame.cs | 33 +++++++++++++++++++ .../Extensions/EntityExtensions.cs | 2 ++ 2 files changed, 35 insertions(+) diff --git a/src/Discord.Net.Core/Entities/Activities/SpotifyGame.cs b/src/Discord.Net.Core/Entities/Activities/SpotifyGame.cs index 23f88687d..4eab34fa2 100644 --- a/src/Discord.Net.Core/Entities/Activities/SpotifyGame.cs +++ b/src/Discord.Net.Core/Entities/Activities/SpotifyGame.cs @@ -31,6 +31,23 @@ 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 when the track started playing. + /// + /// + /// A containing the start timestamp of the song. + /// + public DateTimeOffset? StartedAt { get; internal set; } + + /// + /// Gets the date when the track ends. + /// + /// + /// A containing the finish timestamp of the song. + /// + public DateTimeOffset? EndsAt { get; internal set; } + /// /// Gets the duration of the song. /// @@ -39,6 +56,22 @@ namespace Discord /// public TimeSpan? Duration { get; internal set; } + /// + /// 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..5149eea5b 100644 --- a/src/Discord.Net.WebSocket/Extensions/EntityExtensions.cs +++ b/src/Discord.Net.WebSocket/Extensions/EntityExtensions.cs @@ -38,6 +38,8 @@ namespace Discord.WebSocket AlbumTitle = albumText, TrackTitle = model.Details.GetValueOrDefault(), Artists = model.State.GetValueOrDefault()?.Split(';').Select(x=>x?.Trim()).ToImmutableArray(), + StartedAt = timestamps?.Start, + EndsAt = timestamps?.End, Duration = timestamps?.End - timestamps?.Start, AlbumArtUrl = albumArtId != null ? CDN.GetSpotifyAlbumArtUrl(albumArtId) : null, Type = ActivityType.Listening,