mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-23 11:16:59 -04:00
Clamp progress in DiscordClient.GetMessagesAsync(...)
This commit is contained in:
parent
f866c16355
commit
6f90c367b9
1 changed files with 18 additions and 5 deletions
|
@ -11,6 +11,7 @@ using DiscordChatExporter.Core.Utils;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
using JsonExtensions.Http;
|
using JsonExtensions.Http;
|
||||||
using JsonExtensions.Reading;
|
using JsonExtensions.Reading;
|
||||||
|
using Tyrrrz.Extensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Discord
|
namespace DiscordChatExporter.Core.Discord
|
||||||
{
|
{
|
||||||
|
@ -259,11 +260,23 @@ namespace DiscordChatExporter.Core.Discord
|
||||||
if (message.Timestamp > lastMessage.Timestamp)
|
if (message.Timestamp > lastMessage.Timestamp)
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
// Report progress based on the duration of parsed messages divided by total
|
// Report progress based on the duration of exported messages divided by total
|
||||||
progress?.Report(
|
if (progress is not null)
|
||||||
(message.Timestamp - firstMessage.Timestamp) /
|
{
|
||||||
(lastMessage.Timestamp - firstMessage.Timestamp)
|
var exportedDuration = (message.Timestamp - firstMessage.Timestamp).Duration();
|
||||||
);
|
var totalDuration = (lastMessage.Timestamp - firstMessage.Timestamp).Duration();
|
||||||
|
|
||||||
|
if (totalDuration > TimeSpan.Zero)
|
||||||
|
{
|
||||||
|
progress.Report(exportedDuration / totalDuration);
|
||||||
|
}
|
||||||
|
// Avoid division by zero if all messages have the exact same timestamp
|
||||||
|
// (which can happen easily if there's only one message in the channel)
|
||||||
|
else
|
||||||
|
{
|
||||||
|
progress.Report(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
yield return message;
|
yield return message;
|
||||||
currentAfter = message.Id;
|
currentAfter = message.Id;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue