Browse Source

Adds DateFormatString to DiscordRestApiClient

tags/1.0-rc
Sindre G. Langhus 8 years ago
parent
commit
d0158816d3
3 changed files with 18 additions and 6 deletions
  1. +1
    -1
      src/Discord.Net.Core/API/Common/Embed.cs
  2. +1
    -1
      src/Discord.Net.Core/API/DiscordRestApiClient.cs
  3. +16
    -4
      src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs

+ 1
- 1
src/Discord.Net.Core/API/Common/Embed.cs View File

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


+ 1
- 1
src/Discord.Net.Core/API/DiscordRestApiClient.cs View File

@@ -49,7 +49,7 @@ namespace Discord.API
{
_restClientProvider = restClientProvider;
_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;
FetchCurrentUser = true;



+ 16
- 4
src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs View File

@@ -20,12 +20,13 @@ namespace Discord
_fields = new List<Field>();
}

public string Title { get { return _model.Title; } set { _model.Title = value; } }
public string Title { get { return _model.Title; } set { _model.Title = value; } }
public string Description { get { return _model.Description; } set { _model.Description = value; } }
public string Url { get { return _model.Url; } set { _model.Url = value; } }
public string ThumbnailUrl { 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 DateTimeOffset? Timestamp { get; set; }
public EmbedAuthorBuilder Author { get; set; }
public EmbedFooterBuilder Footer { get; set; }

@@ -59,6 +60,16 @@ namespace Discord
Color = color;
return this;
}
public EmbedBuilder WithTimestamp()
{
Timestamp = DateTimeOffset.UtcNow;
return this;
}
public EmbedBuilder WithTimestamp(DateTimeOffset dateTimeOffset)
{
Timestamp = dateTimeOffset;
return this;
}

public EmbedBuilder WithAuthor(EmbedAuthorBuilder author)
{
@@ -97,6 +108,7 @@ namespace Discord
{
_model.Author = Author?.ToModel();
_model.Footer = Footer?.ToModel();
_model.Timestamp = Timestamp?.ToUniversalTime();
_model.Thumbnail = ThumbnailUrl != null ? new Thumbnail { Url = ThumbnailUrl } : null;
_model.Image = ImageUrl != null ? new Image { Url = ImageUrl } : null;
_model.Fields = _fields.ToArray();
@@ -106,7 +118,7 @@ namespace Discord

public class EmbedFieldBuilder
{
private Field _model;
private readonly Field _model;

public string Name { get { return _model.Name; } set { _model.Name = value; } }
public string Value { get { return _model.Value; } set { _model.Value = value; } }
@@ -138,7 +150,7 @@ namespace Discord

public class EmbedAuthorBuilder
{
private Author _model;
private readonly Author _model;

public string Name { get { return _model.Name; } set { _model.Name = value; } }
public string Url { get { return _model.Url; } set { _model.Url = value; } }
@@ -170,7 +182,7 @@ namespace Discord

public class EmbedFooterBuilder
{
private Footer _model;
private readonly Footer _model;

public string Text { get { return _model.Text; } set { _model.Text = value; } }
public string IconUrl { get { return _model.IconUrl; } set { _model.IconUrl = value; } }


Loading…
Cancel
Save