diff --git a/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs b/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs index 955f4d1..a85de3f 100644 --- a/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs @@ -1,6 +1,8 @@ -using System.Linq; +using System; +using System.Linq; using System.Threading.Tasks; using CliFx.Attributes; +using CliFx.Exceptions; using CliFx.Infrastructure; using DiscordChatExporter.Cli.Commands.Base; using DiscordChatExporter.Core.Discord; @@ -25,10 +27,30 @@ public class ExportGuildCommand : ExportCommandBase )] public bool IncludeVoiceChannels { get; init; } = true; + [CommandOption( + "include-threads", + Description = "Include threads." + )] + public bool IncludeThreads { get; init; } = false; + + [CommandOption( + "include-archived-threads", + Description = "Include archived threads." + )] + public bool IncludeArchivedThreads { get; init; } = false; + public override async ValueTask ExecuteAsync(IConsole console) { await base.ExecuteAsync(console); + // Cannot include archived threads without including active threads as well + if (IncludeArchivedThreads && !IncludeThreads) + { + throw new CommandException( + "Option --include-archived-threads can only be used when --include-threads is also specified." + ); + } + var cancellationToken = console.RegisterCancellationHandler(); await console.Output.WriteLineAsync("Fetching channels..."); @@ -38,6 +60,13 @@ public class ExportGuildCommand : ExportCommandBase .Where(c => IncludeVoiceChannels || !c.Kind.IsVoice()) .ToArray(); - await ExportAsync(console, channels); + var threads = IncludeThreads + ? await Discord.GetGuildThreadsAsync(GuildId, IncludeArchivedThreads, cancellationToken) + : Array.Empty(); + + await ExportAsync( + console, + channels.Concat(threads).ToArray() + ); } } \ No newline at end of file diff --git a/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs b/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs index 3565e24..6b2ef0f 100644 --- a/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Threading.Tasks; using CliFx.Attributes; +using CliFx.Exceptions; using CliFx.Infrastructure; using DiscordChatExporter.Cli.Commands.Base; using DiscordChatExporter.Core.Discord; @@ -28,18 +29,28 @@ public class GetChannelsCommand : DiscordCommandBase [CommandOption( "include-threads", - Description = "Include threads in the output." + Description = "Include threads." )] - public bool IncludeThreads { get; init; } + public bool IncludeThreads { get; init; } = false; [CommandOption( "include-archived-threads", - Description = "Include archived threads in the output." + Description = "Include archived threads." )] - public bool IncludeArchivedThreads { get; init; } + public bool IncludeArchivedThreads { get; init; } = false; public override async ValueTask ExecuteAsync(IConsole console) { + await base.ExecuteAsync(console); + + // Cannot include archived threads without including active threads as well + if (IncludeArchivedThreads && !IncludeThreads) + { + throw new CommandException( + "Option --include-archived-threads can only be used when --include-threads is also specified." + ); + } + var cancellationToken = console.RegisterCancellationHandler(); var channels = (await Discord.GetGuildChannelsAsync(GuildId, cancellationToken)) diff --git a/DiscordChatExporter.Cli/Commands/GetDirectChannelsCommand.cs b/DiscordChatExporter.Cli/Commands/GetDirectChannelsCommand.cs index 8a17ac0..6ae5e33 100644 --- a/DiscordChatExporter.Cli/Commands/GetDirectChannelsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/GetDirectChannelsCommand.cs @@ -14,6 +14,8 @@ public class GetDirectChannelsCommand : DiscordCommandBase { public override async ValueTask ExecuteAsync(IConsole console) { + await base.ExecuteAsync(console); + var cancellationToken = console.RegisterCancellationHandler(); var channels = (await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken)) diff --git a/DiscordChatExporter.Cli/Commands/GetGuildsCommand.cs b/DiscordChatExporter.Cli/Commands/GetGuildsCommand.cs index 4635f4b..0cb5c7e 100644 --- a/DiscordChatExporter.Cli/Commands/GetGuildsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/GetGuildsCommand.cs @@ -14,6 +14,8 @@ public class GetGuildsCommand : DiscordCommandBase { public override async ValueTask ExecuteAsync(IConsole console) { + await base.ExecuteAsync(console); + var cancellationToken = console.RegisterCancellationHandler(); var guilds = (await Discord.GetUserGuildsAsync(cancellationToken))