Browse Source

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.
tags/2.2.0
Saulius Šaltenis Christopher F 5 years ago
parent
commit
2bba324143
2 changed files with 35 additions and 0 deletions
  1. +33
    -0
      src/Discord.Net.Core/Entities/Activities/SpotifyGame.cs
  2. +2
    -0
      src/Discord.Net.WebSocket/Extensions/EntityExtensions.cs

+ 33
- 0
src/Discord.Net.Core/Entities/Activities/SpotifyGame.cs View File

@@ -31,6 +31,23 @@ namespace Discord
/// A string containing the name of the song (e.g. <c>Lonely Together (feat. Rita Ora)</c>).
/// </returns>
public string TrackTitle { get; internal set; }

/// <summary>
/// Gets the date when the track started playing.
/// </summary>
/// <returns>
/// A <see cref="DateTimeOffset"/> containing the start timestamp of the song.
/// </returns>
public DateTimeOffset? StartedAt { get; internal set; }

/// <summary>
/// Gets the date when the track ends.
/// </summary>
/// <returns>
/// A <see cref="DateTimeOffset"/> containing the finish timestamp of the song.
/// </returns>
public DateTimeOffset? EndsAt { get; internal set; }

/// <summary>
/// Gets the duration of the song.
/// </summary>
@@ -39,6 +56,22 @@ namespace Discord
/// </returns>
public TimeSpan? Duration { get; internal set; }

/// <summary>
/// Gets the elapsed duration of the song.
/// </summary>
/// <returns>
/// A <see cref="TimeSpan"/> containing the elapsed duration of the song.
/// </returns>
public TimeSpan? Elapsed => DateTimeOffset.UtcNow - StartedAt;

/// <summary>
/// Gets the remaining duration of the song.
/// </summary>
/// <returns>
/// A <see cref="TimeSpan"/> containing the remaining duration of the song.
/// </returns>
public TimeSpan? Remaining => EndsAt - DateTimeOffset.UtcNow;

/// <summary>
/// Gets the track ID of the song.
/// </summary>


+ 2
- 0
src/Discord.Net.WebSocket/Extensions/EntityExtensions.cs View File

@@ -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,


Loading…
Cancel
Save