From cc92b2cbe6f3540d0ca126caa679d5e1b0bf5b11 Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Sun, 8 Jun 2025 22:53:10 +0300 Subject: [PATCH] More cleanup --- .../Commands/Base/ExportCommandBase.cs | 37 ++++++++++--------- .../Discord/DiscordClient.cs | 2 +- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs b/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs index 2d64bd00..09ab2691 100644 --- a/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs +++ b/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs @@ -147,9 +147,22 @@ public abstract class ExportCommandBase : DiscordCommandBase { var cancellationToken = console.RegisterCancellationHandler(); - var unwrappedChannels = new List(); - unwrappedChannels.AddRange(channels); - // Threads + // Asset reuse can only be enabled if the download assets option is set + // https://github.com/Tyrrrz/DiscordChatExporter/issues/425 + if (ShouldReuseAssets && !ShouldDownloadAssets) + { + throw new CommandException("Option --reuse-media cannot be used without --media."); + } + + // Assets directory can only be specified if the download assets option is set + if (!string.IsNullOrWhiteSpace(AssetsDirPath) && !ShouldDownloadAssets) + { + throw new CommandException("Option --media-dir cannot be used without --media."); + } + + var unwrappedChannels = new List(channels); + + // Unwrap threads if (ThreadInclusionMode != ThreadInclusionMode.None) { await console.Output.WriteLineAsync("Fetching threads..."); @@ -163,7 +176,7 @@ public abstract class ExportCommandBase : DiscordCommandBase { await foreach ( var thread in Discord.GetChannelThreadsAsync( - unwrappedChannels, + channels, ThreadInclusionMode == ThreadInclusionMode.All, Before, After, @@ -180,25 +193,13 @@ public abstract class ExportCommandBase : DiscordCommandBase } ); - // Remove unneeded forums, as they cannot be crawled directly. + // Remove forums, as they cannot be exported directly and their constituent threads + // have already been fetched. unwrappedChannels.RemoveAll(channel => channel.Kind == ChannelKind.GuildForum); await console.Output.WriteLineAsync($"Fetched {fetchedThreadsCount} thread(s)."); } - // Asset reuse can only be enabled if the download assets option is set - // https://github.com/Tyrrrz/DiscordChatExporter/issues/425 - if (ShouldReuseAssets && !ShouldDownloadAssets) - { - throw new CommandException("Option --reuse-media cannot be used without --media."); - } - - // Assets directory can only be specified if the download assets option is set - if (!string.IsNullOrWhiteSpace(AssetsDirPath) && !ShouldDownloadAssets) - { - throw new CommandException("Option --media-dir cannot be used without --media."); - } - // Make sure the user does not try to export multiple channels into one file. // Output path must either be a directory or contain template tokens for this to work. // https://github.com/Tyrrrz/DiscordChatExporter/issues/799 diff --git a/DiscordChatExporter.Core/Discord/DiscordClient.cs b/DiscordChatExporter.Core/Discord/DiscordClient.cs index b9bbdac2..5ac33d55 100644 --- a/DiscordChatExporter.Core/Discord/DiscordClient.cs +++ b/DiscordChatExporter.Core/Discord/DiscordClient.cs @@ -389,7 +389,7 @@ public class DiscordClient( } public async IAsyncEnumerable GetChannelThreadsAsync( - IEnumerable channels, + IReadOnlyList channels, bool includeArchived = false, Snowflake? before = null, Snowflake? after = null,