Refactor Games, support reading Rich Presences (#877)

* Add API-level support for Rich Presences

* Add library-level support for Game presences

* Add model conversions for outgoing+incoming rich presences

* Refactored Game into Activities

* Integrated Activities with user entities

rebase hell from 5f3cb947a92f4fd01cc4df47ca548180036b47f3

* Fix JSON converters for Activities

* Finish rebase, activity should be set on BaseSocketClient

* Use ApplicationId to define a rich presence

* Added SetActivityAsync to Base and Sharded Socket clients

* Remove public parameterless Game constructor

* Remove GameAssets, refactored to GameAsset

* Hide constructors for types that should be read-only

* Revert changes to Discord.Net.sln

got damned visual studio caching

* Refactor GameParty to use dedicated current/capacity values

Per feedback from @khionu
This commit is contained in:
Christopher F
2017-12-23 14:58:35 -05:00
committed by GitHub
parent 678a7238e6
commit 34b4e5a6d2
28 changed files with 376 additions and 58 deletions

View File

@@ -0,0 +1,28 @@
using System;
using Newtonsoft.Json;
namespace Discord.Net.Converters
{
public class UnixTimestampConverter : JsonConverter
{
public static readonly UnixTimestampConverter Instance = new UnixTimestampConverter();
public override bool CanConvert(Type objectType) => true;
public override bool CanRead => true;
public override bool CanWrite => true;
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
// Discord doesn't validate if timestamps contain decimals or not
if (reader.Value is double d)
return new DateTimeOffset(1970, 1, 1, 0, 0, 0, 0, TimeSpan.Zero).AddMilliseconds(d);
long offset = (long)reader.Value;
return new DateTimeOffset(1970, 1, 1, 0, 0, 0, 0, TimeSpan.Zero).AddMilliseconds(offset);
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
}