[TXT] Render reactions

Addresses part of #168
This commit is contained in:
Alexey Golub 2019-06-11 22:39:17 +03:00
parent 02fe2a46e8
commit 557b5be844

View file

@ -93,13 +93,22 @@ 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("{Attachments}");
foreach (var attachment in attachments)
await writer.WriteLineAsync(attachment.Url); 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)
{
foreach (var embed in embeds)
{ {
await writer.WriteLineAsync("{Embed}"); await writer.WriteLineAsync("{Embed}");
@ -142,6 +151,30 @@ namespace DiscordChatExporter.Core.Rendering
// Footer text // Footer text
if (!(embed.Footer?.Text).IsNullOrWhiteSpace()) if (!(embed.Footer?.Text).IsNullOrWhiteSpace())
await writer.WriteLineAsync(embed.Footer?.Text); await writer.WriteLineAsync(embed.Footer?.Text);
await writer.WriteLineAsync();
}
}
private async Task RenderReactionsAsync(TextWriter writer, IReadOnlyList<Reaction> reactions)
{
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})");
await writer.WriteAsync(" ");
}
await writer.WriteLineAsync();
await writer.WriteLineAsync();
}
} }
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)