Closed slatinsky closed 11 months ago
Probably can optimize this too 😁
I'll do it
Suggestion: instead of tracking progress separately, can just do Found {channels.Count(c => c.IsThread)} threads. Slower, but would avoid extra business logic (i.e. off-by-one errors are likely here) and wouldn't matter on top of already heavy I/O requests anyway.
I agree
What's the PadRight/Substring for? Not super clear.
Let's assume, that the first message is
Found 1 threads. general - My first thread
and the second message is
Found 2 threads. general - hello
if we don't use PadRight/Substring, then the second message would look like this in the terminal:
Found 2 threads. general - hellorst thread
PadRight
pads the string with spaces to the right, so that the second message would always overwrite the first one. Substring
makes sure that it never overflows.
Also, we print one progress message for all channels, but multiple messages for threads?
Yes, because to get main channels, we need only one request. But to get threads, we need to make multiple request (at least one per channel)
Other notes:
If we could somehow get currently processed channel index and channels.Count from Discord.GetGuildThreadsAsync
method, we could print more fancy progress bar.
progress: channelIndex / channels.Count * 100
(for this we would also need to merge the loop foreach (var channel in channels)
in DiscordClient.cs
to process active and archived threads at the same time)
@slatinsky could we maybe use the Status
display from Spectre.Console
? We already use this package for progress reporting.
https://spectreconsole.net/live/status
This could clean up all the padright stuff.
in the latest changes, I have added your suggestions to the code and rewritten it to use status from Spectre.Console. Also latest changes from master branch were merged to prevent merge conflicts
Tested manually - cli, exportall
and exportguild
Thank you!
Fetching channels...
step takes a while after thread export option (--include-threads
) was introduced. The process may seem to be stuck to the user.This pull request adds a simple status information to
exportguild
andexportall
commands.exportguild example:
exportall example:
exportall
is similar toexportguild
but it prints the guild nameBoth commands show last parent channel name + thread name while in the process of fetching threads: