mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-12 09:53:04 +00:00
Print archived threads only if explicitly requested in the channels command
This commit is contained in:
@@ -16,7 +16,7 @@ public partial record Channel(
|
||||
int? Position,
|
||||
string? IconUrl,
|
||||
string? Topic,
|
||||
bool IsActive,
|
||||
bool IsArchived,
|
||||
Snowflake? LastMessageId) : IHasId
|
||||
{
|
||||
// Used for visual backwards-compatibility with old exports, where
|
||||
@@ -77,10 +77,10 @@ public partial record Channel
|
||||
|
||||
var topic = json.GetPropertyOrNull("topic")?.GetStringOrNull();
|
||||
|
||||
var isActive = !json
|
||||
var isArchived = json
|
||||
.GetPropertyOrNull("thread_metadata")?
|
||||
.GetPropertyOrNull("archived")?
|
||||
.GetBooleanOrNull() ?? true;
|
||||
.GetBooleanOrNull() ?? false;
|
||||
|
||||
var lastMessageId = json
|
||||
.GetPropertyOrNull("last_message_id")?
|
||||
@@ -96,7 +96,7 @@ public partial record Channel
|
||||
position,
|
||||
iconUrl,
|
||||
topic,
|
||||
isActive,
|
||||
isArchived,
|
||||
lastMessageId
|
||||
);
|
||||
}
|
||||
|
||||
@@ -260,6 +260,7 @@ public class DiscordClient
|
||||
|
||||
public async IAsyncEnumerable<Channel> GetGuildThreadsAsync(
|
||||
Snowflake guildId,
|
||||
bool includeArchived = false,
|
||||
[EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||
{
|
||||
var tokenKind = _resolvedTokenKind ??= await GetTokenKindAsync(cancellationToken);
|
||||
@@ -285,7 +286,11 @@ public class DiscordClient
|
||||
|
||||
foreach (var threadJson in response.Value.GetProperty("threads").EnumerateArray())
|
||||
{
|
||||
yield return Channel.Parse(threadJson, channel);
|
||||
var thread = Channel.Parse(threadJson, channel);
|
||||
if (!includeArchived && thread.IsArchived)
|
||||
continue;
|
||||
|
||||
yield return thread;
|
||||
currentOffset++;
|
||||
}
|
||||
|
||||
@@ -314,28 +319,32 @@ public class DiscordClient
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var channel in channels)
|
||||
// Archived threads
|
||||
if (includeArchived)
|
||||
{
|
||||
// Public archived threads
|
||||
foreach (var channel in channels)
|
||||
{
|
||||
var response = await GetJsonResponseAsync(
|
||||
$"channels/{channel.Id}/threads/archived/public",
|
||||
cancellationToken
|
||||
);
|
||||
// Public archived threads
|
||||
{
|
||||
var response = await GetJsonResponseAsync(
|
||||
$"channels/{channel.Id}/threads/archived/public",
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
foreach (var threadJson in response.GetProperty("threads").EnumerateArray())
|
||||
yield return Channel.Parse(threadJson, channel);
|
||||
}
|
||||
foreach (var threadJson in response.GetProperty("threads").EnumerateArray())
|
||||
yield return Channel.Parse(threadJson, channel);
|
||||
}
|
||||
|
||||
// Private archived threads
|
||||
{
|
||||
var response = await GetJsonResponseAsync(
|
||||
$"channels/{channel.Id}/threads/archived/private",
|
||||
cancellationToken
|
||||
);
|
||||
// Private archived threads
|
||||
{
|
||||
var response = await GetJsonResponseAsync(
|
||||
$"channels/{channel.Id}/threads/archived/private",
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
foreach (var threadJson in response.GetProperty("threads").EnumerateArray())
|
||||
yield return Channel.Parse(threadJson, channel);
|
||||
foreach (var threadJson in response.GetProperty("threads").EnumerateArray())
|
||||
yield return Channel.Parse(threadJson, channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user