|
|
@ -20,6 +20,7 @@ internal class JsonMessageWriter : MessageWriter
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_writer = new Utf8JsonWriter(stream, new JsonWriterOptions
|
|
|
|
_writer = new Utf8JsonWriter(stream, new JsonWriterOptions
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
// https://github.com/Tyrrrz/DiscordChatExporter/issues/450
|
|
|
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
|
|
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
|
|
|
Indented = true,
|
|
|
|
Indented = true,
|
|
|
|
// Validation errors may mask actual failures
|
|
|
|
// Validation errors may mask actual failures
|
|
|
@ -50,7 +51,7 @@ internal class JsonMessageWriter : MessageWriter
|
|
|
|
EmbedAuthor embedAuthor,
|
|
|
|
EmbedAuthor embedAuthor,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_writer.WriteStartObject("author");
|
|
|
|
_writer.WriteStartObject();
|
|
|
|
|
|
|
|
|
|
|
|
_writer.WriteString("name", embedAuthor.Name);
|
|
|
|
_writer.WriteString("name", embedAuthor.Name);
|
|
|
|
_writer.WriteString("url", embedAuthor.Url);
|
|
|
|
_writer.WriteString("url", embedAuthor.Url);
|
|
|
@ -62,27 +63,11 @@ internal class JsonMessageWriter : MessageWriter
|
|
|
|
await _writer.FlushAsync(cancellationToken);
|
|
|
|
await _writer.FlushAsync(cancellationToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async ValueTask WriteEmbedThumbnailAsync(
|
|
|
|
|
|
|
|
EmbedImage embedThumbnail,
|
|
|
|
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_writer.WriteStartObject("thumbnail");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(embedThumbnail.Url))
|
|
|
|
|
|
|
|
_writer.WriteString("url", await Context.ResolveMediaUrlAsync(embedThumbnail.ProxyUrl ?? embedThumbnail.Url, cancellationToken));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_writer.WriteNumber("width", embedThumbnail.Width);
|
|
|
|
|
|
|
|
_writer.WriteNumber("height", embedThumbnail.Height);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_writer.WriteEndObject();
|
|
|
|
|
|
|
|
await _writer.FlushAsync(cancellationToken);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async ValueTask WriteEmbedImageAsync(
|
|
|
|
private async ValueTask WriteEmbedImageAsync(
|
|
|
|
EmbedImage embedImage,
|
|
|
|
EmbedImage embedImage,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_writer.WriteStartObject("image");
|
|
|
|
_writer.WriteStartObject();
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(embedImage.Url))
|
|
|
|
if (!string.IsNullOrWhiteSpace(embedImage.Url))
|
|
|
|
_writer.WriteString("url", await Context.ResolveMediaUrlAsync(embedImage.ProxyUrl ?? embedImage.Url, cancellationToken));
|
|
|
|
_writer.WriteString("url", await Context.ResolveMediaUrlAsync(embedImage.ProxyUrl ?? embedImage.Url, cancellationToken));
|
|
|
@ -98,7 +83,7 @@ internal class JsonMessageWriter : MessageWriter
|
|
|
|
EmbedFooter embedFooter,
|
|
|
|
EmbedFooter embedFooter,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_writer.WriteStartObject("footer");
|
|
|
|
_writer.WriteStartObject();
|
|
|
|
|
|
|
|
|
|
|
|
_writer.WriteString("text", embedFooter.Text);
|
|
|
|
_writer.WriteString("text", embedFooter.Text);
|
|
|
|
|
|
|
|
|
|
|
@ -138,16 +123,37 @@ internal class JsonMessageWriter : MessageWriter
|
|
|
|
_writer.WriteString("color", embed.Color.Value.ToHex());
|
|
|
|
_writer.WriteString("color", embed.Color.Value.ToHex());
|
|
|
|
|
|
|
|
|
|
|
|
if (embed.Author is not null)
|
|
|
|
if (embed.Author is not null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_writer.WritePropertyName("author");
|
|
|
|
await WriteEmbedAuthorAsync(embed.Author, cancellationToken);
|
|
|
|
await WriteEmbedAuthorAsync(embed.Author, cancellationToken);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (embed.Thumbnail is not null)
|
|
|
|
if (embed.Thumbnail is not null)
|
|
|
|
await WriteEmbedThumbnailAsync(embed.Thumbnail, cancellationToken);
|
|
|
|
{
|
|
|
|
|
|
|
|
_writer.WritePropertyName("thumbnail");
|
|
|
|
|
|
|
|
await WriteEmbedImageAsync(embed.Thumbnail, cancellationToken);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (embed.Image is not null)
|
|
|
|
// Legacy: backwards-compatibility for old embeds with a single image
|
|
|
|
await WriteEmbedImageAsync(embed.Image, cancellationToken);
|
|
|
|
if (embed.Images.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_writer.WritePropertyName("image");
|
|
|
|
|
|
|
|
await WriteEmbedImageAsync(embed.Images[0], cancellationToken);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (embed.Footer is not null)
|
|
|
|
if (embed.Footer is not null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_writer.WritePropertyName("footer");
|
|
|
|
await WriteEmbedFooterAsync(embed.Footer, cancellationToken);
|
|
|
|
await WriteEmbedFooterAsync(embed.Footer, cancellationToken);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Images
|
|
|
|
|
|
|
|
_writer.WriteStartArray("images");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var image in embed.Images)
|
|
|
|
|
|
|
|
await WriteEmbedImageAsync(image, cancellationToken);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_writer.WriteEndArray();
|
|
|
|
|
|
|
|
|
|
|
|
// Fields
|
|
|
|
// Fields
|
|
|
|
_writer.WriteStartArray("fields");
|
|
|
|
_writer.WriteStartArray("fields");
|
|
|
|