mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-14 15:14:24 -04:00
Be safer when pulling threads using a bot token
This commit is contained in:
parent
e75a1933f8
commit
6fb6108610
1 changed files with 19 additions and 6 deletions
|
@ -301,7 +301,7 @@ public class DiscordClient
|
||||||
.SetQueryParameter("offset", currentOffset.ToString())
|
.SetQueryParameter("offset", currentOffset.ToString())
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
// Can be null on channels that the user cannot access
|
// Can be null on channels that the user cannot access or channels without threads
|
||||||
var response = await TryGetJsonResponseAsync(url, cancellationToken);
|
var response = await TryGetJsonResponseAsync(url, cancellationToken);
|
||||||
if (response is null)
|
if (response is null)
|
||||||
break;
|
break;
|
||||||
|
@ -333,7 +333,7 @@ public class DiscordClient
|
||||||
.SetQueryParameter("offset", currentOffset.ToString())
|
.SetQueryParameter("offset", currentOffset.ToString())
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
// Can be null on channels that the user cannot access
|
// Can be null on channels that the user cannot access or channels without threads
|
||||||
var response = await TryGetJsonResponseAsync(url, cancellationToken);
|
var response = await TryGetJsonResponseAsync(url, cancellationToken);
|
||||||
if (response is null)
|
if (response is null)
|
||||||
break;
|
break;
|
||||||
|
@ -363,6 +363,7 @@ public class DiscordClient
|
||||||
$"guilds/{guildId}/threads/active",
|
$"guilds/{guildId}/threads/active",
|
||||||
cancellationToken
|
cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach (var threadJson in response.GetProperty("threads").EnumerateArray())
|
foreach (var threadJson in response.GetProperty("threads").EnumerateArray())
|
||||||
{
|
{
|
||||||
var parent = threadJson
|
var parent = threadJson
|
||||||
|
@ -382,23 +383,35 @@ public class DiscordClient
|
||||||
{
|
{
|
||||||
// Public archived threads
|
// Public archived threads
|
||||||
{
|
{
|
||||||
var response = await GetJsonResponseAsync(
|
// Can be null on certain channels
|
||||||
|
var response = await TryGetJsonResponseAsync(
|
||||||
$"channels/{channel.Id}/threads/archived/public",
|
$"channels/{channel.Id}/threads/archived/public",
|
||||||
cancellationToken
|
cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach (var threadJson in response.GetProperty("threads").EnumerateArray())
|
if (response is null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (
|
||||||
|
var threadJson in response.Value.GetProperty("threads").EnumerateArray()
|
||||||
|
)
|
||||||
yield return Channel.Parse(threadJson, channel);
|
yield return Channel.Parse(threadJson, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private archived threads
|
// Private archived threads
|
||||||
{
|
{
|
||||||
var response = await GetJsonResponseAsync(
|
// Can be null on certain channels
|
||||||
|
var response = await TryGetJsonResponseAsync(
|
||||||
$"channels/{channel.Id}/threads/archived/private",
|
$"channels/{channel.Id}/threads/archived/private",
|
||||||
cancellationToken
|
cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach (var threadJson in response.GetProperty("threads").EnumerateArray())
|
if (response is null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (
|
||||||
|
var threadJson in response.Value.GetProperty("threads").EnumerateArray()
|
||||||
|
)
|
||||||
yield return Channel.Parse(threadJson, channel);
|
yield return Channel.Parse(threadJson, channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue