Replace --include-threads and --include-archived-threads with a single multi-value option

Related to #1119
This commit is contained in:
Tyrrrz
2023-08-28 21:52:56 +03:00
parent 5f6e51f6fb
commit d430f77ae1
8 changed files with 83 additions and 52 deletions

View File

@@ -2,9 +2,10 @@
using System.Linq;
using System.Threading.Tasks;
using CliFx.Attributes;
using CliFx.Exceptions;
using CliFx.Infrastructure;
using DiscordChatExporter.Cli.Commands.Base;
using DiscordChatExporter.Cli.Commands.Converters;
using DiscordChatExporter.Cli.Commands.Shared;
using DiscordChatExporter.Core.Discord;
using DiscordChatExporter.Core.Discord.Data;
using DiscordChatExporter.Core.Utils.Extensions;
@@ -20,24 +21,21 @@ public class GetChannelsCommand : DiscordCommandBase
[CommandOption("include-vc", Description = "Include voice channels.")]
public bool IncludeVoiceChannels { get; init; } = true;
[CommandOption("include-threads", Description = "Include threads.")]
public bool IncludeThreads { get; init; } = false;
[CommandOption(
"include-threads",
Description = "Specifies which types of threads should be included.",
Converter = typeof(ThreadInclusionBindingConverter)
)]
public ThreadInclusion ThreadInclusion { get; init; } = ThreadInclusion.None;
[CommandOption("include-archived-threads", Description = "Include archived threads.")]
public bool IncludeArchivedThreads { get; init; } = false;
private bool IncludeThreads => ThreadInclusion != ThreadInclusion.None;
private bool IncludeArchivedThreads => ThreadInclusion.HasFlag(ThreadInclusion.Archived);
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))
@@ -77,7 +75,9 @@ public class GetChannelsCommand : DiscordCommandBase
// Channel category / name
using (console.WithForegroundColor(ConsoleColor.White))
await console.Output.WriteLineAsync($"{channel.ParentNameWithFallback} / {channel.Name}");
await console.Output.WriteLineAsync(
$"{channel.ParentNameWithFallback} / {channel.Name}"
);
var channelThreads = threads.Where(t => t.Parent?.Id == channel.Id).ToArray();
var channelThreadIdMaxLength = channelThreads