Convert a few more things
This commit is contained in:
parent
b48a77df8d
commit
35433b0d82
@ -6,14 +6,14 @@ namespace Myriad.Rest.Exceptions
|
||||
{
|
||||
public class DiscordRequestException: Exception
|
||||
{
|
||||
public DiscordRequestException(HttpResponseMessage response, string requestBody, DiscordApiError? apiError)
|
||||
public DiscordRequestException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError)
|
||||
{
|
||||
RequestBody = requestBody;
|
||||
ResponseBody = responseBody;
|
||||
Response = response;
|
||||
ApiError = apiError;
|
||||
}
|
||||
|
||||
public string RequestBody { get; init; } = null!;
|
||||
public string ResponseBody { get; init; } = null!;
|
||||
public HttpResponseMessage Response { get; init; } = null!;
|
||||
|
||||
public HttpStatusCode StatusCode => Response.StatusCode;
|
||||
@ -29,43 +29,43 @@ namespace Myriad.Rest.Exceptions
|
||||
|
||||
public class NotFoundException: DiscordRequestException
|
||||
{
|
||||
public NotFoundException(HttpResponseMessage response, string requestBody, DiscordApiError? apiError): base(
|
||||
response, requestBody, apiError) { }
|
||||
public NotFoundException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base(
|
||||
response, responseBody, apiError) { }
|
||||
}
|
||||
|
||||
public class UnauthorizedException: DiscordRequestException
|
||||
{
|
||||
public UnauthorizedException(HttpResponseMessage response, string requestBody, DiscordApiError? apiError): base(
|
||||
response, requestBody, apiError) { }
|
||||
public UnauthorizedException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base(
|
||||
response, responseBody, apiError) { }
|
||||
}
|
||||
|
||||
public class ForbiddenException: DiscordRequestException
|
||||
{
|
||||
public ForbiddenException(HttpResponseMessage response, string requestBody, DiscordApiError? apiError): base(
|
||||
response, requestBody, apiError) { }
|
||||
public ForbiddenException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base(
|
||||
response, responseBody, apiError) { }
|
||||
}
|
||||
|
||||
public class ConflictException: DiscordRequestException
|
||||
{
|
||||
public ConflictException(HttpResponseMessage response, string requestBody, DiscordApiError? apiError): base(
|
||||
response, requestBody, apiError) { }
|
||||
public ConflictException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base(
|
||||
response, responseBody, apiError) { }
|
||||
}
|
||||
|
||||
public class BadRequestException: DiscordRequestException
|
||||
{
|
||||
public BadRequestException(HttpResponseMessage response, string requestBody, DiscordApiError? apiError): base(
|
||||
response, requestBody, apiError) { }
|
||||
public BadRequestException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base(
|
||||
response, responseBody, apiError) { }
|
||||
}
|
||||
|
||||
public class TooManyRequestsException: DiscordRequestException
|
||||
{
|
||||
public TooManyRequestsException(HttpResponseMessage response, string requestBody, DiscordApiError? apiError):
|
||||
base(response, requestBody, apiError) { }
|
||||
public TooManyRequestsException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError):
|
||||
base(response, responseBody, apiError) { }
|
||||
}
|
||||
|
||||
public class UnknownDiscordRequestException: DiscordRequestException
|
||||
{
|
||||
public UnknownDiscordRequestException(HttpResponseMessage response, string requestBody,
|
||||
DiscordApiError? apiError): base(response, requestBody, apiError) { }
|
||||
public UnknownDiscordRequestException(HttpResponseMessage response, string responseBody,
|
||||
DiscordApiError? apiError): base(response, responseBody, apiError) { }
|
||||
}
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
using DSharpPlus;
|
||||
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
using PluralKit.Core;
|
||||
|
||||
|
@ -3,9 +3,6 @@ using System.Net.Http;
|
||||
|
||||
using Autofac;
|
||||
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.EventArgs;
|
||||
|
||||
using Myriad.Cache;
|
||||
using Myriad.Gateway;
|
||||
|
||||
@ -24,17 +21,6 @@ namespace PluralKit.Bot
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
// Clients
|
||||
builder.Register(c => new DiscordConfiguration
|
||||
{
|
||||
Token = c.Resolve<BotConfig>().Token,
|
||||
TokenType = TokenType.Bot,
|
||||
MessageCacheSize = 0,
|
||||
LargeThreshold = 50,
|
||||
LoggerFactory = c.Resolve<Microsoft.Extensions.Logging.ILoggerFactory>()
|
||||
}).AsSelf();
|
||||
builder.Register(c => new DiscordShardedClient(c.Resolve<DiscordConfiguration>())).AsSelf().SingleInstance();
|
||||
builder.Register(c => new DiscordRestClient(c.Resolve<DiscordConfiguration>())).AsSelf().SingleInstance();
|
||||
|
||||
builder.Register(c => new GatewaySettings
|
||||
{
|
||||
Token = c.Resolve<BotConfig>().Token,
|
||||
@ -82,9 +68,7 @@ namespace PluralKit.Bot
|
||||
builder.RegisterType<ReactionAdded>().As<IEventHandler<MessageReactionAddEvent>>();
|
||||
|
||||
// Event handler queue
|
||||
builder.RegisterType<HandlerQueue<MessageCreateEventArgs>>().AsSelf().SingleInstance();
|
||||
builder.RegisterType<HandlerQueue<MessageCreateEvent>>().AsSelf().SingleInstance();
|
||||
builder.RegisterType<HandlerQueue<MessageReactionAddEventArgs>>().AsSelf().SingleInstance();
|
||||
builder.RegisterType<HandlerQueue<MessageReactionAddEvent>>().AsSelf().SingleInstance();
|
||||
|
||||
// Bot services
|
||||
@ -104,14 +88,13 @@ namespace PluralKit.Bot
|
||||
|
||||
// Sentry stuff
|
||||
builder.Register(_ => new Scope(null)).AsSelf().InstancePerLifetimeScope();
|
||||
// TODO:
|
||||
// builder.RegisterType<SentryEnricher>()
|
||||
// .As<ISentryEnricher<MessageCreateEvent>>()
|
||||
// .As<ISentryEnricher<MessageDeleteEvent>>()
|
||||
// .As<ISentryEnricher<MessageUpdateEvent>>()
|
||||
// .As<ISentryEnricher<MessageDeleteBulkEvent>>()
|
||||
// .As<ISentryEnricher<MessageReactionAddEvent>>()
|
||||
// .SingleInstance();
|
||||
builder.RegisterType<SentryEnricher>()
|
||||
.As<ISentryEnricher<MessageCreateEvent>>()
|
||||
.As<ISentryEnricher<MessageDeleteEvent>>()
|
||||
.As<ISentryEnricher<MessageUpdateEvent>>()
|
||||
.As<ISentryEnricher<MessageDeleteBulkEvent>>()
|
||||
.As<ISentryEnricher<MessageReactionAddEvent>>()
|
||||
.SingleInstance();
|
||||
|
||||
// Proxy stuff
|
||||
builder.RegisterType<ProxyMatcher>().AsSelf().SingleInstance();
|
||||
|
@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using DSharpPlus.Exceptions;
|
||||
using Myriad.Rest.Exceptions;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
@ -64,12 +64,12 @@ namespace PluralKit.Bot
|
||||
if (e is JsonReaderException jre && jre.Message == "Unexpected character encountered while parsing value: <. Path '', line 0, position 0.") return false;
|
||||
|
||||
// And now (2020-05-12), apparently Discord returns these weird responses occasionally. Also not our problem.
|
||||
if (e is BadRequestException bre && bre.WebResponse.Response.Contains("<center>nginx</center>")) return false;
|
||||
if (e is NotFoundException ne && ne.WebResponse.Response.Contains("<center>nginx</center>")) return false;
|
||||
if (e is UnauthorizedException ue && ue.WebResponse.Response.Contains("<center>nginx</center>")) return false;
|
||||
if (e is BadRequestException bre && bre.ResponseBody.Contains("<center>nginx</center>")) return false;
|
||||
if (e is NotFoundException ne && ne.ResponseBody.Contains("<center>nginx</center>")) return false;
|
||||
if (e is UnauthorizedException ue && ue.ResponseBody.Contains("<center>nginx</center>")) return false;
|
||||
|
||||
// 500s? also not our problem :^)
|
||||
if (e is ServerErrorException) return false;
|
||||
// 5xxs? also not our problem :^)
|
||||
if (e is UnknownDiscordRequestException udre && (int) udre.StatusCode >= 500) return false;
|
||||
|
||||
// Webhook server errors are also *not our problem*
|
||||
// (this includes rate limit errors, WebhookRateLimited is a subclass)
|
||||
|
Loading…
Reference in New Issue
Block a user