From ad2dab2157b5b83f0475bc7e57c20616ef806da0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Slatinsk=C3=BD?= <43640724+slatinsky@users.noreply.github.com> Date: Sun, 8 Oct 2023 22:56:39 +0200 Subject: [PATCH] Add progress to fetching channels step (#1131) --- .../Commands/ExportAllCommand.cs | 47 +++++++++++++------ .../Commands/ExportGuildCommand.cs | 43 ++++++++++++----- 2 files changed, 64 insertions(+), 26 deletions(-) diff --git a/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs b/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs index 416a69f..7c58117 100644 --- a/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.IO.Compression; +using System.Linq; using System.Text.Json; using System.Threading.Tasks; using CliFx.Attributes; @@ -12,6 +13,7 @@ using DiscordChatExporter.Core.Discord; using DiscordChatExporter.Core.Discord.Data; using DiscordChatExporter.Core.Exceptions; using JsonExtensions.Reading; +using Spectre.Console; namespace DiscordChatExporter.Cli.Commands; @@ -51,10 +53,10 @@ public class ExportAllCommand : ExportCommandBase // Pull from the API if (string.IsNullOrWhiteSpace(DataPackageFilePath)) { - await console.Output.WriteLineAsync("Fetching channels..."); - await foreach (var guild in Discord.GetUserGuildsAsync(cancellationToken)) { + await console.Output.WriteLineAsync($"Fetching channels for guild '{guild.Name}'..."); + // Regular channels await foreach ( var channel in Discord.GetGuildChannelsAsync(guild.Id, cancellationToken) @@ -69,21 +71,38 @@ public class ExportAllCommand : ExportCommandBase channels.Add(channel); } + await console.Output.WriteLineAsync($" Found {channels.Count} channels."); + // Threads if (ThreadInclusionMode != ThreadInclusionMode.None) { - await foreach ( - var thread in Discord.GetGuildThreadsAsync( - guild.Id, - ThreadInclusionMode == ThreadInclusionMode.All, - Before, - After, - cancellationToken - ) - ) - { - channels.Add(thread); - } + AnsiConsole.MarkupLine("Fetching threads..."); + await AnsiConsole + .Status() + .StartAsync( + "Found 0 threads.", + async ctx => + { + await foreach ( + var thread in Discord.GetGuildThreadsAsync( + guild.Id, + ThreadInclusionMode == ThreadInclusionMode.All, + Before, + After, + cancellationToken + ) + ) + { + channels.Add(thread); + ctx.Status( + $"Found {channels.Count(channel => channel.IsThread)} threads: {thread.GetHierarchicalName()}" + ); + } + } + ); + await console.Output.WriteLineAsync( + $" Found {channels.Count(channel => channel.IsThread)} threads." + ); } } } diff --git a/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs b/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs index c49079a..7e316d5 100644 --- a/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using CliFx.Attributes; using CliFx.Infrastructure; @@ -7,6 +8,7 @@ using DiscordChatExporter.Cli.Commands.Converters; using DiscordChatExporter.Cli.Commands.Shared; using DiscordChatExporter.Core.Discord; using DiscordChatExporter.Core.Discord.Data; +using Spectre.Console; namespace DiscordChatExporter.Cli.Commands; @@ -47,21 +49,38 @@ public class ExportGuildCommand : ExportCommandBase channels.Add(channel); } + await console.Output.WriteLineAsync($" Found {channels.Count} channels."); + // Threads if (ThreadInclusionMode != ThreadInclusionMode.None) { - await foreach ( - var thread in Discord.GetGuildThreadsAsync( - GuildId, - ThreadInclusionMode == ThreadInclusionMode.All, - Before, - After, - cancellationToken - ) - ) - { - channels.Add(thread); - } + AnsiConsole.MarkupLine("Fetching threads..."); + await AnsiConsole + .Status() + .StartAsync( + "Found 0 threads.", + async ctx => + { + await foreach ( + var thread in Discord.GetGuildThreadsAsync( + GuildId, + ThreadInclusionMode == ThreadInclusionMode.All, + Before, + After, + cancellationToken + ) + ) + { + channels.Add(thread); + ctx.Status( + $"Found {channels.Count(channel => channel.IsThread)} threads: {thread.GetHierarchicalName()}" + ); + } + } + ); + await console.Output.WriteLineAsync( + $" Found {channels.Count(channel => channel.IsThread)} threads." + ); } await ExportAsync(console, channels);