Adds DateFormatString to DiscordRestApiClient

This commit is contained in:
Sindre G. Langhus
2016-11-25 17:09:17 +01:00
parent a455ccc334
commit d0158816d3
3 changed files with 18 additions and 6 deletions

View File

@@ -17,7 +17,7 @@ namespace Discord.API
[JsonProperty("color")] [JsonProperty("color")]
public uint? Color { get; set; } public uint? Color { get; set; }
[JsonProperty("timestamp")] [JsonProperty("timestamp")]
public Optional<DateTimeOffset> Timestamp { get; set; } public DateTimeOffset? Timestamp { get; set; }
[JsonProperty("author")] [JsonProperty("author")]
public Optional<EmbedAuthor> Author { get; set; } public Optional<EmbedAuthor> Author { get; set; }
[JsonProperty("footer")] [JsonProperty("footer")]

View File

@@ -49,7 +49,7 @@ namespace Discord.API
{ {
_restClientProvider = restClientProvider; _restClientProvider = restClientProvider;
_userAgent = userAgent; _userAgent = userAgent;
_serializer = serializer ?? new JsonSerializer { ContractResolver = new DiscordContractResolver() }; _serializer = serializer ?? new JsonSerializer { DateFormatString = "yyyy-MM-ddTHH:mm:ssZ", DateTimeZoneHandling = DateTimeZoneHandling.Utc, ContractResolver = new DiscordContractResolver() };
RequestQueue = requestQueue; RequestQueue = requestQueue;
FetchCurrentUser = true; FetchCurrentUser = true;

View File

@@ -26,6 +26,7 @@ namespace Discord
public string ThumbnailUrl { get; set; } public string ThumbnailUrl { get; set; }
public string ImageUrl { get; set; } public string ImageUrl { get; set; }
public Color? Color { get { return _model.Color.HasValue ? new Color(_model.Color.Value) : (Color?)null; } set { _model.Color = value?.RawValue; } } public Color? Color { get { return _model.Color.HasValue ? new Color(_model.Color.Value) : (Color?)null; } set { _model.Color = value?.RawValue; } }
public DateTimeOffset? Timestamp { get; set; }
public EmbedAuthorBuilder Author { get; set; } public EmbedAuthorBuilder Author { get; set; }
public EmbedFooterBuilder Footer { get; set; } public EmbedFooterBuilder Footer { get; set; }
@@ -59,6 +60,16 @@ namespace Discord
Color = color; Color = color;
return this; return this;
} }
public EmbedBuilder WithTimestamp()
{
Timestamp = DateTimeOffset.UtcNow;
return this;
}
public EmbedBuilder WithTimestamp(DateTimeOffset dateTimeOffset)
{
Timestamp = dateTimeOffset;
return this;
}
public EmbedBuilder WithAuthor(EmbedAuthorBuilder author) public EmbedBuilder WithAuthor(EmbedAuthorBuilder author)
{ {
@@ -97,6 +108,7 @@ namespace Discord
{ {
_model.Author = Author?.ToModel(); _model.Author = Author?.ToModel();
_model.Footer = Footer?.ToModel(); _model.Footer = Footer?.ToModel();
_model.Timestamp = Timestamp?.ToUniversalTime();
_model.Thumbnail = ThumbnailUrl != null ? new Thumbnail { Url = ThumbnailUrl } : null; _model.Thumbnail = ThumbnailUrl != null ? new Thumbnail { Url = ThumbnailUrl } : null;
_model.Image = ImageUrl != null ? new Image { Url = ImageUrl } : null; _model.Image = ImageUrl != null ? new Image { Url = ImageUrl } : null;
_model.Fields = _fields.ToArray(); _model.Fields = _fields.ToArray();
@@ -106,7 +118,7 @@ namespace Discord
public class EmbedFieldBuilder public class EmbedFieldBuilder
{ {
private Field _model; private readonly Field _model;
public string Name { get { return _model.Name; } set { _model.Name = value; } } public string Name { get { return _model.Name; } set { _model.Name = value; } }
public string Value { get { return _model.Value; } set { _model.Value = value; } } public string Value { get { return _model.Value; } set { _model.Value = value; } }
@@ -138,7 +150,7 @@ namespace Discord
public class EmbedAuthorBuilder public class EmbedAuthorBuilder
{ {
private Author _model; private readonly Author _model;
public string Name { get { return _model.Name; } set { _model.Name = value; } } public string Name { get { return _model.Name; } set { _model.Name = value; } }
public string Url { get { return _model.Url; } set { _model.Url = value; } } public string Url { get { return _model.Url; } set { _model.Url = value; } }
@@ -170,7 +182,7 @@ namespace Discord
public class EmbedFooterBuilder public class EmbedFooterBuilder
{ {
private Footer _model; private readonly Footer _model;
public string Text { get { return _model.Text; } set { _model.Text = value; } } public string Text { get { return _model.Text; } set { _model.Text = value; } }
public string IconUrl { get { return _model.IconUrl; } set { _model.IconUrl = value; } } public string IconUrl { get { return _model.IconUrl; } set { _model.IconUrl = value; } }