mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-07-07 14:44:39 +02:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eececb6701 | |||
| d3adf19500 | |||
| a01835efb6 | |||
| 1d39fe9c53 | |||
| 9f6090b3af | |||
| 9fa40dca00 | |||
| 8a4f306012 | |||
| 37be80e9e1 | |||
| 1475ffaf0e | |||
| aa50dd6dc7 | |||
| 539f57f455 | |||
| e1f83997aa | |||
| 26d713a17c | |||
| 5c2e725739 | |||
| bf56902134 | |||
| b4df267372 | |||
| 4ebc681327 | |||
| 5cb6adf19e | |||
| cec8409ac4 | |||
| 3af9421304 | |||
| cc6f930dc6 | |||
| e6aac3cdb9 |
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"xamlstyler.console": {
|
||||
"version": "3.2001.0",
|
||||
"commands": [
|
||||
"xstyler"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,12 +34,14 @@ jobs:
|
||||
|
||||
- name: Create release
|
||||
id: create_release
|
||||
uses: actions/create-release@v1.0.0
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ github.ref }}
|
||||
release_name: ${{ github.ref }}
|
||||
body: |
|
||||
[Changelog](https://github.com/Tyrrrz/DiscordChatExporter/blob/master/Changelog.md)
|
||||
draft: false
|
||||
prerelease: false
|
||||
|
||||
|
||||
+16
-1
@@ -1,10 +1,25 @@
|
||||
### v2.18 (04-Feb-2020)
|
||||
|
||||
- Added JSON export format. It's a structured data format which is easy to parse. If you're using DiscordChatExporter to export chat logs for further ingestion by another tool, this is most likely the format you will want to use.
|
||||
- [GUI] You can now quickly jump to a specific channel in a list. For example, if you want to jump to a channel named "General", you can simply press the 'g' key in the channel list view. You can also press 'g', 'e' and 'n' in quick succession which will jump to the next channel that starts with "gen". This mechanic is consistent with other Windows applications.
|
||||
- [CLI] Improved help text screen.
|
||||
|
||||
### v2.17 (12-Jan-2020)
|
||||
|
||||
- Fixed an issue where an empty file was produced when exporting a channel with no messages (for specified period). With the new behavior, no file will be created and instead a message will be shown to the user informing of the failure.
|
||||
- [HTML/TXT] Added message count to the bottom of the file. This number shows how many messages were exported as part of the current file. Prior to 2.16 this number was present along with the rest of the metadata at the top, then removed due to changes in the exporter, and now brought back at the end of the file instead.
|
||||
- [HTML] Fixed an issue where some emojis were not properly rendered.
|
||||
- [GUI] Added a setting that lets you configure whether to remember the last used token. Previously it was the default behavior, but now you can disable it if you don't want the token persisted on your system.
|
||||
|
||||
### v2.16 (08-Dec-2019)
|
||||
|
||||
- Migrated from .NET Framework to .NET Core. To run this and future versions of DiscordChatExporter you will need [.NET Core runtime for desktop apps](https://dotnet.microsoft.com/download/dotnet-core/3.1/runtime) (for GUI/CLI version on Windows) or [.NET Core base runtime](https://dotnet.microsoft.com/download/dotnet-core/3.1) (for CLI version on Windows, Linux or macOS).
|
||||
- Reworked the exporter engine to render output using streaming data source. This means that only a very small portion of messages are cached in memory when exporting. In other words, you are only limited by storage space and not how much RAM you have, so you can now export terrabytes of chat logs without hitting out of memory exceptions. I still recommend using partitions if you're exporting very large chat logs (250k+ messages) to HTML, unless you want your computer to catch fire when you try to open the export in browser.
|
||||
- Reworked the exporter engine to render output using streaming data source. This means that only a very small portion of messages are cached in memory when exporting. In other words, you are only limited by storage space and not how much RAM you have, so you can now export terabytes of chat logs without hitting out of memory exceptions. I still recommend using partitions if you're exporting very large chat logs (250k+ messages) to HTML, unless you want your computer to catch fire when you try to open the export in browser.
|
||||
- Changed how partitioned files are named, due to the fact that total number of partitions is no longer known ahead of time.
|
||||
- Added a warning about automating user accounts to the usage guide in both GUI and CLI versions.
|
||||
- Added support for announcement (news) channels. You will now be able to see them in the list and export them.
|
||||
- Fixed various issues that resulted in exceptions during export process.
|
||||
- [HTML/TXT] Removed message count from the metadata. Due to the fact that the messages are exported as they are streamed, total number of messages is not known ahead of time.
|
||||
- [HTML] Changed default color of the embed color pill to match the theme.
|
||||
- [HTML] Changed emoji parser to be less greedy. As a result it should match fewer character sequences that look like emojis but really aren't, but on the other hand it might miss some actual emojis. This means that some standard emojis (i.e. not custom server emojis) may not look like in Discord. This is a compromise I'm willing to take because detecting emojis in text is really hard to get right and not worth it at all.
|
||||
- [HTML] Some other minor styling adjustments.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
using DiscordChatExporter.Core.Services;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands
|
||||
@@ -8,14 +8,14 @@ namespace DiscordChatExporter.Cli.Commands
|
||||
[Command("export", Description = "Export a channel.")]
|
||||
public class ExportChannelCommand : ExportCommandBase
|
||||
{
|
||||
[CommandOption("channel", 'c', IsRequired = true, Description= "Channel ID.")]
|
||||
public string ChannelId { get; set; }
|
||||
[CommandOption("channel", 'c', IsRequired = true, Description = "Channel ID.")]
|
||||
public string ChannelId { get; set; } = "";
|
||||
|
||||
public ExportChannelCommand(SettingsService settingsService, DataService dataService, ExportService exportService)
|
||||
: base(settingsService, dataService, exportService)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task ExecuteAsync(IConsole console) => await ExportAsync(console, ChannelId);
|
||||
public override async ValueTask ExecuteAsync(IConsole console) => await ExportAsync(console, ChannelId);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
using CliFx.Utilities;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
using DiscordChatExporter.Core.Services;
|
||||
@@ -19,7 +19,7 @@ namespace DiscordChatExporter.Cli.Commands
|
||||
public ExportFormat ExportFormat { get; set; } = ExportFormat.HtmlDark;
|
||||
|
||||
[CommandOption("output", 'o', Description = "Output file or directory path.")]
|
||||
public string? OutputPath { get; set; }
|
||||
public string OutputPath { get; set; } = Directory.GetCurrentDirectory();
|
||||
|
||||
[CommandOption("after", Description = "Limit to messages sent after this date.")]
|
||||
public DateTimeOffset? After { get; set; }
|
||||
@@ -40,7 +40,7 @@ namespace DiscordChatExporter.Cli.Commands
|
||||
ExportService = exportService;
|
||||
}
|
||||
|
||||
protected async Task ExportAsync(IConsole console, Guild guild, Channel channel)
|
||||
protected async ValueTask ExportAsync(IConsole console, Guild guild, Channel channel)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(DateFormat))
|
||||
SettingsService.DateFormat = DateFormat;
|
||||
@@ -48,23 +48,22 @@ namespace DiscordChatExporter.Cli.Commands
|
||||
console.Output.Write($"Exporting channel [{channel.Name}]... ");
|
||||
var progress = console.CreateProgressTicker();
|
||||
|
||||
var outputPath = OutputPath ?? Directory.GetCurrentDirectory();
|
||||
await ExportService.ExportChatLogAsync(GetToken(), guild, channel,
|
||||
outputPath, ExportFormat, PartitionLimit,
|
||||
await ExportService.ExportChatLogAsync(Token, guild, channel,
|
||||
OutputPath, ExportFormat, PartitionLimit,
|
||||
After, Before, progress);
|
||||
|
||||
console.Output.WriteLine();
|
||||
}
|
||||
|
||||
protected async Task ExportAsync(IConsole console, Channel channel)
|
||||
protected async ValueTask ExportAsync(IConsole console, Channel channel)
|
||||
{
|
||||
var guild = await DataService.GetGuildAsync(GetToken(), channel.GuildId);
|
||||
var guild = await DataService.GetGuildAsync(Token, channel.GuildId);
|
||||
await ExportAsync(console, guild, channel);
|
||||
}
|
||||
|
||||
protected async Task ExportAsync(IConsole console, string channelId)
|
||||
protected async ValueTask ExportAsync(IConsole console, string channelId)
|
||||
{
|
||||
var channel = await DataService.GetChannelAsync(GetToken(), channelId);
|
||||
var channel = await DataService.GetChannelAsync(Token, channelId);
|
||||
await ExportAsync(console, channel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
using DiscordChatExporter.Core.Models.Exceptions;
|
||||
using DiscordChatExporter.Core.Services;
|
||||
using DiscordChatExporter.Core.Services.Exceptions;
|
||||
|
||||
@@ -16,10 +17,10 @@ namespace DiscordChatExporter.Cli.Commands
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task ExecuteAsync(IConsole console)
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
// Get channels
|
||||
var channels = await DataService.GetDirectMessageChannelsAsync(GetToken());
|
||||
var channels = await DataService.GetDirectMessageChannelsAsync(Token);
|
||||
|
||||
// Order channels
|
||||
channels = channels.OrderBy(c => c.Name).ToArray();
|
||||
@@ -39,6 +40,10 @@ namespace DiscordChatExporter.Cli.Commands
|
||||
{
|
||||
console.Error.WriteLine("This channel doesn't exist.");
|
||||
}
|
||||
catch (DomainException ex)
|
||||
{
|
||||
console.Error.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
using DiscordChatExporter.Core.Models.Exceptions;
|
||||
using DiscordChatExporter.Core.Services;
|
||||
using DiscordChatExporter.Core.Services.Exceptions;
|
||||
|
||||
@@ -13,17 +14,17 @@ namespace DiscordChatExporter.Cli.Commands
|
||||
public class ExportGuildCommand : ExportCommandBase
|
||||
{
|
||||
[CommandOption("guild", 'g', IsRequired = true, Description = "Guild ID.")]
|
||||
public string GuildId { get; set; }
|
||||
public string GuildId { get; set; } = "";
|
||||
|
||||
public ExportGuildCommand(SettingsService settingsService, DataService dataService, ExportService exportService)
|
||||
: base(settingsService, dataService, exportService)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task ExecuteAsync(IConsole console)
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
// Get channels
|
||||
var channels = await DataService.GetGuildChannelsAsync(GetToken(), GuildId);
|
||||
var channels = await DataService.GetGuildChannelsAsync(Token, GuildId);
|
||||
|
||||
// Filter and order channels
|
||||
channels = channels.Where(c => c.Type.IsExportable()).OrderBy(c => c.Name).ToArray();
|
||||
@@ -43,6 +44,10 @@ namespace DiscordChatExporter.Cli.Commands
|
||||
{
|
||||
console.Error.WriteLine("This channel doesn't exist.");
|
||||
}
|
||||
catch (DomainException ex)
|
||||
{
|
||||
console.Error.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
using DiscordChatExporter.Core.Services;
|
||||
|
||||
@@ -11,17 +11,17 @@ namespace DiscordChatExporter.Cli.Commands
|
||||
public class GetChannelsCommand : TokenCommandBase
|
||||
{
|
||||
[CommandOption("guild", 'g', IsRequired = true, Description = "Guild ID.")]
|
||||
public string GuildId { get; set; }
|
||||
public string GuildId { get; set; } = "";
|
||||
|
||||
public GetChannelsCommand(DataService dataService)
|
||||
: base(dataService)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task ExecuteAsync(IConsole console)
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
// Get channels
|
||||
var channels = await DataService.GetGuildChannelsAsync(GetToken(), GuildId);
|
||||
var channels = await DataService.GetGuildChannelsAsync(Token, GuildId);
|
||||
|
||||
// Filter and order channels
|
||||
channels = channels.Where(c => c.Type.IsExportable()).OrderBy(c => c.Name).ToArray();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
using DiscordChatExporter.Core.Services;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands
|
||||
@@ -14,10 +14,10 @@ namespace DiscordChatExporter.Cli.Commands
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task ExecuteAsync(IConsole console)
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
// Get channels
|
||||
var channels = await DataService.GetDirectMessageChannelsAsync(GetToken());
|
||||
var channels = await DataService.GetDirectMessageChannelsAsync(Token);
|
||||
|
||||
// Order channels
|
||||
channels = channels.OrderBy(c => c.Name).ToArray();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
using DiscordChatExporter.Core.Services;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands
|
||||
@@ -14,10 +14,10 @@ namespace DiscordChatExporter.Cli.Commands
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task ExecuteAsync(IConsole console)
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
// Get guilds
|
||||
var guilds = await DataService.GetUserGuildsAsync(GetToken());
|
||||
var guilds = await DataService.GetUserGuildsAsync(Token);
|
||||
|
||||
// Order guilds
|
||||
guilds = guilds.OrderBy(g => g.Name).ToArray();
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands
|
||||
{
|
||||
[Command("guide", Description = "Explains how to obtain token, guild or channel ID.")]
|
||||
public class GuideCommand : ICommand
|
||||
{
|
||||
public Task ExecuteAsync(IConsole console)
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.WithForegroundColor(ConsoleColor.White, () => console.Output.WriteLine("To get user token:"));
|
||||
console.Output.WriteLine(" 1. Open Discord");
|
||||
@@ -48,7 +47,7 @@ namespace DiscordChatExporter.Cli.Commands
|
||||
console.Output.WriteLine("If you still have unanswered questions, check out the wiki:");
|
||||
console.Output.WriteLine("https://github.com/Tyrrrz/DiscordChatExporter/wiki");
|
||||
|
||||
return Task.CompletedTask;
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
using DiscordChatExporter.Core.Services;
|
||||
|
||||
@@ -12,18 +11,18 @@ namespace DiscordChatExporter.Cli.Commands
|
||||
protected DataService DataService { get; }
|
||||
|
||||
[CommandOption("token", 't', IsRequired = true, Description = "Authorization token.")]
|
||||
public string TokenValue { get; set; }
|
||||
public string TokenValue { get; set; } = "";
|
||||
|
||||
[CommandOption("bot", 'b', Description = "Whether this authorization token belongs to a bot.")]
|
||||
public bool IsBotToken { get; set; }
|
||||
|
||||
protected AuthToken Token => new AuthToken(IsBotToken ? AuthTokenType.Bot : AuthTokenType.User, TokenValue);
|
||||
|
||||
protected TokenCommandBase(DataService dataService)
|
||||
{
|
||||
DataService = dataService;
|
||||
}
|
||||
|
||||
protected AuthToken GetToken() => new AuthToken(IsBotToken ? AuthTokenType.Bot : AuthTokenType.User, TokenValue);
|
||||
|
||||
public abstract Task ExecuteAsync(IConsole console);
|
||||
public abstract ValueTask ExecuteAsync(IConsole console);
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CliFx" Version="0.0.8" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.0" />
|
||||
<PackageReference Include="CliFx" Version="1.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.1" />
|
||||
<PackageReference Include="Tyrrrz.Extensions" Version="1.6.5" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -30,13 +30,13 @@ namespace DiscordChatExporter.Cli
|
||||
return services.BuildServiceProvider();
|
||||
}
|
||||
|
||||
public static Task<int> Main(string[] args)
|
||||
public static async Task<int> Main(string[] args)
|
||||
{
|
||||
var serviceProvider = ConfigureServices();
|
||||
|
||||
return new CliApplicationBuilder()
|
||||
return await new CliApplicationBuilder()
|
||||
.AddCommandsFromThisAssembly()
|
||||
.UseCommandFactory(schema => (ICommand) serviceProvider.GetService(schema.Type))
|
||||
.UseTypeActivator(serviceProvider.GetService)
|
||||
.Build()
|
||||
.RunAsync(args);
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace DiscordChatExporter.Core.Markdown.Nodes
|
||||
namespace DiscordChatExporter.Core.Markdown.Ast
|
||||
{
|
||||
public class EmojiNode : Node
|
||||
{
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DiscordChatExporter.Core.Markdown.Nodes
|
||||
namespace DiscordChatExporter.Core.Markdown.Ast
|
||||
{
|
||||
public class FormattedNode : Node
|
||||
{
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace DiscordChatExporter.Core.Markdown.Nodes
|
||||
namespace DiscordChatExporter.Core.Markdown.Ast
|
||||
{
|
||||
public class InlineCodeBlockNode : Node
|
||||
{
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace DiscordChatExporter.Core.Markdown.Nodes
|
||||
namespace DiscordChatExporter.Core.Markdown.Ast
|
||||
{
|
||||
public class LinkNode : Node
|
||||
{
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace DiscordChatExporter.Core.Markdown.Nodes
|
||||
namespace DiscordChatExporter.Core.Markdown.Ast
|
||||
{
|
||||
public class MentionNode : Node
|
||||
{
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace DiscordChatExporter.Core.Markdown.Nodes
|
||||
namespace DiscordChatExporter.Core.Markdown.Ast
|
||||
{
|
||||
public enum MentionType
|
||||
{
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace DiscordChatExporter.Core.Markdown.Nodes
|
||||
namespace DiscordChatExporter.Core.Markdown.Ast
|
||||
{
|
||||
public class MultiLineCodeBlockNode : Node
|
||||
{
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace DiscordChatExporter.Core.Markdown.Ast
|
||||
{
|
||||
public abstract class Node
|
||||
{
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace DiscordChatExporter.Core.Markdown.Nodes
|
||||
namespace DiscordChatExporter.Core.Markdown.Ast
|
||||
{
|
||||
public enum TextFormatting
|
||||
{
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace DiscordChatExporter.Core.Markdown.Nodes
|
||||
namespace DiscordChatExporter.Core.Markdown.Ast
|
||||
{
|
||||
public class TextNode : Node
|
||||
{
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using DiscordChatExporter.Core.Markdown.Ast;
|
||||
using DiscordChatExporter.Core.Markdown.Internal;
|
||||
using DiscordChatExporter.Core.Markdown.Nodes;
|
||||
|
||||
namespace DiscordChatExporter.Core.Markdown
|
||||
{
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace DiscordChatExporter.Core.Markdown.Nodes
|
||||
{
|
||||
public abstract class Node
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Tyrrrz.Extensions;
|
||||
|
||||
namespace DiscordChatExporter.Core.Models
|
||||
@@ -28,14 +29,21 @@ namespace DiscordChatExporter.Core.Models
|
||||
|
||||
public partial class Emoji
|
||||
{
|
||||
private static IEnumerable<int> GetCodePoints(string emoji)
|
||||
private static IEnumerable<Rune> GetRunes(string emoji)
|
||||
{
|
||||
for (var i = 0; i < emoji.Length; i += char.IsHighSurrogate(emoji[i]) ? 2 : 1)
|
||||
yield return char.ConvertToUtf32(emoji, i);
|
||||
var lastIndex = 0;
|
||||
while (lastIndex < emoji.Length && Rune.TryGetRuneAt(emoji, lastIndex, out var rune))
|
||||
{
|
||||
// Skip variant selector rune
|
||||
if (rune.Value != 0xfe0f)
|
||||
yield return rune;
|
||||
|
||||
lastIndex += rune.Utf16SequenceLength;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetTwemojiName(string emoji) =>
|
||||
GetCodePoints(emoji).Select(i => i.ToString("x")).JoinToString("-");
|
||||
private static string GetTwemojiName(IEnumerable<Rune> runes) =>
|
||||
runes.Select(r => r.Value.ToString("x")).JoinToString("-");
|
||||
|
||||
public static string GetImageUrl(string? id, string name, bool isAnimated)
|
||||
{
|
||||
@@ -50,9 +58,17 @@ namespace DiscordChatExporter.Core.Models
|
||||
return $"https://cdn.discordapp.com/emojis/{id}.png";
|
||||
}
|
||||
|
||||
// Standard unicode emoji (via twemoji)
|
||||
var twemojiName = GetTwemojiName(name);
|
||||
return $"https://twemoji.maxcdn.com/2/72x72/{twemojiName}.png";
|
||||
// Standard unicode emoji
|
||||
var emojiRunes = GetRunes(name).ToArray();
|
||||
if (emojiRunes.Any())
|
||||
{
|
||||
// Get corresponding Twemoji image
|
||||
var twemojiName = GetTwemojiName(emojiRunes);
|
||||
return $"https://twemoji.maxcdn.com/2/72x72/{twemojiName}.png";
|
||||
}
|
||||
|
||||
// Fallback in case of failure
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace DiscordChatExporter.Core.Models.Exceptions
|
||||
{
|
||||
public class DomainException : Exception
|
||||
{
|
||||
public DomainException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
PlainText,
|
||||
HtmlDark,
|
||||
HtmlLight,
|
||||
Csv
|
||||
Csv,
|
||||
Json
|
||||
}
|
||||
}
|
||||
@@ -18,16 +18,18 @@ namespace DiscordChatExporter.Core.Models
|
||||
ExportFormat.HtmlDark => "html",
|
||||
ExportFormat.HtmlLight => "html",
|
||||
ExportFormat.Csv => "csv",
|
||||
ExportFormat.Json => "json",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(format))
|
||||
};
|
||||
|
||||
public static string GetDisplayName(this ExportFormat format) =>
|
||||
format switch
|
||||
{
|
||||
ExportFormat.PlainText => "Plain Text",
|
||||
ExportFormat.PlainText => "TXT",
|
||||
ExportFormat.HtmlDark => "HTML (Dark)",
|
||||
ExportFormat.HtmlLight => "HTML (Light)",
|
||||
ExportFormat.Csv => "Comma Separated Values (CSV)",
|
||||
ExportFormat.Csv => "CSV",
|
||||
ExportFormat.Json => "JSON",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(format))
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
using DiscordChatExporter.Core.Rendering.Logic;
|
||||
|
||||
namespace DiscordChatExporter.Core.Rendering
|
||||
{
|
||||
public class CsvMessageRenderer : MessageRendererBase
|
||||
{
|
||||
private bool _isHeaderRendered;
|
||||
|
||||
public CsvMessageRenderer(string filePath, RenderContext context)
|
||||
: base(filePath, context)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task RenderMessageAsync(Message message)
|
||||
{
|
||||
// Render header if it's the first entry
|
||||
if (!_isHeaderRendered)
|
||||
{
|
||||
await Writer.WriteLineAsync(CsvRenderingLogic.FormatHeader(Context));
|
||||
_isHeaderRendered = true;
|
||||
}
|
||||
|
||||
await Writer.WriteLineAsync(CsvRenderingLogic.FormatMessage(Context, message));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Scriban" Version="2.1.0" />
|
||||
<PackageReference Include="Scriban" Version="2.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
using DiscordChatExporter.Core.Rendering.Logic;
|
||||
|
||||
namespace DiscordChatExporter.Core.Rendering.Formatters
|
||||
{
|
||||
public class CsvMessageWriter : MessageWriterBase
|
||||
{
|
||||
private readonly TextWriter _writer;
|
||||
|
||||
public CsvMessageWriter(Stream stream, RenderContext context)
|
||||
: base(stream, context)
|
||||
{
|
||||
_writer = new StreamWriter(stream);
|
||||
}
|
||||
|
||||
public override async Task WritePreambleAsync()
|
||||
{
|
||||
await _writer.WriteLineAsync(CsvRenderingLogic.FormatHeader(Context));
|
||||
}
|
||||
|
||||
public override async Task WriteMessageAsync(Message message)
|
||||
{
|
||||
await _writer.WriteLineAsync(CsvRenderingLogic.FormatMessage(Context, message));
|
||||
}
|
||||
|
||||
public override async ValueTask DisposeAsync()
|
||||
{
|
||||
await _writer.DisposeAsync();
|
||||
await base.DisposeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
+37
-41
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
@@ -9,27 +10,29 @@ using Scriban;
|
||||
using Scriban.Runtime;
|
||||
using Tyrrrz.Extensions;
|
||||
|
||||
namespace DiscordChatExporter.Core.Rendering
|
||||
namespace DiscordChatExporter.Core.Rendering.Formatters
|
||||
{
|
||||
public partial class HtmlMessageRenderer : MessageRendererBase
|
||||
public partial class HtmlMessageWriter : MessageWriterBase
|
||||
{
|
||||
private readonly TextWriter _writer;
|
||||
private readonly string _themeName;
|
||||
private readonly List<Message> _messageGroupBuffer = new List<Message>();
|
||||
|
||||
private readonly Template _leadingBlockTemplate;
|
||||
private readonly Template _preambleTemplate;
|
||||
private readonly Template _messageGroupTemplate;
|
||||
private readonly Template _trailingBlockTemplate;
|
||||
private readonly Template _postambleTemplate;
|
||||
|
||||
private bool _isLeadingBlockRendered;
|
||||
private long _messageCount;
|
||||
|
||||
public HtmlMessageRenderer(string filePath, RenderContext context, string themeName)
|
||||
: base(filePath, context)
|
||||
public HtmlMessageWriter(Stream stream, RenderContext context, string themeName)
|
||||
: base(stream, context)
|
||||
{
|
||||
_writer = new StreamWriter(stream);
|
||||
_themeName = themeName;
|
||||
|
||||
_leadingBlockTemplate = Template.Parse(GetLeadingBlockTemplateCode());
|
||||
_preambleTemplate = Template.Parse(GetPreambleTemplateCode());
|
||||
_messageGroupTemplate = Template.Parse(GetMessageGroupTemplateCode());
|
||||
_trailingBlockTemplate = Template.Parse(GetTrailingBlockTemplateCode());
|
||||
_postambleTemplate = Template.Parse(GetPostambleTemplateCode());
|
||||
}
|
||||
|
||||
private MessageGroup GetCurrentMessageGroup()
|
||||
@@ -76,17 +79,11 @@ namespace DiscordChatExporter.Core.Rendering
|
||||
templateContext.PushGlobal(scriptObject);
|
||||
|
||||
// Push output
|
||||
templateContext.PushOutput(new TextWriterOutput(Writer));
|
||||
templateContext.PushOutput(new TextWriterOutput(_writer));
|
||||
|
||||
return templateContext;
|
||||
}
|
||||
|
||||
private async Task RenderLeadingBlockAsync()
|
||||
{
|
||||
var templateContext = CreateTemplateContext();
|
||||
await templateContext.EvaluateAsync(_leadingBlockTemplate.Page);
|
||||
}
|
||||
|
||||
private async Task RenderCurrentMessageGroupAsync()
|
||||
{
|
||||
var templateContext = CreateTemplateContext(new Dictionary<string, object>
|
||||
@@ -97,21 +94,14 @@ namespace DiscordChatExporter.Core.Rendering
|
||||
await templateContext.EvaluateAsync(_messageGroupTemplate.Page);
|
||||
}
|
||||
|
||||
private async Task RenderTrailingBlockAsync()
|
||||
public override async Task WritePreambleAsync()
|
||||
{
|
||||
var templateContext = CreateTemplateContext();
|
||||
await templateContext.EvaluateAsync(_trailingBlockTemplate.Page);
|
||||
await templateContext.EvaluateAsync(_preambleTemplate.Page);
|
||||
}
|
||||
|
||||
public override async Task RenderMessageAsync(Message message)
|
||||
public override async Task WriteMessageAsync(Message message)
|
||||
{
|
||||
// Render leading block if it's the first entry
|
||||
if (!_isLeadingBlockRendered)
|
||||
{
|
||||
await RenderLeadingBlockAsync();
|
||||
_isLeadingBlockRendered = true;
|
||||
}
|
||||
|
||||
// If message group is empty or the given message can be grouped, buffer the given message
|
||||
if (!_messageGroupBuffer.Any() || HtmlRenderingLogic.CanBeGrouped(_messageGroupBuffer.Last(), message))
|
||||
{
|
||||
@@ -125,27 +115,33 @@ namespace DiscordChatExporter.Core.Rendering
|
||||
_messageGroupBuffer.Clear();
|
||||
_messageGroupBuffer.Add(message);
|
||||
}
|
||||
|
||||
// Increment message count
|
||||
_messageCount++;
|
||||
}
|
||||
|
||||
public override async ValueTask DisposeAsync()
|
||||
public override async Task WritePostambleAsync()
|
||||
{
|
||||
// Leading block (can happen if no message were rendered)
|
||||
if (!_isLeadingBlockRendered)
|
||||
await RenderLeadingBlockAsync();
|
||||
|
||||
// Flush current message group
|
||||
if (_messageGroupBuffer.Any())
|
||||
await RenderCurrentMessageGroupAsync();
|
||||
|
||||
// Trailing block
|
||||
await RenderTrailingBlockAsync();
|
||||
var templateContext = CreateTemplateContext(new Dictionary<string, object>
|
||||
{
|
||||
["MessageCount"] = _messageCount
|
||||
});
|
||||
|
||||
// Dispose stream
|
||||
await templateContext.EvaluateAsync(_postambleTemplate.Page);
|
||||
}
|
||||
|
||||
public override async ValueTask DisposeAsync()
|
||||
{
|
||||
await _writer.DisposeAsync();
|
||||
await base.DisposeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public partial class HtmlMessageRenderer
|
||||
public partial class HtmlMessageWriter
|
||||
{
|
||||
private static readonly Assembly ResourcesAssembly = typeof(HtmlRenderingLogic).Assembly;
|
||||
private static readonly string ResourcesNamespace = $"{ResourcesAssembly.GetName().Name}.Resources";
|
||||
@@ -158,18 +154,18 @@ namespace DiscordChatExporter.Core.Rendering
|
||||
ResourcesAssembly
|
||||
.GetManifestResourceString($"{ResourcesNamespace}.Html{themeName}.css");
|
||||
|
||||
private static string GetLeadingBlockTemplateCode() =>
|
||||
private static string GetPreambleTemplateCode() =>
|
||||
ResourcesAssembly
|
||||
.GetManifestResourceString($"{ResourcesNamespace}.HtmlLayoutTemplate.html")
|
||||
.SubstringUntil("{{~ %SPLIT% ~}}");
|
||||
|
||||
private static string GetTrailingBlockTemplateCode() =>
|
||||
ResourcesAssembly
|
||||
.GetManifestResourceString($"{ResourcesNamespace}.HtmlLayoutTemplate.html")
|
||||
.SubstringAfter("{{~ %SPLIT% ~}}");
|
||||
|
||||
private static string GetMessageGroupTemplateCode() =>
|
||||
ResourcesAssembly
|
||||
.GetManifestResourceString($"{ResourcesNamespace}.HtmlMessageGroupTemplate.html");
|
||||
|
||||
private static string GetPostambleTemplateCode() =>
|
||||
ResourcesAssembly
|
||||
.GetManifestResourceString($"{ResourcesNamespace}.HtmlLayoutTemplate.html")
|
||||
.SubstringAfter("{{~ %SPLIT% ~}}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
using DiscordChatExporter.Core.Rendering.Internal;
|
||||
using DiscordChatExporter.Core.Rendering.Logic;
|
||||
|
||||
namespace DiscordChatExporter.Core.Rendering.Formatters
|
||||
{
|
||||
public class JsonMessageWriter : MessageWriterBase
|
||||
{
|
||||
private readonly Utf8JsonWriter _writer;
|
||||
|
||||
private long _messageCount;
|
||||
|
||||
public JsonMessageWriter(Stream stream, RenderContext context)
|
||||
: base(stream, context)
|
||||
{
|
||||
_writer = new Utf8JsonWriter(stream, new JsonWriterOptions
|
||||
{
|
||||
Indented = true
|
||||
});
|
||||
}
|
||||
|
||||
public override async Task WritePreambleAsync()
|
||||
{
|
||||
// Root object (start)
|
||||
_writer.WriteStartObject();
|
||||
|
||||
// Guild
|
||||
_writer.WriteStartObject("guild");
|
||||
_writer.WriteString("id", Context.Guild.Id);
|
||||
_writer.WriteString("name", Context.Guild.Name);
|
||||
_writer.WriteString("iconUrl", Context.Guild.IconUrl);
|
||||
_writer.WriteEndObject();
|
||||
|
||||
// Channel
|
||||
_writer.WriteStartObject("channel");
|
||||
_writer.WriteString("id", Context.Channel.Id);
|
||||
_writer.WriteString("type", Context.Channel.Type.ToString());
|
||||
_writer.WriteString("name", Context.Channel.Name);
|
||||
_writer.WriteString("topic", Context.Channel.Topic);
|
||||
_writer.WriteEndObject();
|
||||
|
||||
// Date range
|
||||
_writer.WriteStartObject("dateRange");
|
||||
_writer.WriteString("after", Context.After);
|
||||
_writer.WriteString("before", Context.Before);
|
||||
_writer.WriteEndObject();
|
||||
|
||||
// Message array (start)
|
||||
_writer.WriteStartArray("messages");
|
||||
|
||||
await _writer.FlushAsync();
|
||||
}
|
||||
|
||||
public override async Task WriteMessageAsync(Message message)
|
||||
{
|
||||
_writer.WriteStartObject();
|
||||
|
||||
// Metadata
|
||||
_writer.WriteString("id", message.Id);
|
||||
_writer.WriteString("type", message.Type.ToString());
|
||||
_writer.WriteString("timestamp", message.Timestamp);
|
||||
_writer.WriteString("timestampEdited", message.EditedTimestamp);
|
||||
_writer.WriteBoolean("isPinned", message.IsPinned);
|
||||
|
||||
// Content
|
||||
var content = PlainTextRenderingLogic.FormatMessageContent(Context, message);
|
||||
_writer.WriteString("content", content);
|
||||
|
||||
// Author
|
||||
_writer.WriteStartObject("author");
|
||||
_writer.WriteString("id", message.Author.Id);
|
||||
_writer.WriteString("name", message.Author.Name);
|
||||
_writer.WriteString("discriminator", $"{message.Author.Discriminator:0000}");
|
||||
_writer.WriteBoolean("isBot", message.Author.IsBot);
|
||||
_writer.WriteString("avatarUrl", message.Author.AvatarUrl);
|
||||
_writer.WriteEndObject();
|
||||
|
||||
// Attachments
|
||||
_writer.WriteStartArray("attachments");
|
||||
|
||||
foreach (var attachment in message.Attachments)
|
||||
{
|
||||
_writer.WriteStartObject();
|
||||
|
||||
_writer.WriteString("id", attachment.Id);
|
||||
_writer.WriteString("url", attachment.Url);
|
||||
_writer.WriteString("fileName", attachment.FileName);
|
||||
_writer.WriteNumber("fileSizeBytes", (long) attachment.FileSize.Bytes);
|
||||
|
||||
_writer.WriteEndObject();
|
||||
}
|
||||
|
||||
_writer.WriteEndArray();
|
||||
|
||||
// Embeds
|
||||
_writer.WriteStartArray("embeds");
|
||||
|
||||
foreach (var embed in message.Embeds)
|
||||
{
|
||||
_writer.WriteStartObject();
|
||||
|
||||
_writer.WriteString("title", embed.Title);
|
||||
_writer.WriteString("url", embed.Url);
|
||||
_writer.WriteString("timestamp", embed.Timestamp);
|
||||
_writer.WriteString("description", embed.Description);
|
||||
|
||||
// Author
|
||||
if (embed.Author != null)
|
||||
{
|
||||
_writer.WriteStartObject("author");
|
||||
_writer.WriteString("name", embed.Author.Name);
|
||||
_writer.WriteString("url", embed.Author.Url);
|
||||
_writer.WriteString("iconUrl", embed.Author.IconUrl);
|
||||
_writer.WriteEndObject();
|
||||
}
|
||||
|
||||
// Thumbnail
|
||||
if (embed.Thumbnail != null)
|
||||
{
|
||||
_writer.WriteStartObject("thumbnail");
|
||||
_writer.WriteString("url", embed.Thumbnail.Url);
|
||||
_writer.WriteNumber("width", embed.Thumbnail.Width);
|
||||
_writer.WriteNumber("height", embed.Thumbnail.Height);
|
||||
_writer.WriteEndObject();
|
||||
}
|
||||
|
||||
// Image
|
||||
if (embed.Image != null)
|
||||
{
|
||||
_writer.WriteStartObject("image");
|
||||
_writer.WriteString("url", embed.Image.Url);
|
||||
_writer.WriteNumber("width", embed.Image.Width);
|
||||
_writer.WriteNumber("height", embed.Image.Height);
|
||||
_writer.WriteEndObject();
|
||||
}
|
||||
|
||||
// Footer
|
||||
if (embed.Footer != null)
|
||||
{
|
||||
_writer.WriteStartObject("footer");
|
||||
_writer.WriteString("text", embed.Footer.Text);
|
||||
_writer.WriteString("iconUrl", embed.Footer.IconUrl);
|
||||
_writer.WriteEndObject();
|
||||
}
|
||||
|
||||
// Fields
|
||||
_writer.WriteStartArray("fields");
|
||||
|
||||
foreach (var field in embed.Fields)
|
||||
{
|
||||
_writer.WriteStartObject();
|
||||
|
||||
_writer.WriteString("name", field.Name);
|
||||
_writer.WriteString("value", field.Value);
|
||||
_writer.WriteBoolean("isInline", field.IsInline);
|
||||
|
||||
_writer.WriteEndObject();
|
||||
}
|
||||
|
||||
_writer.WriteEndArray();
|
||||
|
||||
_writer.WriteEndObject();
|
||||
}
|
||||
|
||||
_writer.WriteEndArray();
|
||||
|
||||
// Reactions
|
||||
_writer.WriteStartArray("reactions");
|
||||
|
||||
foreach (var reaction in message.Reactions)
|
||||
{
|
||||
_writer.WriteStartObject();
|
||||
|
||||
// Emoji
|
||||
_writer.WriteStartObject("emoji");
|
||||
_writer.WriteString("id", reaction.Emoji.Id);
|
||||
_writer.WriteString("name", reaction.Emoji.Name);
|
||||
_writer.WriteBoolean("isAnimated", reaction.Emoji.IsAnimated);
|
||||
_writer.WriteString("imageUrl", reaction.Emoji.ImageUrl);
|
||||
_writer.WriteEndObject();
|
||||
|
||||
// Count
|
||||
_writer.WriteNumber("count", reaction.Count);
|
||||
|
||||
_writer.WriteEndObject();
|
||||
}
|
||||
|
||||
_writer.WriteEndArray();
|
||||
|
||||
_writer.WriteEndObject();
|
||||
|
||||
_messageCount++;
|
||||
|
||||
// Flush every 100 messages
|
||||
if (_messageCount % 100 == 0)
|
||||
await _writer.FlushAsync();
|
||||
}
|
||||
|
||||
public override async Task WritePostambleAsync()
|
||||
{
|
||||
// Message array (end)
|
||||
_writer.WriteEndArray();
|
||||
|
||||
// Message count
|
||||
_writer.WriteNumber("messageCount", _messageCount);
|
||||
|
||||
// Root object (end)
|
||||
_writer.WriteEndObject();
|
||||
|
||||
await _writer.FlushAsync();
|
||||
}
|
||||
|
||||
public override async ValueTask DisposeAsync()
|
||||
{
|
||||
await _writer.DisposeAsync();
|
||||
await base.DisposeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
|
||||
namespace DiscordChatExporter.Core.Rendering.Formatters
|
||||
{
|
||||
public abstract class MessageWriterBase : IAsyncDisposable
|
||||
{
|
||||
protected Stream Stream { get; }
|
||||
|
||||
protected RenderContext Context { get; }
|
||||
|
||||
protected MessageWriterBase(Stream stream, RenderContext context)
|
||||
{
|
||||
Stream = stream;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public virtual Task WritePreambleAsync() => Task.CompletedTask;
|
||||
|
||||
public abstract Task WriteMessageAsync(Message message);
|
||||
|
||||
public virtual Task WritePostambleAsync() => Task.CompletedTask;
|
||||
|
||||
public virtual async ValueTask DisposeAsync() => await Stream.DisposeAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
using DiscordChatExporter.Core.Rendering.Logic;
|
||||
|
||||
namespace DiscordChatExporter.Core.Rendering.Formatters
|
||||
{
|
||||
public class PlainTextMessageWriter : MessageWriterBase
|
||||
{
|
||||
private readonly TextWriter _writer;
|
||||
|
||||
private long _messageCount;
|
||||
|
||||
public PlainTextMessageWriter(Stream stream, RenderContext context)
|
||||
: base(stream, context)
|
||||
{
|
||||
_writer = new StreamWriter(stream);
|
||||
}
|
||||
|
||||
public override async Task WritePreambleAsync()
|
||||
{
|
||||
await _writer.WriteLineAsync(PlainTextRenderingLogic.FormatPreamble(Context));
|
||||
}
|
||||
|
||||
public override async Task WriteMessageAsync(Message message)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
public override async ValueTask DisposeAsync()
|
||||
{
|
||||
await _writer.DisposeAsync();
|
||||
await base.DisposeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
|
||||
namespace DiscordChatExporter.Core.Rendering
|
||||
{
|
||||
public interface IMessageRenderer : IAsyncDisposable
|
||||
{
|
||||
Task RenderMessageAsync(Message message);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace DiscordChatExporter.Core.Rendering.Internal
|
||||
{
|
||||
@@ -17,5 +19,25 @@ namespace DiscordChatExporter.Core.Rendering.Internal
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static void WriteString(this Utf8JsonWriter writer, string propertyName, DateTimeOffset? value)
|
||||
{
|
||||
writer.WritePropertyName(propertyName);
|
||||
|
||||
if (value != null)
|
||||
writer.WriteStringValue(value.Value);
|
||||
else
|
||||
writer.WriteNullValue();
|
||||
}
|
||||
|
||||
public static void WriteNumber(this Utf8JsonWriter writer, string propertyName, int? value)
|
||||
{
|
||||
writer.WritePropertyName(propertyName);
|
||||
|
||||
if (value != null)
|
||||
writer.WriteNumberValue(value.Value);
|
||||
else
|
||||
writer.WriteNullValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using DiscordChatExporter.Core.Markdown;
|
||||
using DiscordChatExporter.Core.Markdown.Nodes;
|
||||
using DiscordChatExporter.Core.Markdown.Ast;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
using Tyrrrz.Extensions;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using DiscordChatExporter.Core.Markdown;
|
||||
using DiscordChatExporter.Core.Markdown.Nodes;
|
||||
using DiscordChatExporter.Core.Markdown.Ast;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
using DiscordChatExporter.Core.Rendering.Internal;
|
||||
using Tyrrrz.Extensions;
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
using DiscordChatExporter.Core.Rendering.Formatters;
|
||||
|
||||
namespace DiscordChatExporter.Core.Rendering
|
||||
{
|
||||
public partial class MessageRenderer : IAsyncDisposable
|
||||
{
|
||||
private readonly RenderOptions _options;
|
||||
private readonly RenderContext _context;
|
||||
|
||||
private long _renderedMessageCount;
|
||||
private int _partitionIndex;
|
||||
private MessageWriterBase? _writer;
|
||||
|
||||
public MessageRenderer(RenderOptions options, RenderContext context)
|
||||
{
|
||||
_options = options;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
private async Task InitializeWriterAsync()
|
||||
{
|
||||
// Get partition file path
|
||||
var filePath = GetPartitionFilePath(_options.BaseFilePath, _partitionIndex);
|
||||
|
||||
// Create output directory
|
||||
var dirPath = Path.GetDirectoryName(_options.BaseFilePath);
|
||||
if (!string.IsNullOrWhiteSpace(dirPath))
|
||||
Directory.CreateDirectory(dirPath);
|
||||
|
||||
// Create writer
|
||||
_writer = CreateMessageWriter(filePath, _options.Format, _context);
|
||||
|
||||
// Write preamble
|
||||
await _writer.WritePreambleAsync();
|
||||
}
|
||||
|
||||
private async Task ResetWriterAsync()
|
||||
{
|
||||
if (_writer != null)
|
||||
{
|
||||
// Write postamble
|
||||
await _writer.WritePostambleAsync();
|
||||
|
||||
// Flush
|
||||
await _writer.DisposeAsync();
|
||||
_writer = null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RenderMessageAsync(Message message)
|
||||
{
|
||||
// Ensure underlying writer is initialized
|
||||
if (_writer == null)
|
||||
await InitializeWriterAsync();
|
||||
|
||||
// Render the actual message
|
||||
await _writer!.WriteMessageAsync(message);
|
||||
|
||||
// Increment count
|
||||
_renderedMessageCount++;
|
||||
|
||||
// Shift partition if necessary
|
||||
if (_options.PartitionLimit != null &&
|
||||
_options.PartitionLimit != 0 &&
|
||||
_renderedMessageCount % _options.PartitionLimit == 0)
|
||||
{
|
||||
await ResetWriterAsync();
|
||||
_partitionIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync() => await ResetWriterAsync();
|
||||
}
|
||||
|
||||
public partial class MessageRenderer
|
||||
{
|
||||
private static string GetPartitionFilePath(string baseFilePath, int partitionIndex)
|
||||
{
|
||||
// First partition - no changes
|
||||
if (partitionIndex <= 0)
|
||||
return baseFilePath;
|
||||
|
||||
// Inject partition index into file name
|
||||
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(baseFilePath);
|
||||
var fileExt = Path.GetExtension(baseFilePath);
|
||||
var fileName = $"{fileNameWithoutExt} [part {partitionIndex + 1}]{fileExt}";
|
||||
|
||||
// Generate new path
|
||||
var dirPath = Path.GetDirectoryName(baseFilePath);
|
||||
if (!string.IsNullOrWhiteSpace(dirPath))
|
||||
return Path.Combine(dirPath, fileName);
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
private static MessageWriterBase CreateMessageWriter(string filePath, ExportFormat format, RenderContext context)
|
||||
{
|
||||
// Create a stream (it will get disposed by the writer)
|
||||
var stream = File.Create(filePath);
|
||||
|
||||
// Create formatter
|
||||
if (format == ExportFormat.PlainText)
|
||||
return new PlainTextMessageWriter(stream, context);
|
||||
|
||||
if (format == ExportFormat.Csv)
|
||||
return new CsvMessageWriter(stream, context);
|
||||
|
||||
if (format == ExportFormat.HtmlDark)
|
||||
return new HtmlMessageWriter(stream, context, "Dark");
|
||||
|
||||
if (format == ExportFormat.HtmlLight)
|
||||
return new HtmlMessageWriter(stream, context, "Light");
|
||||
|
||||
if (format == ExportFormat.Json)
|
||||
return new JsonMessageWriter(stream, context);
|
||||
|
||||
throw new InvalidOperationException($"Unknown export format [{format}].");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
|
||||
namespace DiscordChatExporter.Core.Rendering
|
||||
{
|
||||
public abstract class MessageRendererBase : IMessageRenderer
|
||||
{
|
||||
protected TextWriter Writer { get; }
|
||||
|
||||
protected RenderContext Context { get; }
|
||||
|
||||
protected MessageRendererBase(string filePath, RenderContext context)
|
||||
{
|
||||
Writer = File.CreateText(filePath);
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public abstract Task RenderMessageAsync(Message message);
|
||||
|
||||
public virtual ValueTask DisposeAsync() => Writer.DisposeAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
using DiscordChatExporter.Core.Rendering.Logic;
|
||||
|
||||
namespace DiscordChatExporter.Core.Rendering
|
||||
{
|
||||
public class PlainTextMessageRenderer : MessageRendererBase
|
||||
{
|
||||
private bool _isPreambleRendered;
|
||||
|
||||
public PlainTextMessageRenderer(string filePath, RenderContext context)
|
||||
: base(filePath, context)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task RenderMessageAsync(Message message)
|
||||
{
|
||||
// Render preamble if it's the first entry
|
||||
if (!_isPreambleRendered)
|
||||
{
|
||||
await Writer.WriteLineAsync(PlainTextRenderingLogic.FormatPreamble(Context));
|
||||
_isPreambleRendered = true;
|
||||
}
|
||||
|
||||
await Writer.WriteLineAsync(PlainTextRenderingLogic.FormatMessage(Context, message));
|
||||
await Writer.WriteLineAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using DiscordChatExporter.Core.Models;
|
||||
|
||||
namespace DiscordChatExporter.Core.Rendering
|
||||
{
|
||||
public class RenderOptions
|
||||
{
|
||||
public string BaseFilePath { get; }
|
||||
|
||||
public ExportFormat Format { get; }
|
||||
|
||||
public int? PartitionLimit { get; }
|
||||
|
||||
public RenderOptions(string baseFilePath, ExportFormat format, int? partitionLimit)
|
||||
{
|
||||
BaseFilePath = baseFilePath;
|
||||
Format = format;
|
||||
PartitionLimit = partitionLimit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* === GENERAL === */
|
||||
/* General */
|
||||
|
||||
@font-face {
|
||||
font-family: Whitney;
|
||||
@@ -58,10 +58,10 @@ img {
|
||||
}
|
||||
|
||||
.quote {
|
||||
margin: 0.5em 0;
|
||||
padding-left: 0.6em;
|
||||
border-left: 4px solid;
|
||||
border-radius: 3px;
|
||||
margin: 8px 0;
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
.pre {
|
||||
@@ -69,8 +69,8 @@ img {
|
||||
}
|
||||
|
||||
.pre--multiline {
|
||||
margin-top: 4px;
|
||||
padding: 8px;
|
||||
margin-top: 0.25em;
|
||||
padding: 0.5em;
|
||||
border: 2px solid;
|
||||
border-radius: 5px;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ img {
|
||||
.pre--inline {
|
||||
padding: 2px;
|
||||
border-radius: 3px;
|
||||
font-size: 85%;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
|
||||
.mention {
|
||||
@@ -86,80 +86,69 @@ img {
|
||||
}
|
||||
|
||||
.emoji {
|
||||
width: 1.45em;
|
||||
height: 1.45em;
|
||||
margin: 0 1px;
|
||||
width: 1.25em;
|
||||
height: 1.25em;
|
||||
margin: 0 0.06em;
|
||||
vertical-align: -0.4em;
|
||||
}
|
||||
|
||||
.emoji--small {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
}
|
||||
|
||||
.emoji--large {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
width: 2.8em;
|
||||
height: 2.8em;
|
||||
}
|
||||
|
||||
/* === INFO === */
|
||||
/* Preamble */
|
||||
|
||||
.info {
|
||||
display: flex;
|
||||
.preamble {
|
||||
display: grid;
|
||||
margin: 0 0.3em 0.6em 0.3em;
|
||||
max-width: 100%;
|
||||
margin: 0 5px 10px 5px;
|
||||
grid-template-columns: auto 1fr;
|
||||
}
|
||||
|
||||
.info__guild-icon-container {
|
||||
flex: 0;
|
||||
.preamble__guild-icon-container {
|
||||
grid-column: 1;
|
||||
}
|
||||
|
||||
.info__guild-icon {
|
||||
.preamble__guild-icon {
|
||||
max-width: 88px;
|
||||
max-height: 88px;
|
||||
}
|
||||
|
||||
.info__metadata {
|
||||
flex: 1;
|
||||
margin-left: 10px;
|
||||
.preamble__entries-container {
|
||||
grid-column: 2;
|
||||
margin-left: 0.6em;
|
||||
}
|
||||
|
||||
.info__guild-name {
|
||||
.preamble__entry {
|
||||
font-size: 1.4em;
|
||||
}
|
||||
|
||||
.info__channel-name {
|
||||
font-size: 1.2em;
|
||||
.preamble__entry--small {
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.info__channel-topic {
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.info__channel-message-count {
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.info__channel-date-range {
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
/* === CHATLOG === */
|
||||
/* Chatlog */
|
||||
|
||||
.chatlog {
|
||||
max-width: 100%;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.chatlog__message-group {
|
||||
display: flex;
|
||||
margin: 0 10px;
|
||||
padding: 15px 0;
|
||||
display: grid;
|
||||
margin: 0 0.6em;
|
||||
padding: 0.9em 0;
|
||||
border-top: 1px solid;
|
||||
grid-template-columns: auto 1fr;
|
||||
}
|
||||
|
||||
.chatlog__author-avatar-container {
|
||||
flex: 0;
|
||||
grid-column: 1;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
@@ -171,55 +160,53 @@ img {
|
||||
}
|
||||
|
||||
.chatlog__messages {
|
||||
flex: 1;
|
||||
grid-column: 2;
|
||||
margin-left: 1.2em;
|
||||
min-width: 50%;
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.chatlog__author-name {
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.chatlog__timestamp {
|
||||
margin-left: 5px;
|
||||
font-size: .75em;
|
||||
margin-left: 0.3em;
|
||||
font-size: 0.75em;
|
||||
}
|
||||
|
||||
.chatlog__message {
|
||||
padding: 2px 5px;
|
||||
margin-right: -5px;
|
||||
margin-left: -5px;
|
||||
padding: 0.1em 0.3em;
|
||||
margin: 0 -0.3em;
|
||||
background-color: transparent;
|
||||
transition: background-color 1s ease;
|
||||
}
|
||||
|
||||
.chatlog__content {
|
||||
font-size: .9375em;
|
||||
font-size: 0.95em;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.chatlog__edited-timestamp {
|
||||
margin-left: 3px;
|
||||
font-size: .8em;
|
||||
margin-left: 0.15em;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
|
||||
.chatlog__attachment-thumbnail {
|
||||
margin-top: 5px;
|
||||
margin-top: 0.3em;
|
||||
max-width: 50%;
|
||||
max-height: 500px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.chatlog__embed {
|
||||
margin-top: 5px;
|
||||
display: flex;
|
||||
margin-top: 0.3em;
|
||||
max-width: 520px;
|
||||
}
|
||||
|
||||
.chatlog__embed-color-pill {
|
||||
flex-shrink: 0;
|
||||
width: 4px;
|
||||
width: 0.25em;
|
||||
border-top-left-radius: 3px;
|
||||
border-bottom-left-radius: 3px;
|
||||
}
|
||||
@@ -227,15 +214,15 @@ img {
|
||||
.chatlog__embed-content-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 8px 10px;
|
||||
padding: 0.5em 0.6em;
|
||||
border: 1px solid;
|
||||
border-top-right-radius: 3px;
|
||||
border-bottom-right-radius: 3px;
|
||||
}
|
||||
|
||||
.chatlog__embed-content {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.chatlog__embed-text {
|
||||
@@ -244,31 +231,31 @@ img {
|
||||
|
||||
.chatlog__embed-author {
|
||||
display: flex;
|
||||
margin-bottom: 0.3em;
|
||||
align-items: center;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.chatlog__embed-author-icon {
|
||||
margin-right: 0.5em;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
margin-right: 9px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.chatlog__embed-author-name {
|
||||
font-size: .875em;
|
||||
font-size: 0.875em;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.chatlog__embed-title {
|
||||
margin-bottom: 4px;
|
||||
font-size: .875em;
|
||||
margin-bottom: 0.2em;
|
||||
font-size: 0.875em;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.chatlog__embed-description {
|
||||
font-weight: 500;
|
||||
font-size: 14px;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
|
||||
.chatlog__embed-fields {
|
||||
@@ -280,7 +267,8 @@ img {
|
||||
flex: 0;
|
||||
min-width: 100%;
|
||||
max-width: 506px;
|
||||
padding-top: 10px;
|
||||
padding-top: 0.6em;
|
||||
font-size: 0.875em;
|
||||
}
|
||||
|
||||
.chatlog__embed-field--inline {
|
||||
@@ -290,26 +278,24 @@ img {
|
||||
}
|
||||
|
||||
.chatlog__embed-field-name {
|
||||
margin-bottom: 4px;
|
||||
font-size: .875em;
|
||||
margin-bottom: 0.2em;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.chatlog__embed-field-value {
|
||||
font-size: .875em;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.chatlog__embed-thumbnail {
|
||||
flex: 0;
|
||||
margin-left: 20px;
|
||||
margin-left: 1.2em;
|
||||
max-width: 80px;
|
||||
max-height: 80px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.chatlog__embed-image-container {
|
||||
margin-top: 10px;
|
||||
margin-top: 0.6em;
|
||||
}
|
||||
|
||||
.chatlog__embed-image {
|
||||
@@ -319,11 +305,11 @@ img {
|
||||
}
|
||||
|
||||
.chatlog__embed-footer {
|
||||
margin-top: 10px;
|
||||
margin-top: 0.6em;
|
||||
}
|
||||
|
||||
.chatlog__embed-footer-icon {
|
||||
margin-right: 4px;
|
||||
margin-right: 0.2em;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 50%;
|
||||
@@ -331,8 +317,8 @@ img {
|
||||
}
|
||||
|
||||
.chatlog__embed-footer-text {
|
||||
font-size: 0.75em;
|
||||
font-weight: 500;
|
||||
font-size: .75em;
|
||||
}
|
||||
|
||||
.chatlog__reactions {
|
||||
@@ -342,27 +328,35 @@ img {
|
||||
.chatlog__reaction {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin: 6px 2px 2px 2px;
|
||||
padding: 3px 6px;
|
||||
margin: 0.35em 0.1em 0.1em 0.1em;
|
||||
padding: 0.2em 0.35em;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.chatlog__reaction-count {
|
||||
min-width: 9px;
|
||||
margin-left: 6px;
|
||||
font-size: .875em;
|
||||
margin-left: 0.35em;
|
||||
font-size: 0.875em;
|
||||
}
|
||||
|
||||
.chatlog__bot-tag {
|
||||
position: relative;
|
||||
top: -.2em;
|
||||
margin-left: 0.3em;
|
||||
padding: 0.05em 0.3em;
|
||||
border-radius: 3px;
|
||||
vertical-align: middle;
|
||||
line-height: 1.3;
|
||||
background: #7289da;
|
||||
color: #ffffff;
|
||||
font-size: 0.625em;
|
||||
font-weight: 500;
|
||||
padding: 1px 2px;
|
||||
border-radius: 3px;
|
||||
vertical-align: middle;
|
||||
line-height: 1.3;
|
||||
position: relative;
|
||||
top: -.2em;
|
||||
}
|
||||
|
||||
/* Postamble */
|
||||
|
||||
.postamble {
|
||||
margin: 1.4em 0.3em 0.6em 0.3em;
|
||||
padding: 1em;
|
||||
border-top: 1px solid;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* === GENERAL === */
|
||||
/* General */
|
||||
|
||||
body {
|
||||
background-color: #36393e;
|
||||
@@ -30,21 +30,13 @@ a {
|
||||
color: #7289da;
|
||||
}
|
||||
|
||||
/* === INFO === */
|
||||
/* === Preamble === */
|
||||
|
||||
.info__guild-name {
|
||||
.preamble__entry {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.info__channel-name {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.info__channel-topic {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
/* === CHATLOG === */
|
||||
/* Chatlog */
|
||||
|
||||
.chatlog__message-group {
|
||||
border-color: rgba(255, 255, 255, 0.1);
|
||||
@@ -113,4 +105,14 @@ a {
|
||||
|
||||
.chatlog__reaction-count {
|
||||
color: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
/* Postamble */
|
||||
|
||||
.postamble {
|
||||
border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.postamble__entry {
|
||||
color: #ffffff;
|
||||
}
|
||||
@@ -48,21 +48,21 @@
|
||||
</head>
|
||||
<body>
|
||||
|
||||
{{~ # Info ~}}
|
||||
<div class="info">
|
||||
<div class="info__guild-icon-container">
|
||||
<img class="info__guild-icon" src="{{ Context.Guild.IconUrl }}" />
|
||||
{{~ # Preamble ~}}
|
||||
<div class="preamble">
|
||||
<div class="preamble__guild-icon-container">
|
||||
<img class="preamble__guild-icon" src="{{ Context.Guild.IconUrl }}" alt="Guild icon" />
|
||||
</div>
|
||||
<div class="info__metadata">
|
||||
<div class="info__guild-name">{{ Context.Guild.Name | html.escape }}</div>
|
||||
<div class="info__channel-name">{{ Context.Channel.Name | html.escape }}</div>
|
||||
<div class="preamble__entries-container">
|
||||
<div class="preamble__entry">{{ Context.Guild.Name | html.escape }}</div>
|
||||
<div class="preamble__entry">{{ Context.Channel.Name | html.escape }}</div>
|
||||
|
||||
{{~ if Context.Channel.Topic ~}}
|
||||
<div class="info__channel-topic">{{ Context.Channel.Topic | html.escape }}</div>
|
||||
<div class="preamble__entry preamble__entry--small">{{ Context.Channel.Topic | html.escape }}</div>
|
||||
{{~ end ~}}
|
||||
|
||||
{{~ if Context.After || Context.Before ~}}
|
||||
<div class="info__channel-date-range">
|
||||
<div class="preamble__entry preamble__entry--small">
|
||||
{{~ if Context.After && Context.Before ~}}
|
||||
Between {{ Context.After | FormatDate | html.escape }} and {{ Context.Before | FormatDate | html.escape }}
|
||||
{{~ else if Context.After ~}}
|
||||
@@ -80,5 +80,10 @@
|
||||
{{~ %SPLIT% ~}}
|
||||
</div>
|
||||
|
||||
{{~ # Postamble ~}}
|
||||
<div class="postamble">
|
||||
<div class="postamble__entry">Exported {{ MessageCount | object.format "N0" }} message(s)</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,4 +1,4 @@
|
||||
/* === GENERAL === */
|
||||
/* General */
|
||||
|
||||
body {
|
||||
background-color: #ffffff;
|
||||
@@ -32,21 +32,13 @@ a {
|
||||
color: #7289da;
|
||||
}
|
||||
|
||||
/* === INFO === */
|
||||
/* Preamble */
|
||||
|
||||
.info__guild-name {
|
||||
.preamble__entry {
|
||||
color: #2f3136;
|
||||
}
|
||||
|
||||
.info__channel-name {
|
||||
color: #2f3136;
|
||||
}
|
||||
|
||||
.info__channel-topic {
|
||||
color: #2f3136;
|
||||
}
|
||||
|
||||
/* === CHATLOG === */
|
||||
/* Chatlog */
|
||||
|
||||
.chatlog__message-group {
|
||||
border-color: #eceeef;
|
||||
@@ -116,4 +108,14 @@ a {
|
||||
|
||||
.chatlog__reaction-count {
|
||||
color: #747f8d;
|
||||
}
|
||||
|
||||
/* Postamble */
|
||||
|
||||
.postamble {
|
||||
border-color: #eceeef;
|
||||
}
|
||||
|
||||
.postamble__entry {
|
||||
color: #2f3136;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<div class="chatlog__message-group">
|
||||
{{~ # Avatar ~}}
|
||||
<div class="chatlog__author-avatar-container">
|
||||
<img class="chatlog__author-avatar" src="{{ MessageGroup.Author.AvatarUrl }}" />
|
||||
<img class="chatlog__author-avatar" src="{{ MessageGroup.Author.AvatarUrl }}" alt="Avatar" />
|
||||
</div>
|
||||
<div class="chatlog__messages">
|
||||
{{~ # Author name and timestamp ~}}
|
||||
@@ -35,7 +35,7 @@
|
||||
<a href="{{ attachment.Url }}">
|
||||
{{ # Image }}
|
||||
{{~ if attachment.IsImage ~}}
|
||||
<img class="chatlog__attachment-thumbnail" src="{{ attachment.Url }}" />
|
||||
<img class="chatlog__attachment-thumbnail" src="{{ attachment.Url }}" alt="Attachment" />
|
||||
{{~ # Non-image ~}}
|
||||
{{~ else ~}}
|
||||
Attachment: {{ attachment.FileName }} ({{ attachment.FileSize }})
|
||||
@@ -59,7 +59,7 @@
|
||||
{{~ if embed.Author ~}}
|
||||
<div class="chatlog__embed-author">
|
||||
{{~ if embed.Author.IconUrl ~}}
|
||||
<img class="chatlog__embed-author-icon" src="{{ embed.Author.IconUrl }}" />
|
||||
<img class="chatlog__embed-author-icon" src="{{ embed.Author.IconUrl }}" alt="Author icon" />
|
||||
{{~ end ~}}
|
||||
|
||||
{{~ if embed.Author.Name ~}}
|
||||
@@ -111,7 +111,7 @@
|
||||
{{~ if embed.Thumbnail ~}}
|
||||
<div class="chatlog__embed-thumbnail-container">
|
||||
<a class="chatlog__embed-thumbnail-link" href="{{ embed.Thumbnail.Url }}">
|
||||
<img class="chatlog__embed-thumbnail" src="{{ embed.Thumbnail.Url }}" />
|
||||
<img class="chatlog__embed-thumbnail" src="{{ embed.Thumbnail.Url }}" alt="Thumbnail" />
|
||||
</a>
|
||||
</div>
|
||||
{{~ end ~}}
|
||||
@@ -121,7 +121,7 @@
|
||||
{{~ if embed.Image ~}}
|
||||
<div class="chatlog__embed-image-container">
|
||||
<a class="chatlog__embed-image-link" href="{{ embed.Image.Url }}">
|
||||
<img class="chatlog__embed-image" src="{{ embed.Image.Url }}" />
|
||||
<img class="chatlog__embed-image" src="{{ embed.Image.Url }}" alt="Image" />
|
||||
</a>
|
||||
</div>
|
||||
{{~ end ~}}
|
||||
@@ -131,7 +131,7 @@
|
||||
<div class="chatlog__embed-footer">
|
||||
{{~ if embed.Footer ~}}
|
||||
{{~ if embed.Footer.Text && embed.Footer.IconUrl ~}}
|
||||
<img class="chatlog__embed-footer-icon" src="{{ embed.Footer.IconUrl }}" />
|
||||
<img class="chatlog__embed-footer-icon" src="{{ embed.Footer.IconUrl }}" alt="Footer icon" />
|
||||
{{~ end ~}}
|
||||
{{~ end ~}}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="Onova" Version="2.5.1" />
|
||||
<PackageReference Include="Onova" Version="2.5.2" />
|
||||
<PackageReference Include="Polly" Version="7.2.0" />
|
||||
<PackageReference Include="Tyrrrz.Extensions" Version="1.6.5" />
|
||||
<PackageReference Include="Tyrrrz.Settings" Version="1.3.4" />
|
||||
|
||||
@@ -3,13 +3,14 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
using DiscordChatExporter.Core.Models.Exceptions;
|
||||
using DiscordChatExporter.Core.Rendering;
|
||||
using DiscordChatExporter.Core.Services.Logic;
|
||||
using Tyrrrz.Extensions;
|
||||
|
||||
namespace DiscordChatExporter.Core.Services
|
||||
{
|
||||
public class ExportService
|
||||
public partial class ExportService
|
||||
{
|
||||
private readonly SettingsService _settingsService;
|
||||
private readonly DataService _dataService;
|
||||
@@ -20,51 +21,16 @@ namespace DiscordChatExporter.Core.Services
|
||||
_dataService = dataService;
|
||||
}
|
||||
|
||||
private string GetFilePathFromOutputPath(string outputPath, ExportFormat format, RenderContext context)
|
||||
{
|
||||
// Output is a directory
|
||||
if (Directory.Exists(outputPath) || string.IsNullOrWhiteSpace(Path.GetExtension(outputPath)))
|
||||
{
|
||||
var fileName = ExportLogic.GetDefaultExportFileName(format, context.Guild, context.Channel, context.After, context.Before);
|
||||
return Path.Combine(outputPath, fileName);
|
||||
}
|
||||
|
||||
// Output is a file
|
||||
return outputPath;
|
||||
}
|
||||
|
||||
private IMessageRenderer CreateRenderer(string outputPath, int partitionIndex, ExportFormat format, RenderContext context)
|
||||
{
|
||||
var filePath = ExportLogic.GetExportPartitionFilePath(
|
||||
GetFilePathFromOutputPath(outputPath, format, context),
|
||||
partitionIndex);
|
||||
|
||||
// Create output directory
|
||||
var dirPath = Path.GetDirectoryName(filePath);
|
||||
if (!string.IsNullOrWhiteSpace(dirPath))
|
||||
Directory.CreateDirectory(dirPath);
|
||||
|
||||
// Create renderer
|
||||
|
||||
if (format == ExportFormat.PlainText)
|
||||
return new PlainTextMessageRenderer(filePath, context);
|
||||
|
||||
if (format == ExportFormat.Csv)
|
||||
return new CsvMessageRenderer(filePath, context);
|
||||
|
||||
if (format == ExportFormat.HtmlDark)
|
||||
return new HtmlMessageRenderer(filePath, context, "Dark");
|
||||
|
||||
if (format == ExportFormat.HtmlLight)
|
||||
return new HtmlMessageRenderer(filePath, context, "Light");
|
||||
|
||||
throw new InvalidOperationException($"Unknown export format [{format}].");
|
||||
}
|
||||
|
||||
public async Task ExportChatLogAsync(AuthToken token, Guild guild, Channel channel,
|
||||
string outputPath, ExportFormat format, int? partitionLimit,
|
||||
DateTimeOffset? after = null, DateTimeOffset? before = null, IProgress<double>? progress = null)
|
||||
{
|
||||
// Get base file path from output path
|
||||
var baseFilePath = GetFilePathFromOutputPath(outputPath, format, guild, channel, after, before);
|
||||
|
||||
// Create options
|
||||
var options = new RenderOptions(baseFilePath, format, partitionLimit);
|
||||
|
||||
// Create context
|
||||
var mentionableUsers = new HashSet<User>(IdBasedEqualityComparer.Instance);
|
||||
var mentionableChannels = await _dataService.GetGuildChannelsAsync(token, guild.Id);
|
||||
@@ -76,35 +42,42 @@ namespace DiscordChatExporter.Core.Services
|
||||
mentionableUsers, mentionableChannels, mentionableRoles
|
||||
);
|
||||
|
||||
// Render messages
|
||||
var partitionIndex = 0;
|
||||
var partitionMessageCount = 0;
|
||||
var renderer = CreateRenderer(outputPath, partitionIndex, format, context);
|
||||
// Create renderer
|
||||
await using var renderer = new MessageRenderer(options, context);
|
||||
|
||||
// Render messages
|
||||
var renderedAnything = false;
|
||||
await foreach (var message in _dataService.GetMessagesAsync(token, channel.Id, after, before, progress))
|
||||
{
|
||||
// Add encountered users to the list of mentionable users
|
||||
mentionableUsers.Add(message.Author);
|
||||
mentionableUsers.AddRange(message.MentionedUsers);
|
||||
|
||||
// If new partition is required, reset renderer
|
||||
if (partitionLimit != null && partitionLimit > 0 && partitionMessageCount >= partitionLimit)
|
||||
{
|
||||
partitionIndex++;
|
||||
partitionMessageCount = 0;
|
||||
|
||||
// Flush old renderer and create a new one
|
||||
await renderer.DisposeAsync();
|
||||
renderer = CreateRenderer(outputPath, partitionIndex, format, context);
|
||||
}
|
||||
|
||||
// Render message
|
||||
await renderer.RenderMessageAsync(message);
|
||||
partitionMessageCount++;
|
||||
renderedAnything = true;
|
||||
}
|
||||
|
||||
// Flush last renderer
|
||||
await renderer.DisposeAsync();
|
||||
// Throw if no messages were rendered
|
||||
if (!renderedAnything)
|
||||
throw new DomainException($"Channel [{channel.Name}] contains no messages for specified period");
|
||||
}
|
||||
}
|
||||
|
||||
public partial class ExportService
|
||||
{
|
||||
private static string GetFilePathFromOutputPath(string outputPath, ExportFormat format, Guild guild, Channel channel,
|
||||
DateTimeOffset? after, DateTimeOffset? before)
|
||||
{
|
||||
// Output is a directory
|
||||
if (Directory.Exists(outputPath) || string.IsNullOrWhiteSpace(Path.GetExtension(outputPath)))
|
||||
{
|
||||
var fileName = ExportLogic.GetDefaultExportFileName(format, guild, channel, after, before);
|
||||
return Path.Combine(outputPath, fileName);
|
||||
}
|
||||
|
||||
// Output is a file
|
||||
return outputPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,24 +49,5 @@ namespace DiscordChatExporter.Core.Services.Logic
|
||||
|
||||
return buffer.ToString();
|
||||
}
|
||||
|
||||
public static string GetExportPartitionFilePath(string baseFilePath, int partitionIndex)
|
||||
{
|
||||
// First partition - no changes
|
||||
if (partitionIndex <= 0)
|
||||
return baseFilePath;
|
||||
|
||||
// Inject partition index into file name
|
||||
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(baseFilePath);
|
||||
var fileExt = Path.GetExtension(baseFilePath);
|
||||
var fileName = $"{fileNameWithoutExt} [part {partitionIndex + 1}]{fileExt}";
|
||||
|
||||
// Generate new path
|
||||
var dirPath = Path.GetDirectoryName(baseFilePath);
|
||||
if (!string.IsNullOrWhiteSpace(dirPath))
|
||||
return Path.Combine(dirPath, fileName);
|
||||
|
||||
return fileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,11 @@ namespace DiscordChatExporter.Core.Services
|
||||
{
|
||||
public class SettingsService : SettingsManager
|
||||
{
|
||||
public string DateFormat { get; set; } = "dd-MMM-yy hh:mm tt";
|
||||
|
||||
public bool IsAutoUpdateEnabled { get; set; } = true;
|
||||
|
||||
public string DateFormat { get; set; } = "dd-MMM-yy hh:mm tt";
|
||||
public bool IsTokenPersisted { get; set; } = true;
|
||||
|
||||
public AuthToken? LastToken { get; set; }
|
||||
|
||||
@@ -21,5 +23,7 @@ namespace DiscordChatExporter.Core.Services
|
||||
Configuration.SubDirectoryPath = "";
|
||||
Configuration.FileName = "Settings.dat";
|
||||
}
|
||||
|
||||
public bool ShouldSerializeLastToken() => IsTokenPersisted;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<Application
|
||||
<Application
|
||||
x:Class="DiscordChatExporter.Gui.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Gress" Version="1.1.1" />
|
||||
<PackageReference Include="MaterialDesignColors" Version="1.2.0" />
|
||||
<PackageReference Include="MaterialDesignThemes" Version="2.6.0" />
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.3" />
|
||||
<PackageReference Include="MaterialDesignColors" Version="1.2.2" />
|
||||
<PackageReference Include="MaterialDesignThemes" Version="3.0.1" />
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
|
||||
<PackageReference Include="Ookii.Dialogs.Wpf" Version="1.1.0" />
|
||||
<PackageReference Include="PropertyChanged.Fody" Version="3.1.3" />
|
||||
<PackageReference Include="Stylet" Version="1.3.0" />
|
||||
<PackageReference Include="Tyrrrz.Extensions" Version="1.6.5" />
|
||||
<PackageReference Include="PropertyChanged.Fody" Version="3.2.5" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -30,4 +30,9 @@
|
||||
<ProjectReference Include="..\DiscordChatExporter.Core.Services\DiscordChatExporter.Core.Services.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="Format XAML" AfterTargets="BeforeBuild">
|
||||
<Exec Command="dotnet tool restore" />
|
||||
<Exec Command="dotnet xstyler -r -d "$(MSBuildProjectDirectory)"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Core.Services;
|
||||
using Onova;
|
||||
using Onova.Exceptions;
|
||||
using Onova.Services;
|
||||
@@ -12,17 +13,30 @@ namespace DiscordChatExporter.Gui.Services
|
||||
new GithubPackageResolver("Tyrrrz", "DiscordChatExporter", "DiscordChatExporter.zip"),
|
||||
new ZipPackageExtractor());
|
||||
|
||||
private readonly SettingsService _settingsService;
|
||||
|
||||
private Version? _updateVersion;
|
||||
private bool _updaterLaunched;
|
||||
|
||||
public UpdateService(SettingsService settingsService)
|
||||
{
|
||||
_settingsService = settingsService;
|
||||
}
|
||||
|
||||
public async Task<Version?> CheckForUpdatesAsync()
|
||||
{
|
||||
if (!_settingsService.IsAutoUpdateEnabled)
|
||||
return null;
|
||||
|
||||
var check = await _updateManager.CheckForUpdatesAsync();
|
||||
return check.CanUpdate ? check.LastVersion : null;
|
||||
}
|
||||
|
||||
public async Task PrepareUpdateAsync(Version version)
|
||||
{
|
||||
if (!_settingsService.IsAutoUpdateEnabled)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
await _updateManager.PrepareUpdateAsync(_updateVersion = version);
|
||||
@@ -39,13 +53,15 @@ namespace DiscordChatExporter.Gui.Services
|
||||
|
||||
public void FinalizeUpdate(bool needRestart)
|
||||
{
|
||||
if (!_settingsService.IsAutoUpdateEnabled)
|
||||
return;
|
||||
|
||||
if (_updateVersion == null || _updaterLaunched)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
if (_updateVersion == null || _updaterLaunched)
|
||||
return;
|
||||
|
||||
_updateManager.LaunchUpdater(_updateVersion, needRestart);
|
||||
|
||||
_updaterLaunched = true;
|
||||
}
|
||||
catch (UpdaterAlreadyLaunchedException)
|
||||
|
||||
@@ -7,16 +7,22 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
|
||||
{
|
||||
private readonly SettingsService _settingsService;
|
||||
|
||||
public string DateFormat
|
||||
{
|
||||
get => _settingsService.DateFormat;
|
||||
set => _settingsService.DateFormat = value;
|
||||
}
|
||||
|
||||
public bool IsAutoUpdateEnabled
|
||||
{
|
||||
get => _settingsService.IsAutoUpdateEnabled;
|
||||
set => _settingsService.IsAutoUpdateEnabled = value;
|
||||
}
|
||||
|
||||
public string DateFormat
|
||||
public bool IsTokenPersisted
|
||||
{
|
||||
get => _settingsService.DateFormat;
|
||||
set => _settingsService.DateFormat = value;
|
||||
get => _settingsService.IsTokenPersisted;
|
||||
set => _settingsService.IsTokenPersisted = value;
|
||||
}
|
||||
|
||||
public SettingsViewModel(SettingsService settingsService)
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
using DiscordChatExporter.Core.Models.Exceptions;
|
||||
using DiscordChatExporter.Core.Services;
|
||||
using DiscordChatExporter.Core.Services.Exceptions;
|
||||
using DiscordChatExporter.Gui.Services;
|
||||
@@ -69,10 +70,6 @@ namespace DiscordChatExporter.Gui.ViewModels
|
||||
{
|
||||
try
|
||||
{
|
||||
// Don't check for updates if auto-update is disabled
|
||||
if (!_settingsService.IsAutoUpdateEnabled)
|
||||
return;
|
||||
|
||||
// Check for updates
|
||||
var updateVersion = await _updateService.CheckForUpdatesAsync();
|
||||
if (updateVersion == null)
|
||||
@@ -234,6 +231,10 @@ namespace DiscordChatExporter.Gui.ViewModels
|
||||
{
|
||||
Notifications.Enqueue("Forbidden – account may be locked by 2FA");
|
||||
}
|
||||
catch (DomainException ex)
|
||||
{
|
||||
Notifications.Enqueue(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
operation.Dispose();
|
||||
@@ -280,6 +281,10 @@ namespace DiscordChatExporter.Gui.ViewModels
|
||||
{
|
||||
Notifications.Enqueue($"Channel [{channel.Model.Name}] doesn't exist");
|
||||
}
|
||||
catch (DomainException ex)
|
||||
{
|
||||
Notifications.Enqueue(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
operation.Dispose();
|
||||
@@ -287,7 +292,8 @@ namespace DiscordChatExporter.Gui.ViewModels
|
||||
}
|
||||
|
||||
// Notify of overall completion
|
||||
Notifications.Enqueue($"Successfully exported {successfulExportCount} channel(s)");
|
||||
if (successfulExportCount > 0)
|
||||
Notifications.Enqueue($"Successfully exported {successfulExportCount} channel(s)");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,8 +28,8 @@
|
||||
|
||||
<!-- Auto-updates -->
|
||||
<DockPanel
|
||||
LastChildFill="False"
|
||||
Background="Transparent"
|
||||
LastChildFill="False"
|
||||
ToolTip="Perform automatic updates on every launch">
|
||||
<TextBlock
|
||||
Margin="16,8"
|
||||
@@ -41,6 +41,21 @@
|
||||
IsChecked="{Binding IsAutoUpdateEnabled}" />
|
||||
</DockPanel>
|
||||
|
||||
<!-- Persist token -->
|
||||
<DockPanel
|
||||
Background="Transparent"
|
||||
LastChildFill="False"
|
||||
ToolTip="Persist last used token between sessions">
|
||||
<TextBlock
|
||||
Margin="16,8"
|
||||
DockPanel.Dock="Left"
|
||||
Text="Save token" />
|
||||
<ToggleButton
|
||||
Margin="16,8"
|
||||
DockPanel.Dock="Right"
|
||||
IsChecked="{Binding IsTokenPersisted}" />
|
||||
</DockPanel>
|
||||
|
||||
<!-- Save button -->
|
||||
<Button
|
||||
Margin="8"
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
x:Name="TokenValueTextBox"
|
||||
Grid.Column="1"
|
||||
Margin="2,6,6,7"
|
||||
VerticalAlignment="Bottom"
|
||||
materialDesign:HintAssist.Hint="Token"
|
||||
materialDesign:TextFieldAssist.DecorationVisibility="Hidden"
|
||||
materialDesign:TextFieldAssist.TextBoxViewMargin="0,0,2,0"
|
||||
@@ -245,7 +246,8 @@
|
||||
<ListBox
|
||||
HorizontalContentAlignment="Stretch"
|
||||
ItemsSource="{Binding SelectedGuild.Channels}"
|
||||
SelectionMode="Extended">
|
||||
SelectionMode="Extended"
|
||||
TextSearch.TextPath="Model.Name">
|
||||
<i:Interaction.Behaviors>
|
||||
<behaviors:ChannelViewModelMultiSelectionListBoxBehavior SelectedItems="{Binding SelectedChannels}" />
|
||||
</i:Interaction.Behaviors>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<Version>2.16</Version>
|
||||
<Version>2.18</Version>
|
||||
<Company>Tyrrrz</Company>
|
||||
<Copyright>Copyright (c) Alexey Golub</Copyright>
|
||||
<LangVersion>latest</LangVersion>
|
||||
|
||||
@@ -8,6 +8,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||
Changelog.md = Changelog.md
|
||||
License.txt = License.txt
|
||||
Readme.md = Readme.md
|
||||
DiscordChatExporter.props = DiscordChatExporter.props
|
||||
Dockerfile = Dockerfile
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiscordChatExporter.Core.Markdown", "DiscordChatExporter.Core.Markdown\DiscordChatExporter.Core.Markdown.csproj", "{14D02A08-E820-4012-B805-663B9A3D73E9}"
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
DiscordChatExporter
|
||||
Copyright (C) 2017-2019 Alexey Golub
|
||||
Copyright (C) 2017-2020 Alexey Golub
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
[](https://github.com/Tyrrrz/DiscordChatExporter/releases)
|
||||
[](https://tyrrrz.me/donate)
|
||||
|
||||
DiscordChatExporter can be used to export message history from a [Discord](https://discordapp.com) channel to a file. It works for both direct message chats and guild chats, supports markdown, message grouping, embeds, attachments, mentions, reactions and other features. It works with both user and bot tokens, supports multiple output formats and allows you to trim messages by dates.
|
||||
DiscordChatExporter can be used to export message history from a [Discord](https://discordapp.com) channel to a file. It works with direct messages, group messages, server channels, supports Discord's dialect of markdown and all other rich media features.
|
||||
|
||||
_For guides and other info -- check out the [wiki](https://github.com/Tyrrrz/DiscordChatExporter/wiki)._
|
||||
|
||||
@@ -15,13 +15,23 @@ _For guides and other info -- check out the [wiki](https://github.com/Tyrrrz/Dis
|
||||
- [Docker image](https://hub.docker.com/r/tyrrrz/discordchatexporter): `docker pull tyrrrz/discordchatexporter`
|
||||
- [CI build](https://github.com/Tyrrrz/DiscordChatExporter/actions)
|
||||
|
||||
Note: This application requires .NET Core runtime in order to run:
|
||||
|
||||
- .NET Core runtime for Windows: [x64](https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-desktop-3.1.0-windows-x64-installer) | [x86](https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-desktop-3.1.0-windows-x86-installer)
|
||||
- .NET Core runtime for macOS (for CLI version only): [x64](https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-3.1.0-macos-x64-installer)
|
||||
- .NET Core runtime for Linux (for CLI version only): [Ubuntu/Debian](https://docs.microsoft.com/en-us/dotnet/core/install/linux-package-manager-ubuntu-1904#install-the-net-core-runtime)
|
||||
|
||||
## Features
|
||||
|
||||
- Graphical and command line interfaces
|
||||
- Supports both user tokens and bot tokens
|
||||
- Allows retrieving messages in specified date range
|
||||
- Multiple export formats: HTML (dark/light), TXT and CSV
|
||||
- Renders all message features including: markdown, attachments, embeds, emojis, mentions, etc
|
||||
- Graphical user interface (Windows)
|
||||
- Command line interface (Windows, Linux, macOS)
|
||||
- Works with both user and bot tokens
|
||||
- Exports on the fly without buffering messages in memory
|
||||
- Allows exporting messages in a specified range
|
||||
- Supports file partitioning based on message count
|
||||
- Uses custom markdown parser compatible with Discord syntax
|
||||
- Handles all rich media features, including attachments, embeds, emojis, etc
|
||||
- Renders to HTML (dark & light), TXT, CSV, JSON
|
||||
|
||||
## Screenshots
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"indentSize": 4
|
||||
}
|
||||
Reference in New Issue
Block a user