From c422ac23512388e08e97c01e17e9e43231779626 Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Wed, 30 Aug 2023 18:43:12 +0300 Subject: [PATCH] Clean up --- .../Commands/Base/ExportCommandBase.cs | 6 ++---- ...ter.cs => ThreadInclusionModeBindingConverter.cs} | 10 +++++----- DiscordChatExporter.Cli/Commands/ExportAllCommand.cs | 12 ++++++------ .../Commands/ExportGuildCommand.cs | 8 ++++---- .../Commands/GetChannelsCommand.cs | 8 ++++---- .../{ThreadInclusion.cs => ThreadInclusionMode.cs} | 2 +- .../{ThreadInclusion.cs => ThreadInclusionMode.cs} | 2 +- DiscordChatExporter.Gui/Services/SettingsService.cs | 2 +- .../ViewModels/Components/DashboardViewModel.cs | 4 ++-- .../ViewModels/Dialogs/SettingsViewModel.cs | 10 +++++----- .../Views/Dialogs/SettingsView.xaml | 4 ++-- 11 files changed, 33 insertions(+), 35 deletions(-) rename DiscordChatExporter.Cli/Commands/Converters/{ThreadInclusionBindingConverter.cs => ThreadInclusionModeBindingConverter.cs} (58%) rename DiscordChatExporter.Cli/Commands/Shared/{ThreadInclusion.cs => ThreadInclusionMode.cs} (73%) rename DiscordChatExporter.Gui/Models/{ThreadInclusion.cs => ThreadInclusionMode.cs} (71%) diff --git a/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs b/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs index 54167ff..5612391 100644 --- a/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs +++ b/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs @@ -147,12 +147,10 @@ public abstract class ExportCommandBase : DiscordCommandBase var isValidOutputPath = // Anything is valid when exporting a single channel channels.Count <= 1 - || // When using template tokens, assume the user knows what they're doing - OutputPath.Contains('%') - || + || OutputPath.Contains('%') // Otherwise, require an existing directory or an unambiguous directory path - Directory.Exists(OutputPath) + || Directory.Exists(OutputPath) || PathEx.IsDirectoryPath(OutputPath); if (!isValidOutputPath) diff --git a/DiscordChatExporter.Cli/Commands/Converters/ThreadInclusionBindingConverter.cs b/DiscordChatExporter.Cli/Commands/Converters/ThreadInclusionModeBindingConverter.cs similarity index 58% rename from DiscordChatExporter.Cli/Commands/Converters/ThreadInclusionBindingConverter.cs rename to DiscordChatExporter.Cli/Commands/Converters/ThreadInclusionModeBindingConverter.cs index 0466e65..7857024 100644 --- a/DiscordChatExporter.Cli/Commands/Converters/ThreadInclusionBindingConverter.cs +++ b/DiscordChatExporter.Cli/Commands/Converters/ThreadInclusionModeBindingConverter.cs @@ -4,19 +4,19 @@ using DiscordChatExporter.Cli.Commands.Shared; namespace DiscordChatExporter.Cli.Commands.Converters; -internal class ThreadInclusionBindingConverter : BindingConverter +internal class ThreadInclusionModeBindingConverter : BindingConverter { - public override ThreadInclusion Convert(string? rawValue) + public override ThreadInclusionMode Convert(string? rawValue) { // Empty or unset value is treated as 'active' to match the previous behavior if (string.IsNullOrWhiteSpace(rawValue)) - return ThreadInclusion.Active; + return ThreadInclusionMode.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; + return boolValue ? ThreadInclusionMode.Active : ThreadInclusionMode.None; // Otherwise, fall back to regular enum parsing - return Enum.Parse(rawValue, true); + return Enum.Parse(rawValue, true); } } diff --git a/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs b/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs index 5a5cc0b..0d4df03 100644 --- a/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs @@ -30,9 +30,9 @@ public class ExportAllCommand : ExportCommandBase [CommandOption( "include-threads", Description = "Which types of threads should be included.", - Converter = typeof(ThreadInclusionBindingConverter) + Converter = typeof(ThreadInclusionModeBindingConverter) )] - public ThreadInclusion ThreadInclusion { get; init; } = ThreadInclusion.None; + public ThreadInclusionMode ThreadInclusionMode { get; init; } = ThreadInclusionMode.None; [CommandOption( "data-package", @@ -70,12 +70,12 @@ public class ExportAllCommand : ExportCommandBase } // Threads - if (ThreadInclusion != ThreadInclusion.None) + if (ThreadInclusionMode != ThreadInclusionMode.None) { await foreach ( var thread in Discord.GetGuildThreadsAsync( guild.Id, - ThreadInclusion == ThreadInclusion.All, + ThreadInclusionMode == ThreadInclusionMode.All, cancellationToken ) ) @@ -132,9 +132,9 @@ public class ExportAllCommand : ExportCommandBase channels.RemoveAll(c => c.Kind.IsGuild()); if (!IncludeVoiceChannels) channels.RemoveAll(c => c.Kind.IsVoice()); - if (ThreadInclusion == ThreadInclusion.None) + if (ThreadInclusionMode == ThreadInclusionMode.None) channels.RemoveAll(c => c.Kind.IsThread()); - if (ThreadInclusion != ThreadInclusion.All) + if (ThreadInclusionMode != ThreadInclusionMode.All) channels.RemoveAll(c => c.Kind.IsThread() && c.IsArchived); await ExportAsync(console, channels); diff --git a/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs b/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs index 20ad0f0..38f55c2 100644 --- a/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs @@ -22,9 +22,9 @@ public class ExportGuildCommand : ExportCommandBase [CommandOption( "include-threads", Description = "Which types of threads should be included.", - Converter = typeof(ThreadInclusionBindingConverter) + Converter = typeof(ThreadInclusionModeBindingConverter) )] - public ThreadInclusion ThreadInclusion { get; init; } = ThreadInclusion.None; + public ThreadInclusionMode ThreadInclusionMode { get; init; } = ThreadInclusionMode.None; public override async ValueTask ExecuteAsync(IConsole console) { @@ -48,12 +48,12 @@ public class ExportGuildCommand : ExportCommandBase } // Threads - if (ThreadInclusion != ThreadInclusion.None) + if (ThreadInclusionMode != ThreadInclusionMode.None) { await foreach ( var thread in Discord.GetGuildThreadsAsync( GuildId, - ThreadInclusion == ThreadInclusion.All, + ThreadInclusionMode == ThreadInclusionMode.All, cancellationToken ) ) diff --git a/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs b/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs index f74ca35..178b4d6 100644 --- a/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs @@ -24,9 +24,9 @@ public class GetChannelsCommand : DiscordCommandBase [CommandOption( "include-threads", Description = "Which types of threads should be included.", - Converter = typeof(ThreadInclusionBindingConverter) + Converter = typeof(ThreadInclusionModeBindingConverter) )] - public ThreadInclusion ThreadInclusion { get; init; } = ThreadInclusion.None; + public ThreadInclusionMode ThreadInclusionMode { get; init; } = ThreadInclusionMode.None; public override async ValueTask ExecuteAsync(IConsole console) { @@ -47,11 +47,11 @@ public class GetChannelsCommand : DiscordCommandBase .FirstOrDefault(); var threads = - ThreadInclusion != ThreadInclusion.None + ThreadInclusionMode != ThreadInclusionMode.None ? ( await Discord.GetGuildThreadsAsync( GuildId, - ThreadInclusion == ThreadInclusion.All, + ThreadInclusionMode == ThreadInclusionMode.All, cancellationToken ) ) diff --git a/DiscordChatExporter.Cli/Commands/Shared/ThreadInclusion.cs b/DiscordChatExporter.Cli/Commands/Shared/ThreadInclusionMode.cs similarity index 73% rename from DiscordChatExporter.Cli/Commands/Shared/ThreadInclusion.cs rename to DiscordChatExporter.Cli/Commands/Shared/ThreadInclusionMode.cs index afe201a..878cdff 100644 --- a/DiscordChatExporter.Cli/Commands/Shared/ThreadInclusion.cs +++ b/DiscordChatExporter.Cli/Commands/Shared/ThreadInclusionMode.cs @@ -1,6 +1,6 @@ namespace DiscordChatExporter.Cli.Commands.Shared; -public enum ThreadInclusion +public enum ThreadInclusionMode { None, Active, diff --git a/DiscordChatExporter.Gui/Models/ThreadInclusion.cs b/DiscordChatExporter.Gui/Models/ThreadInclusionMode.cs similarity index 71% rename from DiscordChatExporter.Gui/Models/ThreadInclusion.cs rename to DiscordChatExporter.Gui/Models/ThreadInclusionMode.cs index 98bc6d7..41e2162 100644 --- a/DiscordChatExporter.Gui/Models/ThreadInclusion.cs +++ b/DiscordChatExporter.Gui/Models/ThreadInclusionMode.cs @@ -1,6 +1,6 @@ namespace DiscordChatExporter.Gui.Models; -public enum ThreadInclusion +public enum ThreadInclusionMode { None, Active, diff --git a/DiscordChatExporter.Gui/Services/SettingsService.cs b/DiscordChatExporter.Gui/Services/SettingsService.cs index ba20113..6662b41 100644 --- a/DiscordChatExporter.Gui/Services/SettingsService.cs +++ b/DiscordChatExporter.Gui/Services/SettingsService.cs @@ -17,7 +17,7 @@ public partial class SettingsService : SettingsBase public bool IsTokenPersisted { get; set; } = true; - public ThreadInclusion ThreadInclusion { get; set; } = ThreadInclusion.None; + public ThreadInclusionMode ThreadInclusionMode { get; set; } = ThreadInclusionMode.None; public string DateFormat { get; set; } = "MM/dd/yyyy h:mm tt"; diff --git a/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs b/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs index e6e660f..8cd1217 100644 --- a/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs +++ b/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs @@ -170,12 +170,12 @@ public class DashboardViewModel : PropertyChangedBase } // Threads - if (_settingsService.ThreadInclusion != ThreadInclusion.None) + if (_settingsService.ThreadInclusionMode != ThreadInclusionMode.None) { await foreach ( var thread in _discord.GetGuildThreadsAsync( SelectedGuild.Id, - _settingsService.ThreadInclusion == ThreadInclusion.All + _settingsService.ThreadInclusionMode == ThreadInclusionMode.All ) ) { diff --git a/DiscordChatExporter.Gui/ViewModels/Dialogs/SettingsViewModel.cs b/DiscordChatExporter.Gui/ViewModels/Dialogs/SettingsViewModel.cs index 2ab0d82..0d22736 100644 --- a/DiscordChatExporter.Gui/ViewModels/Dialogs/SettingsViewModel.cs +++ b/DiscordChatExporter.Gui/ViewModels/Dialogs/SettingsViewModel.cs @@ -28,13 +28,13 @@ public class SettingsViewModel : DialogScreen set => _settingsService.IsTokenPersisted = value; } - public IReadOnlyList AvailableThreadInclusions { get; } = - Enum.GetValues(); + public IReadOnlyList AvailableThreadInclusions { get; } = + Enum.GetValues(); - public ThreadInclusion ThreadInclusion + public ThreadInclusionMode ThreadInclusionMode { - get => _settingsService.ThreadInclusion; - set => _settingsService.ThreadInclusion = value; + get => _settingsService.ThreadInclusionMode; + set => _settingsService.ThreadInclusionMode = value; } public string DateFormat diff --git a/DiscordChatExporter.Gui/Views/Dialogs/SettingsView.xaml b/DiscordChatExporter.Gui/Views/Dialogs/SettingsView.xaml index 45a7b7a..ced29e9 100644 --- a/DiscordChatExporter.Gui/Views/Dialogs/SettingsView.xaml +++ b/DiscordChatExporter.Gui/Views/Dialogs/SettingsView.xaml @@ -82,7 +82,7 @@ IsChecked="{Binding IsTokenPersisted}" /> - + + SelectedItem="{Binding ThreadInclusionMode}" />