mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-02-14 07:43:31 -07:00
Added UI options to enable the existing export search
The setting on whether the existing export search is enabled or not has been made configurable in both the CLI and the GUI (instead of being hardcoded): - A search-existing-exports option has been added to all CLI export commands, which enables the existing export search for the respective command. - A Search for existing exports option has been added to the GUI settings, which enables the existing export search for exports. Additionally, there have been several minor improvements: - The ConsoleProgressLogger has been fixed to interpolate given messages (previously, the square brackets in the default export file names could cause an exception). - The names of existing channel exports in log messages have been enclosed by quotation marks. - The setting on how to handle existing export files has been renamed from prev-export / Previous Export to export-exists / Export Exists.
This commit is contained in:
parent
90ed829375
commit
da3bcefbb9
|
|
@ -115,11 +115,18 @@ public abstract class ExportCommandBase : DiscordCommandBase
|
|||
}
|
||||
|
||||
[CommandOption(
|
||||
"prev-export",
|
||||
Description = "What the exporter should do if the channel had already been exported."
|
||||
"export-exists",
|
||||
Description = "What the exporter should do if a channel had already been exported."
|
||||
)]
|
||||
public ExportExistsHandling ExportExistsHandling { get; init; } = ExportExistsHandling.Abort;
|
||||
|
||||
[CommandOption(
|
||||
"search-existing-exports",
|
||||
Description = "Whether the target directory should be searched for existing export(s) of the channel(s). "
|
||||
+ "This is required to find an existing export if the channel, channel parent or guild name has changed."
|
||||
)]
|
||||
public bool SearchForExistingExports { get; init; }
|
||||
|
||||
[Obsolete("This option doesn't do anything. Kept for backwards compatibility.")]
|
||||
[CommandOption(
|
||||
"dateformat",
|
||||
|
|
@ -272,6 +279,7 @@ public abstract class ExportCommandBase : DiscordCommandBase
|
|||
After,
|
||||
Before,
|
||||
ExportExistsHandling,
|
||||
SearchForExistingExports,
|
||||
PartitionLimit,
|
||||
MessageFilter,
|
||||
ShouldFormatMarkdown,
|
||||
|
|
|
|||
|
|
@ -78,21 +78,21 @@ public class ConsoleProgressLogger(IAnsiConsole console) : ProgressLogger
|
|||
/// <remarks>The ConsoleProgressLogger logs the success message to the console.</remarks>
|
||||
public override void LogSuccess(ExportRequest request, string message)
|
||||
{
|
||||
LogMessage("SUCCESS", "[green]", request, message);
|
||||
LogMessage("SUCCESS", "green", request, message);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>The ConsoleProgressLogger logs the informational message to the console.</remarks>
|
||||
public override void LogInfo(ExportRequest request, string message)
|
||||
{
|
||||
LogMessage("INFO", "[default]", request, message);
|
||||
LogMessage("INFO", "default", request, message);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>The ConsoleProgressLogger logs the warning message to the console.</remarks>
|
||||
public override void LogWarning(ExportRequest request, string message)
|
||||
{
|
||||
LogMessage("WARNING", "[yellow]", request, message);
|
||||
LogMessage("WARNING", "yellow", request, message);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
|
@ -100,7 +100,7 @@ public class ConsoleProgressLogger(IAnsiConsole console) : ProgressLogger
|
|||
public override void LogError(ExportRequest? request, string message)
|
||||
{
|
||||
IncrementCounter(ExportResult.ExportError);
|
||||
LogMessage("ERROR", "[red]", request, message);
|
||||
LogMessage("ERROR", "red", request, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -120,8 +120,8 @@ public class ConsoleProgressLogger(IAnsiConsole console) : ProgressLogger
|
|||
channelInfo =
|
||||
request.Guild.Name + " / " + request.Channel.GetHierarchicalName() + " | ";
|
||||
|
||||
var logMessage = $"{color}{paddedCategory}{channelInfo}{message}[/]";
|
||||
console.MarkupLine(logMessage);
|
||||
FormattableString logMessage = $"[{color}]{paddedCategory}{channelInfo}{message}[/]";
|
||||
console.MarkupLineInterpolated(logMessage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -35,13 +35,11 @@ public class ChannelExporter(DiscordClient discord)
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO: Add a way for the user to choose the setting
|
||||
var searchForExistingExport = true;
|
||||
if (
|
||||
!DetectExistingExport(
|
||||
request,
|
||||
logger,
|
||||
searchForExistingExport,
|
||||
request.SearchForExistingExports,
|
||||
outputDirFilesDict,
|
||||
out var existingExportFile
|
||||
)
|
||||
|
|
@ -215,7 +213,7 @@ public class ChannelExporter(DiscordClient discord)
|
|||
logger.LogError(
|
||||
request,
|
||||
"Found multiple existing channel exports under different file names: "
|
||||
+ string.Join(", ", regexFiles)
|
||||
+ string.Join(", ", regexFiles.Select(fileName => $"\"{fileName}\""))
|
||||
+ "."
|
||||
);
|
||||
return false;
|
||||
|
|
@ -223,7 +221,7 @@ public class ChannelExporter(DiscordClient discord)
|
|||
|
||||
logger.LogInfo(
|
||||
request,
|
||||
"Found existing channel export under file name " + regexFiles[0] + "."
|
||||
$"Found existing channel export under file name \"{regexFiles[0]}\"."
|
||||
);
|
||||
existingExportFile = Path.Combine(request.OutputDirPath, regexFiles[0]);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ public partial class ExportRequest
|
|||
|
||||
public ExportExistsHandling ExportExistsHandling { get; }
|
||||
|
||||
public bool SearchForExistingExports { get; }
|
||||
|
||||
public Snowflake? LastPriorMessage { get; set; }
|
||||
|
||||
public PartitionLimit PartitionLimit { get; }
|
||||
|
|
@ -59,6 +61,7 @@ public partial class ExportRequest
|
|||
Snowflake? after,
|
||||
Snowflake? before,
|
||||
ExportExistsHandling exportExistsHandling,
|
||||
bool searchForExistingExports,
|
||||
PartitionLimit partitionLimit,
|
||||
MessageFilter messageFilter,
|
||||
bool shouldFormatMarkdown,
|
||||
|
|
@ -74,6 +77,7 @@ public partial class ExportRequest
|
|||
After = after;
|
||||
Before = before;
|
||||
ExportExistsHandling = exportExistsHandling;
|
||||
SearchForExistingExports = searchForExistingExports;
|
||||
PartitionLimit = partitionLimit;
|
||||
MessageFilter = messageFilter;
|
||||
ShouldFormatMarkdown = shouldFormatMarkdown;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@ public partial class SettingsService()
|
|||
[ObservableProperty]
|
||||
public partial ExportExistsHandling ExportExistsHandling { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial bool SearchForExistingExports { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial string? Locale { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -272,6 +272,7 @@ public partial class DashboardViewModel : ViewModelBase
|
|||
dialog.After?.Pipe(timestamp => Snowflake.FromDate(timestamp, true)),
|
||||
dialog.Before?.Pipe(timestamp => Snowflake.FromDate(timestamp)),
|
||||
_settingsService.ExportExistsHandling,
|
||||
_settingsService.SearchForExistingExports,
|
||||
dialog.PartitionLimit,
|
||||
dialog.MessageFilter,
|
||||
dialog.ShouldFormatMarkdown,
|
||||
|
|
|
|||
|
|
@ -71,6 +71,12 @@ public class SettingsViewModel : DialogViewModelBase
|
|||
set => _settingsService.ExportExistsHandling = value;
|
||||
}
|
||||
|
||||
public bool SearchForExistingExports
|
||||
{
|
||||
get => _settingsService.SearchForExistingExports;
|
||||
set => _settingsService.SearchForExistingExports = value;
|
||||
}
|
||||
|
||||
// These items have to be non-nullable because Avalonia ComboBox doesn't allow a null value to be selected
|
||||
public IReadOnlyList<string> AvailableLocales { get; } =
|
||||
[
|
||||
|
|
|
|||
|
|
@ -136,14 +136,23 @@
|
|||
<DockPanel
|
||||
Margin="16,8"
|
||||
LastChildFill="False"
|
||||
ToolTip.Tip="What the exporter should do if the channel had already been exported">
|
||||
<TextBlock DockPanel.Dock="Left" Text="Previous Export" />
|
||||
ToolTip.Tip="What the exporter should do if a channel had already been exported">
|
||||
<TextBlock DockPanel.Dock="Left" Text="Export exists" />
|
||||
<ComboBox
|
||||
Width="150"
|
||||
DockPanel.Dock="Right"
|
||||
ItemsSource="{Binding AvailableExportExistsHandlingOptions}"
|
||||
SelectedItem="{Binding ExportExistsHandling}" />
|
||||
</DockPanel>
|
||||
|
||||
<!-- Search for existing exports -->
|
||||
<DockPanel
|
||||
Margin="16,8"
|
||||
LastChildFill="False"
|
||||
ToolTip.Tip="Whether the target directory should be searched for existing export(s) of the channel(s).
This is required to find an existing export if the channel, channel parent or guild name has changed.">
|
||||
<TextBlock DockPanel.Dock="Left" Text="Search for existing exports" />
|
||||
<ToggleSwitch DockPanel.Dock="Right" IsChecked="{Binding SearchForExistingExports}" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
|
|
|
|||
Loading…
Reference in a new issue