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