[TXT] Render reactions

Addresses part of #168
pull/196/head
Alexey Golub 6 years ago
parent 02fe2a46e8
commit 557b5be844

@ -93,55 +93,88 @@ namespace DiscordChatExporter.Core.Rendering
private string FormatMarkdown(string markdown) => FormatMarkdown(MarkdownParser.Parse(markdown)); private string FormatMarkdown(string markdown) => FormatMarkdown(MarkdownParser.Parse(markdown));
private async Task RenderAttachmentAsync(TextWriter writer, Attachment attachment) private async Task RenderAttachmentsAsync(TextWriter writer, IReadOnlyList<Attachment> attachments)
{ {
await writer.WriteLineAsync("{Attachment}"); if (attachments.Any())
await writer.WriteLineAsync(attachment.Url); {
await writer.WriteLineAsync("{Attachments}");
foreach (var attachment in attachments)
await writer.WriteLineAsync(attachment.Url);
await writer.WriteLineAsync();
}
} }
private async Task RenderEmbedAsync(TextWriter writer, Embed embed) private async Task RenderEmbedsAsync(TextWriter writer, IReadOnlyList<Embed> embeds)
{ {
await writer.WriteLineAsync("{Embed}"); foreach (var embed in embeds)
{
await writer.WriteLineAsync("{Embed}");
// Author name // Author name
if (!(embed.Author?.Name).IsNullOrWhiteSpace()) if (!(embed.Author?.Name).IsNullOrWhiteSpace())
await writer.WriteLineAsync(embed.Author?.Name); await writer.WriteLineAsync(embed.Author?.Name);
// URL // URL
if (!embed.Url.IsNullOrWhiteSpace()) if (!embed.Url.IsNullOrWhiteSpace())
await writer.WriteLineAsync(embed.Url); await writer.WriteLineAsync(embed.Url);
// Title // Title
if (!embed.Title.IsNullOrWhiteSpace()) if (!embed.Title.IsNullOrWhiteSpace())
await writer.WriteLineAsync(FormatMarkdown(embed.Title)); await writer.WriteLineAsync(FormatMarkdown(embed.Title));
// Description // Description
if (!embed.Description.IsNullOrWhiteSpace()) if (!embed.Description.IsNullOrWhiteSpace())
await writer.WriteLineAsync(FormatMarkdown(embed.Description)); await writer.WriteLineAsync(FormatMarkdown(embed.Description));
// Fields // Fields
foreach (var field in embed.Fields) foreach (var field in embed.Fields)
{ {
// Name // Name
if (!field.Name.IsNullOrWhiteSpace()) if (!field.Name.IsNullOrWhiteSpace())
await writer.WriteLineAsync(field.Name); await writer.WriteLineAsync(field.Name);
// Value // Value
if (!field.Value.IsNullOrWhiteSpace()) if (!field.Value.IsNullOrWhiteSpace())
await writer.WriteLineAsync(field.Value); await writer.WriteLineAsync(field.Value);
}
// Thumbnail URL
if (!(embed.Thumbnail?.Url).IsNullOrWhiteSpace())
await writer.WriteLineAsync(embed.Thumbnail?.Url);
// Image URL
if (!(embed.Image?.Url).IsNullOrWhiteSpace())
await writer.WriteLineAsync(embed.Image?.Url);
// Footer text
if (!(embed.Footer?.Text).IsNullOrWhiteSpace())
await writer.WriteLineAsync(embed.Footer?.Text);
await writer.WriteLineAsync();
} }
}
// Thumbnail URL private async Task RenderReactionsAsync(TextWriter writer, IReadOnlyList<Reaction> reactions)
if (!(embed.Thumbnail?.Url).IsNullOrWhiteSpace()) {
await writer.WriteLineAsync(embed.Thumbnail?.Url); if (reactions.Any())
{
await writer.WriteLineAsync("{Reactions}");
foreach (var reaction in reactions)
{
await writer.WriteAsync(reaction.Emoji.Name);
if (reaction.Count > 1)
await writer.WriteAsync($" ({reaction.Count})");
// Image URL await writer.WriteAsync(" ");
if (!(embed.Image?.Url).IsNullOrWhiteSpace()) }
await writer.WriteLineAsync(embed.Image?.Url);
// Footer text await writer.WriteLineAsync();
if (!(embed.Footer?.Text).IsNullOrWhiteSpace()) await writer.WriteLineAsync();
await writer.WriteLineAsync(embed.Footer?.Text); }
} }
private async Task RenderMessageAsync(TextWriter writer, Message message) private async Task RenderMessageAsync(TextWriter writer, Message message)
@ -156,18 +189,13 @@ namespace DiscordChatExporter.Core.Rendering
await writer.WriteLineAsync(); await writer.WriteLineAsync();
// Attachments // Attachments
foreach (var attachment in message.Attachments) await RenderAttachmentsAsync(writer, message.Attachments);
{
await RenderAttachmentAsync(writer, attachment);
await writer.WriteLineAsync();
}
// Embeds // Embeds
foreach (var embed in message.Embeds) await RenderEmbedsAsync(writer, message.Embeds);
{
await RenderEmbedAsync(writer, embed); // Reactions
await writer.WriteLineAsync(); await RenderReactionsAsync(writer, message.Reactions);
}
} }
public async Task RenderAsync(TextWriter writer) public async Task RenderAsync(TextWriter writer)

Loading…
Cancel
Save