mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-16 03:42:30 +00:00
Cleanup
This commit is contained in:
@@ -56,7 +56,7 @@ public class DiscordClient
|
|||||||
// This may add an unnecessary delay in case the user doesn't intend to
|
// This may add an unnecessary delay in case the user doesn't intend to
|
||||||
// make any more requests, but implementing a smarter solution would
|
// make any more requests, but implementing a smarter solution would
|
||||||
// require properly keeping track of Discord's global/per-route/per-resource
|
// require properly keeping track of Discord's global/per-route/per-resource
|
||||||
// rate limits and that's not worth the effort.
|
// rate limits and that's just way too much effort.
|
||||||
var remainingRequestCount = response
|
var remainingRequestCount = response
|
||||||
.Headers
|
.Headers
|
||||||
.TryGetValue("X-RateLimit-Remaining")?
|
.TryGetValue("X-RateLimit-Remaining")?
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Utils.Extensions;
|
namespace DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
|
||||||
@@ -32,13 +28,4 @@ public static class ExceptionExtensions
|
|||||||
PopulateChildren(exception, children);
|
PopulateChildren(exception, children);
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpStatusCode? TryGetStatusCode(this HttpRequestException ex) =>
|
|
||||||
// This is extremely frail, but there's no other way
|
|
||||||
Regex
|
|
||||||
.Match(ex.Message, @": (\d+) \(")
|
|
||||||
.Groups[1]
|
|
||||||
.Value
|
|
||||||
.NullIfWhiteSpace()?
|
|
||||||
.Pipe(s => (HttpStatusCode) int.Parse(s, CultureInfo.InvariantCulture));
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
using System.Net.Http.Headers;
|
using System.Globalization;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Core.Utils.Extensions;
|
namespace DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
|
||||||
@@ -8,4 +12,13 @@ public static class HttpExtensions
|
|||||||
headers.TryGetValues(name, out var values)
|
headers.TryGetValues(name, out var values)
|
||||||
? string.Concat(values)
|
? string.Concat(values)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
public static HttpStatusCode? TryGetStatusCode(this HttpRequestException ex) =>
|
||||||
|
// This is extremely frail, but there's no other way
|
||||||
|
Regex
|
||||||
|
.Match(ex.Message, @": (\d+) \(")
|
||||||
|
.Groups[1]
|
||||||
|
.Value
|
||||||
|
.NullIfWhiteSpace()?
|
||||||
|
.Pipe(s => (HttpStatusCode) int.Parse(s, CultureInfo.InvariantCulture));
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user