Compare commits

...

33 Commits

Author SHA1 Message Date
Alexey Golub dbf15c7bee Update version 2020-03-26 23:32:51 +02:00
Alexey Golub a41a4ca8a7 [HTML] Fix occasionally wrong user colors 2020-03-26 23:32:41 +02:00
Alexey Golub c098f4b137 [HTML] Use nicknames when rendering mentions 2020-03-26 23:22:21 +02:00
Alexey Golub ff15257d23 Fix bugs in previous PR 2020-03-26 22:59:36 +02:00
Will Kennedy 79e43c4144 Add support for Guild Member object & included data (#279) 2020-03-26 14:36:55 +02:00
Alexey Golub 7bb8038ce9 Revert "[GUI] Publish as 32-bit for maximum compatibility"
This reverts commit ee27167998.
2020-03-26 14:02:13 +02:00
Alexey Golub ee27167998 [GUI] Publish as 32-bit for maximum compatibility
Closes #243
2020-03-25 22:25:24 +02:00
Alexey Golub 9f4277ae84 Add parallel exporting
Closes #264
2020-03-25 19:22:33 +02:00
Alexey Golub 70a1c9db8c Clean up warnings 2020-03-23 19:11:15 +02:00
Will Kennedy 378f0a20db [HTML] Update CSS for mentions (#278) 2020-03-14 14:21:53 +02:00
Alexey Golub a24fe3906c Update GitHub Actions workflows 2020-02-16 20:33:30 +02:00
Alexey Golub eececb6701 Update version 2020-02-04 14:05:44 +02:00
Alexey Golub d3adf19500 Simplify display text for export formats 2020-02-04 14:04:26 +02:00
Alexey Golub a01835efb6 [CLI] Cleanup 2020-02-04 12:14:53 +02:00
Alexey Golub 1d39fe9c53 Update readme 2020-02-03 18:10:06 +02:00
Alexey Golub 9f6090b3af Add JSON message writer
Closes #103
2020-02-03 17:47:42 +02:00
Alexey Golub 9fa40dca00 Add text search in the channel list
Closes #184
2020-02-03 14:18:27 +02:00
Alexey Golub 8a4f306012 Update CliFx to v1.0 2020-01-30 16:34:36 +02:00
Alexey Golub 37be80e9e1 Update version 2020-01-12 21:14:00 +02:00
Alexey Golub 1475ffaf0e Use the new Rune API for handling emoji code points 2020-01-12 21:04:02 +02:00
Alexey Golub aa50dd6dc7 [HTML] Clean up layouts and styles 2020-01-12 20:16:08 +02:00
Alexey Golub 539f57f455 [HTML/TXT] Render exported message count at the bottom
Closes #249
2020-01-11 18:03:07 +02:00
Alexey Golub e1f83997aa [GUI] Fix token textbox alignment 2020-01-11 18:01:35 +02:00
Alexey Golub 26d713a17c Refactor 2020-01-11 17:28:01 +02:00
Alexey Golub 5c2e725739 Move partitioning to message renderer facade 2020-01-11 14:18:04 +02:00
Alexey Golub bf56902134 Refactor partitioning, don't create empty files
Closes #246
2020-01-10 21:05:07 +02:00
Alexey Golub b4df267372 Update NuGet packages 2020-01-10 20:10:01 +02:00
Alexey Golub 4ebc681327 Format XAML with XAMLStyler 2020-01-10 20:06:13 +02:00
Alexey Golub 5cb6adf19e Add an option to not save token
Closes #252
2020-01-10 20:03:31 +02:00
Alexey Golub cec8409ac4 Check if auto-update is enabled in UpdateService 2020-01-03 21:44:30 +02:00
Alexey Golub 3af9421304 Add changelog to CD 2019-12-15 15:35:32 +02:00
Alexey Golub cc6f930dc6 Update readme 2019-12-10 19:27:41 +02:00
Alexey Golub e6aac3cdb9 Update changelog and readme 2019-12-08 14:00:12 +02:00
77 changed files with 1250 additions and 576 deletions
+12
View File
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"xamlstyler.console": {
"version": "3.2001.0",
"commands": [
"xstyler"
]
}
}
}
+7 -5
View File
@@ -11,10 +11,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v2
- name: Install .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v1.4.0
with:
dotnet-version: 3.1.100
@@ -34,17 +34,19 @@ jobs:
- name: Create release
id: create_release
uses: actions/create-release@v1.0.0
uses: actions/create-release@v1.0.1
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
- name: Upload release asset (CLI)
uses: actions/upload-release-asset@v1.0.1
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
@@ -54,7 +56,7 @@ jobs:
asset_content_type: application/zip
- name: Upload release asset (GUI)
uses: actions/upload-release-asset@v1.0.1
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
+4 -4
View File
@@ -8,10 +8,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v2
- name: Install .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v1.4.0
with:
dotnet-version: 3.1.100
@@ -22,13 +22,13 @@ jobs:
run: dotnet publish DiscordChatExporter.Gui/ -o DiscordChatExporter.Gui/bin/Publish/ --configuration Release
- name: Upload build artifacts (CLI)
uses: actions/upload-artifact@master
uses: actions/upload-artifact@v1
with:
name: DiscordChatExporter.CLI
path: DiscordChatExporter.Cli/bin/Publish/
- name: Upload build artifact (GUI)
uses: actions/upload-artifact@master
uses: actions/upload-artifact@v1
with:
name: DiscordChatExporter
path: DiscordChatExporter.Gui/bin/Publish/
+23 -1
View File
@@ -1,10 +1,32 @@
### v2.19 (26-Mar-2020)
- Added parallel exporting. This option allows you to export multiple channels faster by doing it in parallel. You can configure the parallel limit in settings (GUI) or with the `--parallel` option (CLI). Default value is `1`, which means there is no parallelization. Warning: be careful when using this option, as this will result in higher volume of concurrent HTTP requests sent to Discord, which might get you flagged. Use at your own risk.
- [HTML] Added support for user colors. User names are now appropriately colored according to the assigned guild roles.
- [HTML] Added support for nicknames. User names are replaced with nicknames where it's applicable. It's still possible to see the full user name by hovering your mouse over the nickname.
- [HTML] Improved styling for mentions to bring it more in line with how it looks in Discord.
### 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,23 @@ 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();
console.Output.WriteLine("Done.");
}
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,45 +1,25 @@
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using CliFx;
using CliFx.Attributes;
using CliFx.Services;
using DiscordChatExporter.Core.Services;
using DiscordChatExporter.Core.Services.Exceptions;
namespace DiscordChatExporter.Cli.Commands
{
[Command("exportdm", Description = "Export all direct message channels.")]
public class ExportDirectMessagesCommand : ExportCommandBase
public class ExportDirectMessagesCommand : ExportMultipleCommandBase
{
public ExportDirectMessagesCommand(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.GetDirectMessageChannelsAsync(GetToken());
var directMessageChannels = await DataService.GetDirectMessageChannelsAsync(Token);
var channels = directMessageChannels.OrderBy(c => c.Name).ToArray();
// Order channels
channels = channels.OrderBy(c => c.Name).ToArray();
// Loop through channels
foreach (var channel in channels)
{
try
{
await ExportAsync(console, channel);
}
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden)
{
console.Error.WriteLine("You don't have access to this channel.");
}
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.NotFound)
{
console.Error.WriteLine("This channel doesn't exist.");
}
}
await ExportMultipleAsync(console, channels);
}
}
}
@@ -1,49 +1,33 @@
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.Services;
using DiscordChatExporter.Core.Services.Exceptions;
namespace DiscordChatExporter.Cli.Commands
{
[Command("exportguild", Description = "Export all channels within specified guild.")]
public class ExportGuildCommand : ExportCommandBase
public class ExportGuildCommand : ExportMultipleCommandBase
{
[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 guildChannels = await DataService.GetGuildChannelsAsync(Token, GuildId);
// Filter and order channels
channels = channels.Where(c => c.Type.IsExportable()).OrderBy(c => c.Name).ToArray();
var channels = guildChannels
.Where(c => c.Type.IsExportable())
.OrderBy(c => c.Name)
.ToArray();
// Loop through channels
foreach (var channel in channels)
{
try
{
await ExportAsync(console, channel);
}
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden)
{
console.Error.WriteLine("You don't have access to this channel.");
}
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.NotFound)
{
console.Error.WriteLine("This channel doesn't exist.");
}
}
await ExportMultipleAsync(console, channels);
}
}
}
@@ -0,0 +1,92 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using CliFx;
using CliFx.Attributes;
using CliFx.Utilities;
using DiscordChatExporter.Core.Models;
using DiscordChatExporter.Core.Models.Exceptions;
using DiscordChatExporter.Core.Services;
using DiscordChatExporter.Core.Services.Exceptions;
using Gress;
using Tyrrrz.Extensions;
namespace DiscordChatExporter.Cli.Commands
{
public abstract class ExportMultipleCommandBase : ExportCommandBase
{
[CommandOption("parallel", Description = "Export this number of separate channels in parallel.")]
public int ParallelLimit { get; set; } = 1;
protected ExportMultipleCommandBase(SettingsService settingsService, DataService dataService, ExportService exportService)
: base(settingsService, dataService, exportService)
{
}
protected async ValueTask ExportMultipleAsync(IConsole console, IReadOnlyList<Channel> channels)
{
// This uses a separate route from ExportCommandBase because the progress ticker is not thread-safe
// Ugly code ahead. Will need to refactor.
if (!string.IsNullOrWhiteSpace(DateFormat))
SettingsService.DateFormat = DateFormat;
// Progress
console.Output.Write($"Exporting {channels.Count} channels... ");
var ticker = console.CreateProgressTicker();
// TODO: refactor this after improving Gress
var progressManager = new ProgressManager();
progressManager.PropertyChanged += (sender, args) => ticker.Report(progressManager.Progress);
var operations = progressManager.CreateOperations(channels.Count);
// Export channels
using var semaphore = new SemaphoreSlim(ParallelLimit.ClampMin(1));
var errors = new List<string>();
await Task.WhenAll(channels.Select(async (channel, i) =>
{
var operation = operations[i];
await semaphore.WaitAsync();
var guild = await DataService.GetGuildAsync(Token, channel.GuildId);
try
{
await ExportService.ExportChatLogAsync(Token, guild, channel,
OutputPath, ExportFormat, PartitionLimit,
After, Before, operation);
}
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden)
{
errors.Add("You don't have access to this channel.");
}
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.NotFound)
{
errors.Add("This channel doesn't exist.");
}
catch (DomainException ex)
{
errors.Add(ex.Message);
}
finally
{
semaphore.Release();
operation.Dispose();
}
}));
ticker.Report(1);
console.Output.WriteLine();
foreach (var error in errors)
console.Error.WriteLine(error);
console.Output.WriteLine("Done.");
}
}
}
@@ -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,22 +11,22 @@ 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 guildChannels = await DataService.GetGuildChannelsAsync(Token, GuildId);
// Filter and order channels
channels = channels.Where(c => c.Type.IsExportable()).OrderBy(c => c.Name).ToArray();
var channels = guildChannels
.Where(c => c.Type.IsExportable())
.OrderBy(c => c.Name)
.ToArray();
// Print result
foreach (var channel in channels)
console.Output.WriteLine($"{channel.Id} | {channel.Name}");
}
@@ -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,15 +14,11 @@ 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 directMessageChannels = await DataService.GetDirectMessageChannelsAsync(Token);
var channels = directMessageChannels.OrderBy(c => c.Name).ToArray();
// Order channels
channels = channels.OrderBy(c => c.Name).ToArray();
// Print result
foreach (var channel in channels)
console.Output.WriteLine($"{channel.Id} | {channel.Name}");
}
@@ -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,16 +14,11 @@ 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();
// Print result
foreach (var guild in guilds)
foreach (var guild in guilds.OrderBy(g => g.Name))
console.Output.WriteLine($"{guild.Id} | {guild.Name}");
}
}
@@ -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,9 @@
</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="Gress" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.1" />
<PackageReference Include="Tyrrrz.Extensions" Version="1.6.5" />
</ItemGroup>
+4 -3
View File
@@ -1,4 +1,5 @@
using System;
using System.Drawing;
using System.Threading.Tasks;
using CliFx;
using DiscordChatExporter.Cli.Commands;
@@ -30,13 +31,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,4 +1,4 @@
namespace DiscordChatExporter.Core.Markdown.Nodes
namespace DiscordChatExporter.Core.Markdown.Ast
{
public class EmojiNode : Node
{
@@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace DiscordChatExporter.Core.Markdown.Nodes
namespace DiscordChatExporter.Core.Markdown.Ast
{
public class FormattedNode : Node
{
@@ -1,4 +1,4 @@
namespace DiscordChatExporter.Core.Markdown.Nodes
namespace DiscordChatExporter.Core.Markdown.Ast
{
public class InlineCodeBlockNode : Node
{
@@ -1,4 +1,4 @@
namespace DiscordChatExporter.Core.Markdown.Nodes
namespace DiscordChatExporter.Core.Markdown.Ast
{
public class LinkNode : Node
{
@@ -1,4 +1,4 @@
namespace DiscordChatExporter.Core.Markdown.Nodes
namespace DiscordChatExporter.Core.Markdown.Ast
{
public class MentionNode : Node
{
@@ -1,4 +1,4 @@
namespace DiscordChatExporter.Core.Markdown.Nodes
namespace DiscordChatExporter.Core.Markdown.Ast
{
public enum MentionType
{
@@ -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,4 +1,4 @@
namespace DiscordChatExporter.Core.Markdown.Nodes
namespace DiscordChatExporter.Core.Markdown.Ast
{
public enum TextFormatting
{
@@ -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
{
}
}
+24 -8
View File
@@ -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))
};
}
+29 -8
View File
@@ -1,6 +1,11 @@
namespace DiscordChatExporter.Core.Models
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace DiscordChatExporter.Core.Models
{
// https://discordapp.string.IsNullOrWhiteSpace(com/developers/docs/resources/guild#guild-object
// https://discordapp.com/developers/docs/resources/guild#guild-object
public partial class Guild : IHasId
{
@@ -10,13 +15,19 @@
public string? IconHash { get; }
public IReadOnlyList<Role> Roles { get; }
public Dictionary<string, Member?> Members { get; }
public string IconUrl { get; }
public Guild(string id, string name, string? iconHash)
public Guild(string id, string name, IReadOnlyList<Role> roles, string? iconHash)
{
Id = id;
Name = name;
IconHash = iconHash;
Roles = roles;
Members = new Dictionary<string, Member?>();
IconUrl = GetIconUrl(id, iconHash);
}
@@ -26,13 +37,23 @@
public partial class Guild
{
public static string GetIconUrl(string id, string? iconHash)
{
return !string.IsNullOrWhiteSpace(iconHash)
public static string GetUserColor(Guild guild, User user) =>
guild.Members.GetValueOrDefault(user.Id, null)
?.Roles
.Select(r => guild.Roles.FirstOrDefault(role => r == role.Id))
.Where(r => r != null)
.Where(r => r.Color != Color.Black)
.Where(r => r.Color.R + r.Color.G + r.Color.B > 0)
.Aggregate<Role, Role?>(null, (a, b) => (a?.Position ?? 0) > b.Position ? a : b)
?.ColorAsHex ?? "";
public static string GetUserNick(Guild guild, User user) => guild.Members.GetValueOrDefault(user.Id)?.Nick ?? user.Name;
public static string GetIconUrl(string id, string? iconHash) =>
!string.IsNullOrWhiteSpace(iconHash)
? $"https://cdn.discordapp.com/icons/{id}/{iconHash}.png"
: "https://cdn.discordapp.com/embed/avatars/0.png";
}
public static Guild DirectMessages { get; } = new Guild("@me", "Direct Messages", null);
public static Guild DirectMessages { get; } = new Guild("@me", "Direct Messages", Array.Empty<Role>(), null);
}
}
+23
View File
@@ -0,0 +1,23 @@
using System.Collections.Generic;
using System.Linq;
namespace DiscordChatExporter.Core.Models
{
// https://discordapp.com/developers/docs/resources/guild#guild-member-object
public class Member
{
public string UserId { get; }
public string? Nick { get; }
public IReadOnlyList<string> Roles { get; }
public Member(string userId, string? nick, IReadOnlyList<string> roles)
{
UserId = userId;
Nick = nick;
Roles = roles;
}
}
}
+15 -3
View File
@@ -1,4 +1,6 @@
namespace DiscordChatExporter.Core.Models
using System.Drawing;
namespace DiscordChatExporter.Core.Models
{
// https://discordapp.com/developers/docs/topics/permissions#role-object
@@ -8,10 +10,20 @@
public string Name { get; }
public Role(string id, string name)
public Color Color { get; }
public string ColorAsHex => $"#{Color.ToArgb() & 0xffffff:X6}";
public string ColorAsRgb => $"{Color.R}, {Color.G}, {Color.B}";
public int Position { get; }
public Role(string id, string name, Color color, int position)
{
Id = id;
Name = name;
Color = color;
Position = position;
}
public override string ToString() => Name;
@@ -19,6 +31,6 @@
public partial class Role
{
public static Role CreateDeletedRole(string id) => new Role(id, "deleted-role");
public static Role CreateDeletedRole(string id) => new Role(id, "deleted-role", Color.Black, -1);
}
}
@@ -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();
}
}
}
@@ -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()
@@ -72,21 +75,19 @@ namespace DiscordChatExporter.Core.Rendering
scriptObject.Import("FormatMarkdown",
new Func<string, string>(m => HtmlRenderingLogic.FormatMarkdown(Context, m)));
scriptObject.Import("GetUserColor", new Func<Guild, User, string>(Guild.GetUserColor));
scriptObject.Import("GetUserNick", new Func<Guild, User, string>(Guild.GetUserNick));
// Push model
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 +98,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 +119,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 +158,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();
}
}
}
@@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using System.Drawing;
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;
@@ -97,7 +98,9 @@ namespace DiscordChatExporter.Core.Rendering.Logic
var user = context.MentionableUsers.FirstOrDefault(u => u.Id == mentionNode.Id) ??
User.CreateUnknownUser(mentionNode.Id);
return $"<span class=\"mention\" title=\"{HtmlEncode(user.FullName)}\">@{HtmlEncode(user.Name)}</span>";
var nick = Guild.GetUserNick(context.Guild, user);
return $"<span class=\"mention\" title=\"{HtmlEncode(user.FullName)}\">@{HtmlEncode(nick)}</span>";
}
// Channel mention node
@@ -114,8 +117,11 @@ namespace DiscordChatExporter.Core.Rendering.Logic
{
var role = context.MentionableRoles.FirstOrDefault(r => r.Id == mentionNode.Id) ??
Role.CreateDeletedRole(mentionNode.Id);
string style = "";
if (role.Color != Color.Black)
style = $"style=\"color: {role.ColorAsHex}; background-color: rgba({role.ColorAsRgb}, 0.1); font-weight: 400;\"";
return $"<span class=\"mention\">@{HtmlEncode(role.Name)}</span>";
return $"<span class=\"mention\" {style}>@{HtmlEncode(role.Name)}</span>";
}
}
@@ -128,7 +134,8 @@ namespace DiscordChatExporter.Core.Rendering.Logic
// Make emoji large if it's jumbo
var jumboableCssClass = isJumbo ? "emoji--large" : null;
return $"<img class=\"emoji {jumboableCssClass}\" alt=\"{emojiNode.Name}\" title=\"{emojiNode.Name}\" src=\"{emojiImageUrl}\" />";
return
$"<img class=\"emoji {jumboableCssClass}\" alt=\"{emojiNode.Name}\" title=\"{emojiNode.Name}\" src=\"{emojiImageUrl}\" />";
}
// Link node
@@ -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,88 +78,81 @@ img {
.pre--inline {
padding: 2px;
border-radius: 3px;
font-size: 85%;
font-size: 0.85em;
}
.mention {
border-radius: 3px;
padding: 0 2px;
color: #7289da;
background: rgba(114, 137, 218, .1);
font-weight: 500;
}
.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 +164,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 +218,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 +235,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 +271,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 +282,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 +309,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 +321,8 @@ img {
}
.chatlog__embed-footer-text {
font-size: 0.75em;
font-weight: 500;
font-size: .75em;
}
.chatlog__reactions {
@@ -342,27 +332,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;
@@ -26,25 +26,13 @@ a {
color: #b9bbbe !important;
}
.mention {
color: #7289da;
}
/* === Preamble === */
/* === INFO === */
.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 +101,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;
@@ -27,26 +27,13 @@ a {
color: #657b83 !important;
}
.mention {
background-color: #f1f3fb;
color: #7289da;
}
/* Preamble */
/* === INFO === */
.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 +103,14 @@ a {
.chatlog__reaction-count {
color: #747f8d;
}
/* Postamble */
.postamble {
border-color: #eceeef;
}
.postamble__entry {
color: #2f3136;
}
@@ -1,11 +1,11 @@
<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 ~}}
<span class="chatlog__author-name" title="{{ MessageGroup.Author.FullName | html.escape }}" data-user-id="{{ MessageGroup.Author.Id | html.escape }}">{{ MessageGroup.Author.Name | html.escape }}</span>
<span class="chatlog__author-name" title="{{ MessageGroup.Author.FullName | html.escape }}" data-user-id="{{ MessageGroup.Author.Id | html.escape }}" style="color: {{ GetUserColor Context.Guild MessageGroup.Author }}">{{ GetUserNick Context.Guild MessageGroup.Author | html.escape }}</span>
{{~ # Bot tag ~}}
{{~ if MessageGroup.Author.IsBot ~}}
@@ -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 ~}}
@@ -21,13 +21,23 @@ namespace DiscordChatExporter.Core.Services
return new User(id, discriminator, name, avatarHash, isBot);
}
private Member ParseMember(JToken json)
{
var userId = ParseUser(json["user"]!).Id;
var nick = json["nick"]?.Value<string>();
var roles = (json["roles"] ?? Enumerable.Empty<JToken>()).Select(j => j.Value<string>()).ToArray();
return new Member(userId, nick, roles);
}
private Guild ParseGuild(JToken json)
{
var id = json["id"]!.Value<string>();
var name = json["name"]!.Value<string>();
var iconHash = json["icon"]!.Value<string>();
var roles = (json["roles"] ?? Enumerable.Empty<JToken>()).Select(ParseRole).ToArray();
return new Guild(id, name, iconHash);
return new Guild(id, name, roles, iconHash);
}
private Channel ParseChannel(JToken json)
@@ -64,8 +74,10 @@ namespace DiscordChatExporter.Core.Services
{
var id = json["id"]!.Value<string>();
var name = json["name"]!.Value<string>();
var color = json["color"]!.Value<int>();
var position = json["position"]!.Value<int>();
return new Role(id, name);
return new Role(id, name, Color.FromArgb(color), position);
}
private Attachment ParseAttachment(JToken json)
@@ -42,6 +42,11 @@ namespace DiscordChatExporter.Core.Services
}
private async Task<JToken> GetApiResponseAsync(AuthToken token, string route)
{
return (await GetApiResponseAsync(token, route, true))!;
}
private async Task<JToken?> GetApiResponseAsync(AuthToken token, string route, bool errorOnFail)
{
using var response = await _httpPolicy.ExecuteAsync(async () =>
{
@@ -56,7 +61,10 @@ namespace DiscordChatExporter.Core.Services
// We throw our own exception here because default one doesn't have status code
if (!response.IsSuccessStatusCode)
throw new HttpErrorStatusCodeException(response.StatusCode, response.ReasonPhrase);
{
if (errorOnFail) throw new HttpErrorStatusCodeException(response.StatusCode, response.ReasonPhrase);
else return null;
}
var jsonRaw = await response.Content.ReadAsStringAsync();
return JToken.Parse(jsonRaw);
@@ -74,6 +82,15 @@ namespace DiscordChatExporter.Core.Services
return guild;
}
public async Task<Member?> GetGuildMemberAsync(AuthToken token, string guildId, string userId)
{
var response = await GetApiResponseAsync(token, $"guilds/{guildId}/members/{userId}", false);
if (response == null) return null;
var member = ParseMember(response);
return member;
}
public async Task<Channel> GetChannelAsync(AuthToken token, string channelId)
{
var response = await GetApiResponseAsync(token, $"channels/{channelId}");
@@ -97,10 +114,11 @@ namespace DiscordChatExporter.Core.Services
if (!response.HasValues)
yield break;
foreach (var guild in response.Select(ParseGuild))
// Get full guild object
foreach (var guildId in response.Select(j => j["id"]!.Value<string>()))
{
yield return guild;
afterId = guild.Id;
yield return await GetGuildAsync(token, guildId);
afterId = guildId;
}
}
}
@@ -125,18 +143,6 @@ namespace DiscordChatExporter.Core.Services
return channels;
}
public async Task<IReadOnlyList<Role>> GetGuildRolesAsync(AuthToken token, string guildId)
{
// Special case for direct messages pseudo-guild
if (guildId == Guild.DirectMessages.Id)
return Array.Empty<Role>();
var response = await GetApiResponseAsync(token, $"guilds/{guildId}/roles");
var roles = response.Select(ParseRole).ToArray();
return roles;
}
private async Task<Message> GetLastMessageAsync(AuthToken token, string channelId, DateTimeOffset? before = null)
{
var route = $"channels/{channelId}/messages?limit=1";
@@ -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,55 +21,20 @@ 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);
var mentionableRoles = await _dataService.GetGuildRolesAsync(token, guild.Id);
var mentionableRoles = guild.Roles;
var context = new RenderContext
(
@@ -76,35 +42,55 @@ 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);
var encounteredUsers = new List<User>();
encounteredUsers.Add(message.Author);
encounteredUsers.AddRange(message.MentionedUsers);
// If new partition is required, reset renderer
if (partitionLimit != null && partitionLimit > 0 && partitionMessageCount >= partitionLimit)
mentionableUsers.AddRange(encounteredUsers);
foreach (User u in encounteredUsers)
{
partitionIndex++;
partitionMessageCount = 0;
// Flush old renderer and create a new one
await renderer.DisposeAsync();
renderer = CreateRenderer(outputPath, partitionIndex, format, context);
if(!guild.Members.ContainsKey(u.Id))
{
var member = await _dataService.GetGuildMemberAsync(token, guild.Id, u.Id);
guild.Members[u.Id] = member;
}
}
// 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,13 @@ 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 int ParallelLimit { get; set; } = 1;
public AuthToken? LastToken { get; set; }
@@ -21,5 +25,7 @@ namespace DiscordChatExporter.Core.Services
Configuration.SubDirectoryPath = "";
Configuration.FileName = "Settings.dat";
}
public bool ShouldSerializeLastToken() => IsTokenPersisted;
}
}
+1 -1
View File
@@ -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 ." />
</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)
@@ -5,13 +5,13 @@ namespace DiscordChatExporter.Gui.ViewModels.Components
{
public partial class ChannelViewModel : PropertyChangedBase
{
public Channel Model { get; set; }
public Channel? Model { get; set; }
public string? Category { get; set; }
}
public partial class ChannelViewModel
{
public static implicit operator Channel(ChannelViewModel viewModel) => viewModel.Model;
public static implicit operator Channel?(ChannelViewModel? viewModel) => viewModel?.Model;
}
}
@@ -6,13 +6,13 @@ namespace DiscordChatExporter.Gui.ViewModels.Components
{
public partial class GuildViewModel : PropertyChangedBase
{
public Guild Model { get; set; }
public Guild? Model { get; set; }
public IReadOnlyList<ChannelViewModel> Channels { get; set; }
public IReadOnlyList<ChannelViewModel>? Channels { get; set; }
}
public partial class GuildViewModel
{
public static implicit operator Guild(GuildViewModel viewModel) => viewModel.Model;
public static implicit operator Guild?(GuildViewModel? viewModel) => viewModel?.Model;
}
}
@@ -14,11 +14,11 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
private readonly DialogManager _dialogManager;
private readonly SettingsService _settingsService;
public GuildViewModel Guild { get; set; }
public GuildViewModel? Guild { get; set; }
public IReadOnlyList<ChannelViewModel> Channels { get; set; }
public IReadOnlyList<ChannelViewModel>? Channels { get; set; }
public bool IsSingleChannel => Channels.Count == 1;
public bool IsSingleChannel => Channels == null || Channels.Count == 1;
public string? OutputPath { get; set; }
@@ -62,7 +62,7 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
var channel = Channels.Single();
// Generate default file name
var defaultFileName = ExportLogic.GetDefaultExportFileName(SelectedFormat, Guild, channel, After, Before);
var defaultFileName = ExportLogic.GetDefaultExportFileName(SelectedFormat, Guild!, channel!, After, Before);
// Generate filter
var ext = SelectedFormat.GetFileExtension();
@@ -1,5 +1,6 @@
using DiscordChatExporter.Core.Services;
using DiscordChatExporter.Gui.ViewModels.Framework;
using Tyrrrz.Extensions;
namespace DiscordChatExporter.Gui.ViewModels.Dialogs
{
@@ -7,16 +8,28 @@ 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 int ParallelLimit
{
get => _settingsService.ParallelLimit;
set => _settingsService.ParallelLimit = value.Clamp(1, 10);
}
public SettingsViewModel(SettingsService settingsService)
@@ -5,7 +5,8 @@ namespace DiscordChatExporter.Gui.ViewModels.Framework
{
public abstract class DialogScreen<T> : PropertyChangedBase
{
public T DialogResult { get; private set; }
// ReSharper disable once RedundantDefaultMemberInitializer
public T DialogResult { get; private set; } = default!;
public event EventHandler? Closed;
@@ -2,8 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
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 +71,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)
@@ -181,7 +179,7 @@ namespace DiscordChatExporter.Gui.ViewModels
// Create guild view model
var guildViewModel = _viewModelFactory.CreateGuildViewModel(guild,
channelViewModels.OrderBy(c => c.Category)
.ThenBy(c => c.Model.Name)
.ThenBy(c => c.Model!.Name)
.ToArray());
// Add to list
@@ -213,7 +211,7 @@ namespace DiscordChatExporter.Gui.ViewModels
// Create guild view model
var guildViewModel = _viewModelFactory.CreateGuildViewModel(guild,
channelViewModels.OrderBy(c => c.Category)
.ThenBy(c => c.Model.Name)
.ThenBy(c => c.Model!.Name)
.ToArray());
// Add to list
@@ -234,6 +232,10 @@ namespace DiscordChatExporter.Gui.ViewModels
{
Notifications.Enqueue("Forbidden account may be locked by 2FA");
}
catch (DomainException ex)
{
Notifications.Enqueue(ex.Message);
}
finally
{
operation.Dispose();
@@ -255,18 +257,21 @@ namespace DiscordChatExporter.Gui.ViewModels
return;
// Create a progress operation for each channel to export
var operations = ProgressManager.CreateOperations(dialog.Channels.Count);
var operations = ProgressManager.CreateOperations(dialog.Channels!.Count);
// Export channels
var successfulExportCount = 0;
for (var i = 0; i < dialog.Channels.Count; i++)
using var semaphore = new SemaphoreSlim(_settingsService.ParallelLimit.ClampMin(1));
await Task.WhenAll(dialog.Channels.Select(async (channel, i) =>
{
var operation = operations[i];
var channel = dialog.Channels[i];
await semaphore.WaitAsync();
try
{
await _exportService.ExportChatLogAsync(token, dialog.Guild, channel,
await _exportService.ExportChatLogAsync(token, dialog.Guild!, channel!,
dialog.OutputPath!, dialog.SelectedFormat, dialog.PartitionLimit,
dialog.After, dialog.Before, operation);
@@ -274,20 +279,26 @@ namespace DiscordChatExporter.Gui.ViewModels
}
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden)
{
Notifications.Enqueue($"You don't have access to channel [{channel.Model.Name}]");
Notifications.Enqueue($"You don't have access to channel [{channel.Model!.Name}]");
}
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.NotFound)
{
Notifications.Enqueue($"Channel [{channel.Model.Name}] doesn't exist");
Notifications.Enqueue($"Channel [{channel.Model!.Name}] doesn't exist");
}
catch (DomainException ex)
{
Notifications.Enqueue(ex.Message);
}
finally
{
operation.Dispose();
semaphore.Release();
}
}
}));
// 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,36 @@
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>
<!-- Parallel limit -->
<StackPanel Background="Transparent" ToolTip="How many channels can be exported at the same time">
<TextBlock Margin="16,8">
<Run Text="Parallel limit:" />
<Run Foreground="{DynamicResource PrimaryTextBrush}" Text="{Binding ParallelLimit, Mode=OneWay}" />
</TextBlock>
<Slider
Margin="16,8"
IsSnapToTickEnabled="True"
Maximum="10"
Minimum="1"
TickFrequency="1"
Value="{Binding ParallelLimit}" />
</StackPanel>
<!-- Save button -->
<Button
Margin="8"
+3 -1
View File
@@ -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>
+1 -1
View File
@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>2.16</Version>
<Version>2.19</Version>
<Company>Tyrrrz</Company>
<Copyright>Copyright (c) Alexey Golub</Copyright>
<LangVersion>latest</LangVersion>
+2
View File
@@ -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
View File
@@ -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
+16 -6
View File
@@ -5,7 +5,7 @@
[![Downloads](https://img.shields.io/github/downloads/Tyrrrz/DiscordChatExporter/total.svg)](https://github.com/Tyrrrz/DiscordChatExporter/releases)
[![Donate](https://img.shields.io/badge/donate-$$$-purple.svg)](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
+3
View File
@@ -0,0 +1,3 @@
{
"indentSize": 4
}