Browse Source

Added StartedAt and EndsAt timespans for SpotifyGame.

They make it possible to expose track's Elapsed and Remaining properties.
pull/1414/head
LtLi0n 5 years ago
parent
commit
3c67868bea
2 changed files with 36 additions and 2 deletions
  1. +34
    -1
      src/Discord.Net.Core/Entities/Activities/SpotifyGame.cs
  2. +2
    -1
      src/Discord.Net.WebSocket/Extensions/EntityExtensions.cs

+ 34
- 1
src/Discord.Net.Core/Entities/Activities/SpotifyGame.cs View File

@@ -31,13 +31,46 @@ 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 the track began playing at.
/// </summary>
/// <returns>
/// A <see cref="DateTimeOffset"/> containing the start timestamp of the song.
/// </returns>
public DateTimeOffset? StartedAt { get; internal set; }

/// <summary>
/// Gets the date the track will stop playing at.
/// </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>
/// <returns>
/// A <see cref="TimeSpan"/> containing the duration of the song.
/// </returns>
public TimeSpan? Duration { get; internal set; }
public TimeSpan? Duration => EndsAt - StartedAt;

/// <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.


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

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


Loading…
Cancel
Save