mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-07-08 15:14:37 +02:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dbf15c7bee | |||
| a41a4ca8a7 | |||
| c098f4b137 | |||
| ff15257d23 | |||
| 79e43c4144 | |||
| 7bb8038ce9 | |||
| ee27167998 | |||
| 9f4277ae84 | |||
| 70a1c9db8c | |||
| 378f0a20db | |||
| a24fe3906c |
@@ -11,10 +11,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v1
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Install .NET Core
|
- name: Install .NET Core
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1.4.0
|
||||||
with:
|
with:
|
||||||
dotnet-version: 3.1.100
|
dotnet-version: 3.1.100
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Create release
|
- name: Create release
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: actions/create-release@v1
|
uses: actions/create-release@v1.0.1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
@@ -46,7 +46,7 @@ jobs:
|
|||||||
prerelease: false
|
prerelease: false
|
||||||
|
|
||||||
- name: Upload release asset (CLI)
|
- name: Upload release asset (CLI)
|
||||||
uses: actions/upload-release-asset@v1.0.1
|
uses: actions/upload-release-asset@v1.0.2
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
@@ -56,7 +56,7 @@ jobs:
|
|||||||
asset_content_type: application/zip
|
asset_content_type: application/zip
|
||||||
|
|
||||||
- name: Upload release asset (GUI)
|
- name: Upload release asset (GUI)
|
||||||
uses: actions/upload-release-asset@v1.0.1
|
uses: actions/upload-release-asset@v1.0.2
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v1
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Install .NET Core
|
- name: Install .NET Core
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1.4.0
|
||||||
with:
|
with:
|
||||||
dotnet-version: 3.1.100
|
dotnet-version: 3.1.100
|
||||||
|
|
||||||
@@ -22,13 +22,13 @@ jobs:
|
|||||||
run: dotnet publish DiscordChatExporter.Gui/ -o DiscordChatExporter.Gui/bin/Publish/ --configuration Release
|
run: dotnet publish DiscordChatExporter.Gui/ -o DiscordChatExporter.Gui/bin/Publish/ --configuration Release
|
||||||
|
|
||||||
- name: Upload build artifacts (CLI)
|
- name: Upload build artifacts (CLI)
|
||||||
uses: actions/upload-artifact@master
|
uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
name: DiscordChatExporter.CLI
|
name: DiscordChatExporter.CLI
|
||||||
path: DiscordChatExporter.Cli/bin/Publish/
|
path: DiscordChatExporter.Cli/bin/Publish/
|
||||||
|
|
||||||
- name: Upload build artifact (GUI)
|
- name: Upload build artifact (GUI)
|
||||||
uses: actions/upload-artifact@master
|
uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
name: DiscordChatExporter
|
name: DiscordChatExporter
|
||||||
path: DiscordChatExporter.Gui/bin/Publish/
|
path: DiscordChatExporter.Gui/bin/Publish/
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
### 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)
|
### 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.
|
- 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.
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
After, Before, progress);
|
After, Before, progress);
|
||||||
|
|
||||||
console.Output.WriteLine();
|
console.Output.WriteLine();
|
||||||
|
console.Output.WriteLine("Done.");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async ValueTask ExportAsync(IConsole console, Channel channel)
|
protected async ValueTask ExportAsync(IConsole console, Channel channel)
|
||||||
|
|||||||
@@ -1,16 +1,13 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CliFx;
|
using CliFx;
|
||||||
using CliFx.Attributes;
|
using CliFx.Attributes;
|
||||||
using DiscordChatExporter.Core.Models.Exceptions;
|
|
||||||
using DiscordChatExporter.Core.Services;
|
using DiscordChatExporter.Core.Services;
|
||||||
using DiscordChatExporter.Core.Services.Exceptions;
|
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands
|
namespace DiscordChatExporter.Cli.Commands
|
||||||
{
|
{
|
||||||
[Command("exportdm", Description = "Export all direct message channels.")]
|
[Command("exportdm", Description = "Export all direct message channels.")]
|
||||||
public class ExportDirectMessagesCommand : ExportCommandBase
|
public class ExportDirectMessagesCommand : ExportMultipleCommandBase
|
||||||
{
|
{
|
||||||
public ExportDirectMessagesCommand(SettingsService settingsService, DataService dataService, ExportService exportService)
|
public ExportDirectMessagesCommand(SettingsService settingsService, DataService dataService, ExportService exportService)
|
||||||
: base(settingsService, dataService, exportService)
|
: base(settingsService, dataService, exportService)
|
||||||
@@ -19,32 +16,10 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
|
|
||||||
public override async ValueTask ExecuteAsync(IConsole console)
|
public override async ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
// Get channels
|
var directMessageChannels = await DataService.GetDirectMessageChannelsAsync(Token);
|
||||||
var channels = await DataService.GetDirectMessageChannelsAsync(Token);
|
var channels = directMessageChannels.OrderBy(c => c.Name).ToArray();
|
||||||
|
|
||||||
// Order channels
|
await ExportMultipleAsync(console, 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.");
|
|
||||||
}
|
|
||||||
catch (DomainException ex)
|
|
||||||
{
|
|
||||||
console.Error.WriteLine(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,14 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CliFx;
|
using CliFx;
|
||||||
using CliFx.Attributes;
|
using CliFx.Attributes;
|
||||||
using DiscordChatExporter.Core.Models;
|
using DiscordChatExporter.Core.Models;
|
||||||
using DiscordChatExporter.Core.Models.Exceptions;
|
|
||||||
using DiscordChatExporter.Core.Services;
|
using DiscordChatExporter.Core.Services;
|
||||||
using DiscordChatExporter.Core.Services.Exceptions;
|
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands
|
namespace DiscordChatExporter.Cli.Commands
|
||||||
{
|
{
|
||||||
[Command("exportguild", Description = "Export all channels within specified guild.")]
|
[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.")]
|
[CommandOption("guild", 'g', IsRequired = true, Description = "Guild ID.")]
|
||||||
public string GuildId { get; set; } = "";
|
public string GuildId { get; set; } = "";
|
||||||
@@ -23,32 +20,14 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
|
|
||||||
public override async ValueTask ExecuteAsync(IConsole console)
|
public override async ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
// Get channels
|
var guildChannels = await DataService.GetGuildChannelsAsync(Token, GuildId);
|
||||||
var channels = await DataService.GetGuildChannelsAsync(Token, GuildId);
|
|
||||||
|
|
||||||
// Filter and order channels
|
var channels = guildChannels
|
||||||
channels = channels.Where(c => c.Type.IsExportable()).OrderBy(c => c.Name).ToArray();
|
.Where(c => c.Type.IsExportable())
|
||||||
|
.OrderBy(c => c.Name)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
// Loop through channels
|
await ExportMultipleAsync(console, 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.");
|
|
||||||
}
|
|
||||||
catch (DomainException ex)
|
|
||||||
{
|
|
||||||
console.Error.WriteLine(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,13 +20,13 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
|
|
||||||
public override async ValueTask ExecuteAsync(IConsole console)
|
public override async ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
// Get channels
|
var guildChannels = await DataService.GetGuildChannelsAsync(Token, GuildId);
|
||||||
var channels = await DataService.GetGuildChannelsAsync(Token, GuildId);
|
|
||||||
|
|
||||||
// Filter and order channels
|
var channels = guildChannels
|
||||||
channels = channels.Where(c => c.Type.IsExportable()).OrderBy(c => c.Name).ToArray();
|
.Where(c => c.Type.IsExportable())
|
||||||
|
.OrderBy(c => c.Name)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
// Print result
|
|
||||||
foreach (var channel in channels)
|
foreach (var channel in channels)
|
||||||
console.Output.WriteLine($"{channel.Id} | {channel.Name}");
|
console.Output.WriteLine($"{channel.Id} | {channel.Name}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,13 +16,9 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
|
|
||||||
public override async ValueTask ExecuteAsync(IConsole console)
|
public override async ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
// Get channels
|
var directMessageChannels = await DataService.GetDirectMessageChannelsAsync(Token);
|
||||||
var channels = 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)
|
foreach (var channel in channels)
|
||||||
console.Output.WriteLine($"{channel.Id} | {channel.Name}");
|
console.Output.WriteLine($"{channel.Id} | {channel.Name}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,14 +16,9 @@ namespace DiscordChatExporter.Cli.Commands
|
|||||||
|
|
||||||
public override async ValueTask ExecuteAsync(IConsole console)
|
public override async ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
// Get guilds
|
|
||||||
var guilds = await DataService.GetUserGuildsAsync(Token);
|
var guilds = await DataService.GetUserGuildsAsync(Token);
|
||||||
|
|
||||||
// Order guilds
|
foreach (var guild in guilds.OrderBy(g => g.Name))
|
||||||
guilds = guilds.OrderBy(g => g.Name).ToArray();
|
|
||||||
|
|
||||||
// Print result
|
|
||||||
foreach (var guild in guilds)
|
|
||||||
console.Output.WriteLine($"{guild.Id} | {guild.Name}");
|
console.Output.WriteLine($"{guild.Id} | {guild.Name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CliFx" Version="1.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="Microsoft.Extensions.DependencyInjection" Version="3.1.1" />
|
||||||
<PackageReference Include="Tyrrrz.Extensions" Version="1.6.5" />
|
<PackageReference Include="Tyrrrz.Extensions" Version="1.6.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CliFx;
|
using CliFx;
|
||||||
using DiscordChatExporter.Cli.Commands;
|
using DiscordChatExporter.Cli.Commands;
|
||||||
|
|||||||
@@ -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
|
public partial class Guild : IHasId
|
||||||
{
|
{
|
||||||
@@ -10,13 +15,19 @@
|
|||||||
|
|
||||||
public string? IconHash { get; }
|
public string? IconHash { get; }
|
||||||
|
|
||||||
|
public IReadOnlyList<Role> Roles { get; }
|
||||||
|
|
||||||
|
public Dictionary<string, Member?> Members { get; }
|
||||||
|
|
||||||
public string IconUrl { 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;
|
Id = id;
|
||||||
Name = name;
|
Name = name;
|
||||||
IconHash = iconHash;
|
IconHash = iconHash;
|
||||||
|
Roles = roles;
|
||||||
|
Members = new Dictionary<string, Member?>();
|
||||||
|
|
||||||
IconUrl = GetIconUrl(id, iconHash);
|
IconUrl = GetIconUrl(id, iconHash);
|
||||||
}
|
}
|
||||||
@@ -26,13 +37,23 @@
|
|||||||
|
|
||||||
public partial class Guild
|
public partial class Guild
|
||||||
{
|
{
|
||||||
public static string GetIconUrl(string id, string? iconHash)
|
public static string GetUserColor(Guild guild, User user) =>
|
||||||
{
|
guild.Members.GetValueOrDefault(user.Id, null)
|
||||||
return !string.IsNullOrWhiteSpace(iconHash)
|
?.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/icons/{id}/{iconHash}.png"
|
||||||
: "https://cdn.discordapp.com/embed/avatars/0.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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace DiscordChatExporter.Core.Models
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Core.Models
|
||||||
{
|
{
|
||||||
// https://discordapp.com/developers/docs/topics/permissions#role-object
|
// https://discordapp.com/developers/docs/topics/permissions#role-object
|
||||||
|
|
||||||
@@ -8,10 +10,20 @@
|
|||||||
|
|
||||||
public string Name { get; }
|
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;
|
Id = id;
|
||||||
Name = name;
|
Name = name;
|
||||||
|
Color = color;
|
||||||
|
Position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() => Name;
|
public override string ToString() => Name;
|
||||||
@@ -19,6 +31,6 @@
|
|||||||
|
|
||||||
public partial class Role
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,6 +75,10 @@ namespace DiscordChatExporter.Core.Rendering.Formatters
|
|||||||
scriptObject.Import("FormatMarkdown",
|
scriptObject.Import("FormatMarkdown",
|
||||||
new Func<string, string>(m => HtmlRenderingLogic.FormatMarkdown(Context, m)));
|
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
|
// Push model
|
||||||
templateContext.PushGlobal(scriptObject);
|
templateContext.PushGlobal(scriptObject);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
@@ -97,7 +98,9 @@ namespace DiscordChatExporter.Core.Rendering.Logic
|
|||||||
var user = context.MentionableUsers.FirstOrDefault(u => u.Id == mentionNode.Id) ??
|
var user = context.MentionableUsers.FirstOrDefault(u => u.Id == mentionNode.Id) ??
|
||||||
User.CreateUnknownUser(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
|
// Channel mention node
|
||||||
@@ -114,8 +117,11 @@ namespace DiscordChatExporter.Core.Rendering.Logic
|
|||||||
{
|
{
|
||||||
var role = context.MentionableRoles.FirstOrDefault(r => r.Id == mentionNode.Id) ??
|
var role = context.MentionableRoles.FirstOrDefault(r => r.Id == mentionNode.Id) ??
|
||||||
Role.CreateDeletedRole(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
|
// Make emoji large if it's jumbo
|
||||||
var jumboableCssClass = isJumbo ? "emoji--large" : null;
|
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
|
// Link node
|
||||||
|
|||||||
@@ -82,6 +82,10 @@ img {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.mention {
|
.mention {
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 0 2px;
|
||||||
|
color: #7289da;
|
||||||
|
background: rgba(114, 137, 218, .1);
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,10 +26,6 @@ a {
|
|||||||
color: #b9bbbe !important;
|
color: #b9bbbe !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mention {
|
|
||||||
color: #7289da;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* === Preamble === */
|
/* === Preamble === */
|
||||||
|
|
||||||
.preamble__entry {
|
.preamble__entry {
|
||||||
|
|||||||
@@ -27,11 +27,6 @@ a {
|
|||||||
color: #657b83 !important;
|
color: #657b83 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mention {
|
|
||||||
background-color: #f1f3fb;
|
|
||||||
color: #7289da;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Preamble */
|
/* Preamble */
|
||||||
|
|
||||||
.preamble__entry {
|
.preamble__entry {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="chatlog__messages">
|
<div class="chatlog__messages">
|
||||||
{{~ # Author name and timestamp ~}}
|
{{~ # 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 ~}}
|
{{~ # Bot tag ~}}
|
||||||
{{~ if MessageGroup.Author.IsBot ~}}
|
{{~ if MessageGroup.Author.IsBot ~}}
|
||||||
|
|||||||
@@ -21,13 +21,23 @@ namespace DiscordChatExporter.Core.Services
|
|||||||
return new User(id, discriminator, name, avatarHash, isBot);
|
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)
|
private Guild ParseGuild(JToken json)
|
||||||
{
|
{
|
||||||
var id = json["id"]!.Value<string>();
|
var id = json["id"]!.Value<string>();
|
||||||
var name = json["name"]!.Value<string>();
|
var name = json["name"]!.Value<string>();
|
||||||
var iconHash = json["icon"]!.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)
|
private Channel ParseChannel(JToken json)
|
||||||
@@ -64,8 +74,10 @@ namespace DiscordChatExporter.Core.Services
|
|||||||
{
|
{
|
||||||
var id = json["id"]!.Value<string>();
|
var id = json["id"]!.Value<string>();
|
||||||
var name = json["name"]!.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)
|
private Attachment ParseAttachment(JToken json)
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ namespace DiscordChatExporter.Core.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async Task<JToken> GetApiResponseAsync(AuthToken token, string route)
|
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 () =>
|
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
|
// We throw our own exception here because default one doesn't have status code
|
||||||
if (!response.IsSuccessStatusCode)
|
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();
|
var jsonRaw = await response.Content.ReadAsStringAsync();
|
||||||
return JToken.Parse(jsonRaw);
|
return JToken.Parse(jsonRaw);
|
||||||
@@ -74,6 +82,15 @@ namespace DiscordChatExporter.Core.Services
|
|||||||
return guild;
|
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)
|
public async Task<Channel> GetChannelAsync(AuthToken token, string channelId)
|
||||||
{
|
{
|
||||||
var response = await GetApiResponseAsync(token, $"channels/{channelId}");
|
var response = await GetApiResponseAsync(token, $"channels/{channelId}");
|
||||||
@@ -97,10 +114,11 @@ namespace DiscordChatExporter.Core.Services
|
|||||||
if (!response.HasValues)
|
if (!response.HasValues)
|
||||||
yield break;
|
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;
|
yield return await GetGuildAsync(token, guildId);
|
||||||
afterId = guild.Id;
|
afterId = guildId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -125,18 +143,6 @@ namespace DiscordChatExporter.Core.Services
|
|||||||
return channels;
|
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)
|
private async Task<Message> GetLastMessageAsync(AuthToken token, string channelId, DateTimeOffset? before = null)
|
||||||
{
|
{
|
||||||
var route = $"channels/{channelId}/messages?limit=1";
|
var route = $"channels/{channelId}/messages?limit=1";
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace DiscordChatExporter.Core.Services
|
|||||||
// Create context
|
// Create context
|
||||||
var mentionableUsers = new HashSet<User>(IdBasedEqualityComparer.Instance);
|
var mentionableUsers = new HashSet<User>(IdBasedEqualityComparer.Instance);
|
||||||
var mentionableChannels = await _dataService.GetGuildChannelsAsync(token, guild.Id);
|
var mentionableChannels = await _dataService.GetGuildChannelsAsync(token, guild.Id);
|
||||||
var mentionableRoles = await _dataService.GetGuildRolesAsync(token, guild.Id);
|
var mentionableRoles = guild.Roles;
|
||||||
|
|
||||||
var context = new RenderContext
|
var context = new RenderContext
|
||||||
(
|
(
|
||||||
@@ -50,8 +50,21 @@ namespace DiscordChatExporter.Core.Services
|
|||||||
await foreach (var message in _dataService.GetMessagesAsync(token, channel.Id, after, before, progress))
|
await foreach (var message in _dataService.GetMessagesAsync(token, channel.Id, after, before, progress))
|
||||||
{
|
{
|
||||||
// Add encountered users to the list of mentionable users
|
// Add encountered users to the list of mentionable users
|
||||||
mentionableUsers.Add(message.Author);
|
var encounteredUsers = new List<User>();
|
||||||
mentionableUsers.AddRange(message.MentionedUsers);
|
encounteredUsers.Add(message.Author);
|
||||||
|
encounteredUsers.AddRange(message.MentionedUsers);
|
||||||
|
|
||||||
|
mentionableUsers.AddRange(encounteredUsers);
|
||||||
|
|
||||||
|
foreach (User u in encounteredUsers)
|
||||||
|
{
|
||||||
|
if(!guild.Members.ContainsKey(u.Id))
|
||||||
|
{
|
||||||
|
var member = await _dataService.GetGuildMemberAsync(token, guild.Id, u.Id);
|
||||||
|
guild.Members[u.Id] = member;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Render message
|
// Render message
|
||||||
await renderer.RenderMessageAsync(message);
|
await renderer.RenderMessageAsync(message);
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ namespace DiscordChatExporter.Core.Services
|
|||||||
|
|
||||||
public bool IsTokenPersisted { get; set; } = true;
|
public bool IsTokenPersisted { get; set; } = true;
|
||||||
|
|
||||||
|
public int ParallelLimit { get; set; } = 1;
|
||||||
|
|
||||||
public AuthToken? LastToken { get; set; }
|
public AuthToken? LastToken { get; set; }
|
||||||
|
|
||||||
public ExportFormat LastExportFormat { get; set; } = ExportFormat.HtmlDark;
|
public ExportFormat LastExportFormat { get; set; } = ExportFormat.HtmlDark;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
<Target Name="Format XAML" AfterTargets="BeforeBuild">
|
<Target Name="Format XAML" AfterTargets="BeforeBuild">
|
||||||
<Exec Command="dotnet tool restore" />
|
<Exec Command="dotnet tool restore" />
|
||||||
<Exec Command="dotnet xstyler -r -d "$(MSBuildProjectDirectory)"" />
|
<Exec Command="dotnet xstyler -r -d ." />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -5,13 +5,13 @@ namespace DiscordChatExporter.Gui.ViewModels.Components
|
|||||||
{
|
{
|
||||||
public partial class ChannelViewModel : PropertyChangedBase
|
public partial class ChannelViewModel : PropertyChangedBase
|
||||||
{
|
{
|
||||||
public Channel Model { get; set; }
|
public Channel? Model { get; set; }
|
||||||
|
|
||||||
public string? Category { get; set; }
|
public string? Category { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class ChannelViewModel
|
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 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 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 DialogManager _dialogManager;
|
||||||
private readonly SettingsService _settingsService;
|
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; }
|
public string? OutputPath { get; set; }
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
|
|||||||
var channel = Channels.Single();
|
var channel = Channels.Single();
|
||||||
|
|
||||||
// Generate default file name
|
// Generate default file name
|
||||||
var defaultFileName = ExportLogic.GetDefaultExportFileName(SelectedFormat, Guild, channel, After, Before);
|
var defaultFileName = ExportLogic.GetDefaultExportFileName(SelectedFormat, Guild!, channel!, After, Before);
|
||||||
|
|
||||||
// Generate filter
|
// Generate filter
|
||||||
var ext = SelectedFormat.GetFileExtension();
|
var ext = SelectedFormat.GetFileExtension();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using DiscordChatExporter.Core.Services;
|
using DiscordChatExporter.Core.Services;
|
||||||
using DiscordChatExporter.Gui.ViewModels.Framework;
|
using DiscordChatExporter.Gui.ViewModels.Framework;
|
||||||
|
using Tyrrrz.Extensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Gui.ViewModels.Dialogs
|
namespace DiscordChatExporter.Gui.ViewModels.Dialogs
|
||||||
{
|
{
|
||||||
@@ -25,6 +26,12 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
|
|||||||
set => _settingsService.IsTokenPersisted = value;
|
set => _settingsService.IsTokenPersisted = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int ParallelLimit
|
||||||
|
{
|
||||||
|
get => _settingsService.ParallelLimit;
|
||||||
|
set => _settingsService.ParallelLimit = value.Clamp(1, 10);
|
||||||
|
}
|
||||||
|
|
||||||
public SettingsViewModel(SettingsService settingsService)
|
public SettingsViewModel(SettingsService settingsService)
|
||||||
{
|
{
|
||||||
_settingsService = settingsService;
|
_settingsService = settingsService;
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ namespace DiscordChatExporter.Gui.ViewModels.Framework
|
|||||||
{
|
{
|
||||||
public abstract class DialogScreen<T> : PropertyChangedBase
|
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;
|
public event EventHandler? Closed;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DiscordChatExporter.Core.Models;
|
using DiscordChatExporter.Core.Models;
|
||||||
using DiscordChatExporter.Core.Models.Exceptions;
|
using DiscordChatExporter.Core.Models.Exceptions;
|
||||||
@@ -178,7 +179,7 @@ namespace DiscordChatExporter.Gui.ViewModels
|
|||||||
// Create guild view model
|
// Create guild view model
|
||||||
var guildViewModel = _viewModelFactory.CreateGuildViewModel(guild,
|
var guildViewModel = _viewModelFactory.CreateGuildViewModel(guild,
|
||||||
channelViewModels.OrderBy(c => c.Category)
|
channelViewModels.OrderBy(c => c.Category)
|
||||||
.ThenBy(c => c.Model.Name)
|
.ThenBy(c => c.Model!.Name)
|
||||||
.ToArray());
|
.ToArray());
|
||||||
|
|
||||||
// Add to list
|
// Add to list
|
||||||
@@ -210,7 +211,7 @@ namespace DiscordChatExporter.Gui.ViewModels
|
|||||||
// Create guild view model
|
// Create guild view model
|
||||||
var guildViewModel = _viewModelFactory.CreateGuildViewModel(guild,
|
var guildViewModel = _viewModelFactory.CreateGuildViewModel(guild,
|
||||||
channelViewModels.OrderBy(c => c.Category)
|
channelViewModels.OrderBy(c => c.Category)
|
||||||
.ThenBy(c => c.Model.Name)
|
.ThenBy(c => c.Model!.Name)
|
||||||
.ToArray());
|
.ToArray());
|
||||||
|
|
||||||
// Add to list
|
// Add to list
|
||||||
@@ -256,18 +257,21 @@ namespace DiscordChatExporter.Gui.ViewModels
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Create a progress operation for each channel to export
|
// 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
|
// Export channels
|
||||||
var successfulExportCount = 0;
|
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 operation = operations[i];
|
||||||
var channel = dialog.Channels[i];
|
|
||||||
|
await semaphore.WaitAsync();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _exportService.ExportChatLogAsync(token, dialog.Guild, channel,
|
await _exportService.ExportChatLogAsync(token, dialog.Guild!, channel!,
|
||||||
dialog.OutputPath!, dialog.SelectedFormat, dialog.PartitionLimit,
|
dialog.OutputPath!, dialog.SelectedFormat, dialog.PartitionLimit,
|
||||||
dialog.After, dialog.Before, operation);
|
dialog.After, dialog.Before, operation);
|
||||||
|
|
||||||
@@ -275,11 +279,11 @@ namespace DiscordChatExporter.Gui.ViewModels
|
|||||||
}
|
}
|
||||||
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden)
|
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)
|
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)
|
catch (DomainException ex)
|
||||||
{
|
{
|
||||||
@@ -288,8 +292,9 @@ namespace DiscordChatExporter.Gui.ViewModels
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
operation.Dispose();
|
operation.Dispose();
|
||||||
|
semaphore.Release();
|
||||||
}
|
}
|
||||||
}
|
}));
|
||||||
|
|
||||||
// Notify of overall completion
|
// Notify of overall completion
|
||||||
if (successfulExportCount > 0)
|
if (successfulExportCount > 0)
|
||||||
|
|||||||
@@ -56,6 +56,21 @@
|
|||||||
IsChecked="{Binding IsTokenPersisted}" />
|
IsChecked="{Binding IsTokenPersisted}" />
|
||||||
</DockPanel>
|
</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 -->
|
<!-- Save button -->
|
||||||
<Button
|
<Button
|
||||||
Margin="8"
|
Margin="8"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<Version>2.18</Version>
|
<Version>2.19</Version>
|
||||||
<Company>Tyrrrz</Company>
|
<Company>Tyrrrz</Company>
|
||||||
<Copyright>Copyright (c) Alexey Golub</Copyright>
|
<Copyright>Copyright (c) Alexey Golub</Copyright>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
|
|||||||
Reference in New Issue
Block a user