mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-02-02 16:19:12 +00:00
Replace --include-threads and --include-archived-threads with a single multi-value option
Related to #1119
This commit is contained in:
@@ -246,7 +246,9 @@ public abstract class ExportCommandBase : DiscordCommandBase
|
||||
|
||||
foreach (var (channel, error) in errorsByChannel)
|
||||
{
|
||||
await console.Error.WriteAsync($"{channel.ParentNameWithFallback} / {channel.Name}: ");
|
||||
await console.Error.WriteAsync(
|
||||
$"{channel.ParentNameWithFallback} / {channel.Name}: "
|
||||
);
|
||||
|
||||
using (console.WithForegroundColor(ConsoleColor.Red))
|
||||
await console.Error.WriteLineAsync(error);
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using CliFx.Extensibility;
|
||||
using DiscordChatExporter.Cli.Commands.Shared;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands.Converters;
|
||||
|
||||
internal class ThreadInclusionBindingConverter : BindingConverter<ThreadInclusion>
|
||||
{
|
||||
public override ThreadInclusion Convert(string? rawValue)
|
||||
{
|
||||
// Empty or unset value is treated as 'active' to match the previous behavior
|
||||
if (string.IsNullOrWhiteSpace(rawValue))
|
||||
return ThreadInclusion.Active;
|
||||
|
||||
// Boolean 'true' is treated as 'active', boolean 'false' is treated as 'none'
|
||||
if (bool.TryParse(rawValue, out var boolValue))
|
||||
return boolValue ? ThreadInclusion.Active : ThreadInclusion.None;
|
||||
|
||||
// Otherwise, fall back to regular enum parsing
|
||||
return Enum.Parse<ThreadInclusion>(rawValue, true);
|
||||
}
|
||||
}
|
||||
@@ -7,19 +7,15 @@ internal class TruthyBooleanBindingConverter : BindingConverter<bool>
|
||||
{
|
||||
public override bool Convert(string? rawValue)
|
||||
{
|
||||
// Null is still considered true, to match the base behavior
|
||||
if (rawValue is null)
|
||||
// Empty or unset value is treated as 'true', to match the regular boolean behavior
|
||||
if (string.IsNullOrWhiteSpace(rawValue))
|
||||
return true;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(rawValue))
|
||||
return false;
|
||||
// Number '1' is treated as 'true', other numbers are treated as 'false'
|
||||
if (int.TryParse(rawValue, CultureInfo.InvariantCulture, out var intValue))
|
||||
return intValue == 1;
|
||||
|
||||
if (bool.TryParse(rawValue, out var boolValue))
|
||||
return boolValue;
|
||||
|
||||
if (int.TryParse(rawValue, CultureInfo.InvariantCulture, out var intValue) && intValue == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
// Otherwise, fall back to regular boolean parsing
|
||||
return bool.Parse(rawValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ 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.Exceptions;
|
||||
@@ -25,11 +27,16 @@ public class ExportAllCommand : ExportCommandBase
|
||||
[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);
|
||||
|
||||
[CommandOption(
|
||||
"data-package",
|
||||
@@ -42,14 +49,6 @@ public class ExportAllCommand : ExportCommandBase
|
||||
{
|
||||
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 = new List<Channel>();
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
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;
|
||||
|
||||
@@ -18,24 +19,21 @@ public class ExportGuildCommand : ExportCommandBase
|
||||
[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 = new List<Channel>();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -44,7 +44,9 @@ public class GetDirectChannelsCommand : 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}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
DiscordChatExporter.Cli/Commands/Shared/ThreadInclusion.cs
Normal file
12
DiscordChatExporter.Cli/Commands/Shared/ThreadInclusion.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands.Shared;
|
||||
|
||||
[Flags]
|
||||
public enum ThreadInclusion
|
||||
{
|
||||
None = 0,
|
||||
Active = 1,
|
||||
Archived = 2,
|
||||
All = Active | Archived
|
||||
}
|
||||
Reference in New Issue
Block a user