This commit is contained in:
Alexey Golub
2020-04-22 20:44:14 +03:00
parent 6a430cdc76
commit dc79813ad7
13 changed files with 227 additions and 263 deletions

View File

@@ -1,22 +0,0 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace DiscordChatExporter.Domain.Discord
{
public static class AccessibilityExtensions
{
private static async ValueTask<IReadOnlyList<T>> AggregateAsync<T>(this IAsyncEnumerable<T> asyncEnumerable)
{
var list = new List<T>();
await foreach (var i in asyncEnumerable)
list.Add(i);
return list;
}
public static ValueTaskAwaiter<IReadOnlyList<T>> GetAwaiter<T>(this IAsyncEnumerable<T> asyncEnumerable) =>
asyncEnumerable.AggregateAsync().GetAwaiter();
}
}

View File

@@ -2,11 +2,7 @@
namespace DiscordChatExporter.Domain.Discord
{
public enum AuthTokenType
{
User,
Bot
}
public enum AuthTokenType { User, Bot }
public class AuthToken
{

View File

@@ -23,7 +23,9 @@ namespace DiscordChatExporter.Domain.Discord
_token = token;
_httpClient = httpClient;
// Discord seems to always respond 429 on our first request with unreasonable wait time (10+ minutes).
_httpClient.BaseAddress = new Uri("https://discordapp.com/api/v6");
// Discord seems to always respond with 429 on the first request with unreasonable wait time (10+ minutes).
// For that reason the policy will start respecting their retry-after header only after Nth failed response.
_httpRequestPolicy = Policy
.HandleResult<HttpResponseMessage>(m => m.StatusCode == HttpStatusCode.TooManyRequests)
@@ -240,10 +242,7 @@ namespace DiscordChatExporter.Domain.Discord
handler.UseCookies = false;
return new HttpClient(handler, true)
{
BaseAddress = new Uri("https://discordapp.com/api/v6")
};
return new HttpClient(handler, true);
});
}
}