mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-22 10:55:15 -04:00
Cleanup
This commit is contained in:
parent
49c4b12512
commit
e5d5f1c85f
3 changed files with 15 additions and 15 deletions
|
@ -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));
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue