mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-23 11:16:59 -04:00
parent
e1f83997aa
commit
539f57f455
7 changed files with 82 additions and 18 deletions
|
@ -21,6 +21,8 @@ namespace DiscordChatExporter.Core.Rendering.Formatters
|
|||
private readonly Template _messageGroupTemplate;
|
||||
private readonly Template _postambleTemplate;
|
||||
|
||||
private long _messageCount;
|
||||
|
||||
public HtmlMessageWriter(TextWriter writer, RenderContext context, string themeName)
|
||||
: base(writer, context)
|
||||
{
|
||||
|
@ -111,6 +113,9 @@ namespace DiscordChatExporter.Core.Rendering.Formatters
|
|||
_messageGroupBuffer.Clear();
|
||||
_messageGroupBuffer.Add(message);
|
||||
}
|
||||
|
||||
// Increment message count
|
||||
_messageCount++;
|
||||
}
|
||||
|
||||
public override async Task WritePostambleAsync()
|
||||
|
@ -119,7 +124,11 @@ namespace DiscordChatExporter.Core.Rendering.Formatters
|
|||
if (_messageGroupBuffer.Any())
|
||||
await RenderCurrentMessageGroupAsync();
|
||||
|
||||
var templateContext = CreateTemplateContext();
|
||||
var templateContext = CreateTemplateContext(new Dictionary<string, object>
|
||||
{
|
||||
["MessageCount"] = _messageCount
|
||||
});
|
||||
|
||||
await templateContext.EvaluateAsync(_postambleTemplate.Page);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ namespace DiscordChatExporter.Core.Rendering.Formatters
|
|||
{
|
||||
public class PlainTextMessageWriter : MessageWriterBase
|
||||
{
|
||||
private long _messageCount;
|
||||
|
||||
public PlainTextMessageWriter(TextWriter writer, RenderContext context)
|
||||
: base(writer, context)
|
||||
{
|
||||
|
@ -21,6 +23,14 @@ namespace DiscordChatExporter.Core.Rendering.Formatters
|
|||
{
|
||||
await Writer.WriteLineAsync(PlainTextRenderingLogic.FormatMessage(Context, message));
|
||||
await Writer.WriteLineAsync();
|
||||
|
||||
_messageCount++;
|
||||
}
|
||||
|
||||
public override async Task WritePostambleAsync()
|
||||
{
|
||||
await Writer.WriteLineAsync();
|
||||
await Writer.WriteLineAsync(PlainTextRenderingLogic.FormatPostamble(_messageCount));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ namespace DiscordChatExporter.Core.Rendering.Logic
|
|||
{
|
||||
var buffer = new StringBuilder();
|
||||
|
||||
buffer.AppendLine('='.Repeat(62));
|
||||
buffer.Append('=', 62).AppendLine();
|
||||
buffer.AppendLine($"Guild: {context.Guild.Name}");
|
||||
buffer.AppendLine($"Channel: {context.Channel.Name}");
|
||||
|
||||
|
@ -31,7 +31,18 @@ namespace DiscordChatExporter.Core.Rendering.Logic
|
|||
if (context.Before != null)
|
||||
buffer.AppendLine($"Before: {FormatDate(context.Before.Value, context.DateFormat)}");
|
||||
|
||||
buffer.AppendLine('='.Repeat(62));
|
||||
buffer.Append('=', 62).AppendLine();
|
||||
|
||||
return buffer.ToString();
|
||||
}
|
||||
|
||||
public static string FormatPostamble(long messageCount)
|
||||
{
|
||||
var buffer = new StringBuilder();
|
||||
|
||||
buffer.Append('=', 62).AppendLine();
|
||||
buffer.AppendLine($"Exported {messageCount:N0} message(s)");
|
||||
buffer.Append('=', 62).AppendLine();
|
||||
|
||||
return buffer.ToString();
|
||||
}
|
||||
|
@ -121,7 +132,7 @@ namespace DiscordChatExporter.Core.Rendering.Logic
|
|||
return FormatMarkdown(context, message.Content);
|
||||
}
|
||||
|
||||
public static string FormatAttachments(RenderContext context, IReadOnlyList<Attachment> attachments)
|
||||
public static string FormatAttachments(IReadOnlyList<Attachment> attachments)
|
||||
{
|
||||
if (!attachments.Any())
|
||||
return "";
|
||||
|
@ -193,7 +204,7 @@ namespace DiscordChatExporter.Core.Rendering.Logic
|
|||
return buffer.ToString();
|
||||
}
|
||||
|
||||
public static string FormatReactions(RenderContext context, IReadOnlyList<Reaction> reactions)
|
||||
public static string FormatReactions(IReadOnlyList<Reaction> reactions)
|
||||
{
|
||||
if (!reactions.Any())
|
||||
return "";
|
||||
|
@ -225,9 +236,9 @@ namespace DiscordChatExporter.Core.Rendering.Logic
|
|||
.AppendLine(FormatMessageHeader(context, message))
|
||||
.AppendLineIfNotEmpty(FormatMessageContent(context, message))
|
||||
.AppendLine()
|
||||
.AppendLineIfNotEmpty(FormatAttachments(context, message.Attachments))
|
||||
.AppendLineIfNotEmpty(FormatAttachments(message.Attachments))
|
||||
.AppendLineIfNotEmpty(FormatEmbeds(context, message.Embeds))
|
||||
.AppendLineIfNotEmpty(FormatReactions(context, message.Reactions));
|
||||
.AppendLineIfNotEmpty(FormatReactions(message.Reactions));
|
||||
|
||||
return buffer.Trim().ToString();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* === GENERAL === */
|
||||
/* === General === */
|
||||
|
||||
@font-face {
|
||||
font-family: Whitney;
|
||||
|
@ -102,7 +102,7 @@ img {
|
|||
height: 2rem;
|
||||
}
|
||||
|
||||
/* === INFO === */
|
||||
/* === Preamble === */
|
||||
|
||||
.info {
|
||||
display: flex;
|
||||
|
@ -144,11 +144,10 @@ img {
|
|||
margin-top: 2px;
|
||||
}
|
||||
|
||||
/* === CHATLOG === */
|
||||
/* === Chatlog === */
|
||||
|
||||
.chatlog {
|
||||
max-width: 100%;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.chatlog__message-group {
|
||||
|
@ -365,4 +364,12 @@ img {
|
|||
line-height: 1.3;
|
||||
position: relative;
|
||||
top: -.2em;
|
||||
}
|
||||
|
||||
/* Postamble */
|
||||
|
||||
.postamble {
|
||||
margin: 24px 5px 10px 5px;
|
||||
padding: 16px;
|
||||
border-top: 1px solid;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
/* === GENERAL === */
|
||||
/* === General === */
|
||||
|
||||
body {
|
||||
background-color: #36393e;
|
||||
|
@ -30,7 +30,7 @@ a {
|
|||
color: #7289da;
|
||||
}
|
||||
|
||||
/* === INFO === */
|
||||
/* === Preamble === */
|
||||
|
||||
.info__guild-name {
|
||||
color: #ffffff;
|
||||
|
@ -44,7 +44,7 @@ a {
|
|||
color: #ffffff;
|
||||
}
|
||||
|
||||
/* === CHATLOG === */
|
||||
/* === Chatlog === */
|
||||
|
||||
.chatlog__message-group {
|
||||
border-color: rgba(255, 255, 255, 0.1);
|
||||
|
@ -113,4 +113,14 @@ a {
|
|||
|
||||
.chatlog__reaction-count {
|
||||
color: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
/* === Postamble === */
|
||||
|
||||
.postamble {
|
||||
border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.postamble__info {
|
||||
color: #ffffff;
|
||||
}
|
|
@ -48,7 +48,7 @@
|
|||
</head>
|
||||
<body>
|
||||
|
||||
{{~ # Info ~}}
|
||||
{{~ # Preamble ~}}
|
||||
<div class="info">
|
||||
<div class="info__guild-icon-container">
|
||||
<img class="info__guild-icon" src="{{ Context.Guild.IconUrl }}" />
|
||||
|
@ -80,5 +80,12 @@
|
|||
{{~ %SPLIT% ~}}
|
||||
</div>
|
||||
|
||||
{{~ # Postamble ~}}
|
||||
<div class="postamble">
|
||||
<div class="postamble__info">
|
||||
Exported {{ MessageCount | object.format "N0" }} message(s)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -1,4 +1,4 @@
|
|||
/* === GENERAL === */
|
||||
/* === General === */
|
||||
|
||||
body {
|
||||
background-color: #ffffff;
|
||||
|
@ -32,7 +32,7 @@ a {
|
|||
color: #7289da;
|
||||
}
|
||||
|
||||
/* === INFO === */
|
||||
/* === Preamble === */
|
||||
|
||||
.info__guild-name {
|
||||
color: #2f3136;
|
||||
|
@ -46,7 +46,7 @@ a {
|
|||
color: #2f3136;
|
||||
}
|
||||
|
||||
/* === CHATLOG === */
|
||||
/* === Chatlog === */
|
||||
|
||||
.chatlog__message-group {
|
||||
border-color: #eceeef;
|
||||
|
@ -116,4 +116,14 @@ a {
|
|||
|
||||
.chatlog__reaction-count {
|
||||
color: #747f8d;
|
||||
}
|
||||
|
||||
/* === Postamble === */
|
||||
|
||||
.postamble {
|
||||
border-color: #eceeef;
|
||||
}
|
||||
|
||||
.postamble__info {
|
||||
color: #2f3136;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue