| @@ -5,12 +5,12 @@ namespace Discord.API | |||||
| internal class GameAssets | internal class GameAssets | ||||
| { | { | ||||
| [JsonProperty("small_text")] | [JsonProperty("small_text")] | ||||
| public Optional<string> SmallText { get; } | |||||
| public Optional<string> SmallText { get; set; } | |||||
| [JsonProperty("small_image")] | [JsonProperty("small_image")] | ||||
| public Optional<string> SmallImage { get; } | |||||
| public Optional<string> SmallImage { get; set; } | |||||
| [JsonProperty("large_image")] | [JsonProperty("large_image")] | ||||
| public Optional<string> LargeText { get; } | |||||
| public Optional<string> LargeText { get; set; } | |||||
| [JsonProperty("large_text")] | [JsonProperty("large_text")] | ||||
| public Optional<string> LargeImage { get; } | |||||
| public Optional<string> LargeImage { get; set; } | |||||
| } | } | ||||
| } | } | ||||
| @@ -334,6 +334,12 @@ namespace Discord.WebSocket | |||||
| Game = null; | Game = null; | ||||
| await SendStatusAsync().ConfigureAwait(false); | await SendStatusAsync().ConfigureAwait(false); | ||||
| } | } | ||||
| public async Task SetGameAsync(Game game) | |||||
| { | |||||
| Game = game; | |||||
| await SendStatusAsync().ConfigureAwait(false); | |||||
| } | |||||
| private async Task SendStatusAsync() | private async Task SendStatusAsync() | ||||
| { | { | ||||
| if (CurrentUser == null) | if (CurrentUser == null) | ||||
| @@ -346,11 +352,49 @@ namespace Discord.WebSocket | |||||
| GameModel gameModel; | GameModel gameModel; | ||||
| if (game != null) | if (game != null) | ||||
| { | { | ||||
| var assets = game.Value.Assets.HasValue | |||||
| ? new API.GameAssets() | |||||
| { | |||||
| SmallText = game.Value.Assets.Value.SmallText, | |||||
| SmallImage = game.Value.Assets.Value.SmallImage, | |||||
| LargeText = game.Value.Assets.Value.LargeText, | |||||
| LargeImage = game.Value.Assets.Value.LargeImage, | |||||
| } | |||||
| : Optional.Create<API.GameAssets>(); | |||||
| var party = game.Value.Party.HasValue | |||||
| ? new API.GameParty | |||||
| { | |||||
| Id = game.Value.Party.Value.Id, | |||||
| Size = game.Value.Party.Value.Size | |||||
| } | |||||
| : Optional.Create<API.GameParty>(); | |||||
| var secrets = game.Value.Secrets.HasValue | |||||
| ? new API.GameSecrets() | |||||
| { | |||||
| Join = game.Value.Secrets.Value.Join, | |||||
| Match = game.Value.Secrets.Value.Match, | |||||
| Spectate = game.Value.Secrets.Value.Spectate | |||||
| } | |||||
| : Optional.Create<API.GameSecrets>(); | |||||
| var timestamps = game.Value.Timestamps.HasValue | |||||
| ? new API.GameTimestamps | |||||
| { | |||||
| Start = game.Value.Timestamps.Value.Start, | |||||
| End = game.Value.Timestamps.Value.End | |||||
| } | |||||
| : Optional.Create<API.GameTimestamps>(); | |||||
| gameModel = new API.Game | gameModel = new API.Game | ||||
| { | { | ||||
| Name = game.Value.Name, | Name = game.Value.Name, | ||||
| StreamType = game.Value.StreamType, | StreamType = game.Value.StreamType, | ||||
| StreamUrl = game.Value.StreamUrl | |||||
| StreamUrl = game.Value.StreamUrl, | |||||
| Details = game.Value.Details, | |||||
| State = game.Value.State, | |||||
| ApplicationId = game.Value.ApplicationId ?? Optional.Create<ulong>(), | |||||
| Assets = assets, | |||||
| Party = party, | |||||
| Secrets = secrets, | |||||
| Timestamps = timestamps, | |||||
| }; | }; | ||||
| } | } | ||||
| else | else | ||||
| @@ -6,7 +6,38 @@ | |||||
| { | { | ||||
| return new Game(model.Name, | return new Game(model.Name, | ||||
| model.StreamUrl.GetValueOrDefault(null), | model.StreamUrl.GetValueOrDefault(null), | ||||
| model.StreamType.GetValueOrDefault(null) ?? StreamType.NotStreaming); | |||||
| model.StreamType.GetValueOrDefault(null) ?? StreamType.NotStreaming, | |||||
| model.Details.GetValueOrDefault(), | |||||
| model.State.GetValueOrDefault(), | |||||
| model.ApplicationId.ToNullable(), | |||||
| model.Assets.GetValueOrDefault(null)?.ToEntity(), | |||||
| model.Party.GetValueOrDefault(null)?.ToEntity(), | |||||
| model.Secrets.GetValueOrDefault(null)?.ToEntity(), | |||||
| model.Timestamps.GetValueOrDefault(null)?.ToEntity() | |||||
| ); | |||||
| } | |||||
| public static GameAssets ToEntity(this API.GameAssets model) | |||||
| { | |||||
| return new GameAssets(model.SmallText.GetValueOrDefault(), | |||||
| model.SmallImage.GetValueOrDefault(), | |||||
| model.LargeText.GetValueOrDefault(), | |||||
| model.LargeImage.GetValueOrDefault()); | |||||
| } | |||||
| public static GameParty ToEntity(this API.GameParty model) | |||||
| { | |||||
| return new GameParty(model.Size, model.Id); | |||||
| } | |||||
| public static GameSecrets ToEntity(this API.GameSecrets model) | |||||
| { | |||||
| return new GameSecrets(model.Match, model.Join, model.Spectate); | |||||
| } | |||||
| public static GameTimestamps ToEntity(this API.GameTimestamps model) | |||||
| { | |||||
| return new GameTimestamps(model.Start, model.End); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||