| @@ -2,7 +2,7 @@ | |||||
| { | { | ||||
| public class GameParty | public class GameParty | ||||
| { | { | ||||
| public ulong[] Size { get; internal set; } | |||||
| public ulong Id { get; internal set; } | |||||
| public string Id { get; internal set; } | |||||
| public int[] Size { get; internal set; } | |||||
| } | } | ||||
| } | } | ||||
| @@ -4,10 +4,10 @@ namespace Discord | |||||
| { | { | ||||
| public class GameTimestamps | public class GameTimestamps | ||||
| { | { | ||||
| public DateTimeOffset Start { get; } | |||||
| public DateTimeOffset End { get; } | |||||
| public DateTimeOffset? Start { get; } | |||||
| public DateTimeOffset? End { get; } | |||||
| public GameTimestamps(DateTimeOffset start, DateTimeOffset end) | |||||
| public GameTimestamps(DateTimeOffset? start, DateTimeOffset? end) | |||||
| { | { | ||||
| Start = start; | Start = start; | ||||
| End = end; | End = end; | ||||
| @@ -5,8 +5,8 @@ namespace Discord.API | |||||
| internal class GameParty | internal class GameParty | ||||
| { | { | ||||
| [JsonProperty("id")] | [JsonProperty("id")] | ||||
| public ulong Id { get; set; } | |||||
| public string Id { get; set; } | |||||
| [JsonProperty("size")] | [JsonProperty("size")] | ||||
| public ulong[] Size { get; set; } | |||||
| public int[] Size { get; set; } | |||||
| } | } | ||||
| } | } | ||||
| @@ -6,8 +6,10 @@ namespace Discord.API | |||||
| internal class GameTimestamps | internal class GameTimestamps | ||||
| { | { | ||||
| [JsonProperty("start")] | [JsonProperty("start")] | ||||
| public DateTimeOffset Start { get; set; } | |||||
| [UnixTimestamp] | |||||
| public Optional<DateTimeOffset> Start { get; set; } | |||||
| [JsonProperty("end")] | [JsonProperty("end")] | ||||
| public DateTimeOffset End { get; set; } | |||||
| [UnixTimestamp] | |||||
| public Optional<DateTimeOffset> End { get; set; } | |||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,7 @@ | |||||
| using System; | |||||
| namespace Discord.API | |||||
| { | |||||
| [AttributeUsage(AttributeTargets.Property)] | |||||
| internal class UnixTimestampAttribute : Attribute { } | |||||
| } | |||||
| @@ -66,6 +66,12 @@ namespace Discord.Net.Converters | |||||
| if (type == typeof(ulong)) | if (type == typeof(ulong)) | ||||
| return UInt64Converter.Instance; | return UInt64Converter.Instance; | ||||
| } | } | ||||
| bool hasUnixStamp = propInfo.GetCustomAttribute<UnixTimestampAttribute>() != null; | |||||
| if (hasUnixStamp) | |||||
| { | |||||
| if (type == typeof(DateTimeOffset)) | |||||
| return UnixTimestampConverter.Instance; | |||||
| } | |||||
| //Enums | //Enums | ||||
| if (type == typeof(PermissionTarget)) | if (type == typeof(PermissionTarget)) | ||||
| @@ -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(); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -69,7 +69,7 @@ | |||||
| public static GameTimestamps ToEntity(this API.GameTimestamps model) | public static GameTimestamps ToEntity(this API.GameTimestamps model) | ||||
| { | { | ||||
| return new GameTimestamps(model.Start, model.End); | |||||
| return new GameTimestamps(model.Start.ToNullable(), model.End.ToNullable()); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||