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 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;
|
Response = response;
|
||||||
ApiError = apiError;
|
ApiError = apiError;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string RequestBody { get; init; } = null!;
|
public string ResponseBody { get; init; } = null!;
|
||||||
public HttpResponseMessage Response { get; init; } = null!;
|
public HttpResponseMessage Response { get; init; } = null!;
|
||||||
|
|
||||||
public HttpStatusCode StatusCode => Response.StatusCode;
|
public HttpStatusCode StatusCode => Response.StatusCode;
|
||||||
@ -29,43 +29,43 @@ namespace Myriad.Rest.Exceptions
|
|||||||
|
|
||||||
public class NotFoundException: DiscordRequestException
|
public class NotFoundException: DiscordRequestException
|
||||||
{
|
{
|
||||||
public NotFoundException(HttpResponseMessage response, string requestBody, DiscordApiError? apiError): base(
|
public NotFoundException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base(
|
||||||
response, requestBody, apiError) { }
|
response, responseBody, apiError) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UnauthorizedException: DiscordRequestException
|
public class UnauthorizedException: DiscordRequestException
|
||||||
{
|
{
|
||||||
public UnauthorizedException(HttpResponseMessage response, string requestBody, DiscordApiError? apiError): base(
|
public UnauthorizedException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base(
|
||||||
response, requestBody, apiError) { }
|
response, responseBody, apiError) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ForbiddenException: DiscordRequestException
|
public class ForbiddenException: DiscordRequestException
|
||||||
{
|
{
|
||||||
public ForbiddenException(HttpResponseMessage response, string requestBody, DiscordApiError? apiError): base(
|
public ForbiddenException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base(
|
||||||
response, requestBody, apiError) { }
|
response, responseBody, apiError) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ConflictException: DiscordRequestException
|
public class ConflictException: DiscordRequestException
|
||||||
{
|
{
|
||||||
public ConflictException(HttpResponseMessage response, string requestBody, DiscordApiError? apiError): base(
|
public ConflictException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base(
|
||||||
response, requestBody, apiError) { }
|
response, responseBody, apiError) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BadRequestException: DiscordRequestException
|
public class BadRequestException: DiscordRequestException
|
||||||
{
|
{
|
||||||
public BadRequestException(HttpResponseMessage response, string requestBody, DiscordApiError? apiError): base(
|
public BadRequestException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base(
|
||||||
response, requestBody, apiError) { }
|
response, responseBody, apiError) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TooManyRequestsException: DiscordRequestException
|
public class TooManyRequestsException: DiscordRequestException
|
||||||
{
|
{
|
||||||
public TooManyRequestsException(HttpResponseMessage response, string requestBody, DiscordApiError? apiError):
|
public TooManyRequestsException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError):
|
||||||
base(response, requestBody, apiError) { }
|
base(response, responseBody, apiError) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UnknownDiscordRequestException: DiscordRequestException
|
public class UnknownDiscordRequestException: DiscordRequestException
|
||||||
{
|
{
|
||||||
public UnknownDiscordRequestException(HttpResponseMessage response, string requestBody,
|
public UnknownDiscordRequestException(HttpResponseMessage response, string responseBody,
|
||||||
DiscordApiError? apiError): base(response, requestBody, apiError) { }
|
DiscordApiError? apiError): base(response, responseBody, apiError) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,4 @@
|
|||||||
using DSharpPlus;
|
using Myriad.Types;
|
||||||
|
|
||||||
using Myriad.Types;
|
|
||||||
|
|
||||||
using PluralKit.Core;
|
using PluralKit.Core;
|
||||||
|
|
||||||
|
@ -3,9 +3,6 @@ using System.Net.Http;
|
|||||||
|
|
||||||
using Autofac;
|
using Autofac;
|
||||||
|
|
||||||
using DSharpPlus;
|
|
||||||
using DSharpPlus.EventArgs;
|
|
||||||
|
|
||||||
using Myriad.Cache;
|
using Myriad.Cache;
|
||||||
using Myriad.Gateway;
|
using Myriad.Gateway;
|
||||||
|
|
||||||
@ -24,17 +21,6 @@ namespace PluralKit.Bot
|
|||||||
protected override void Load(ContainerBuilder builder)
|
protected override void Load(ContainerBuilder builder)
|
||||||
{
|
{
|
||||||
// Clients
|
// 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
|
builder.Register(c => new GatewaySettings
|
||||||
{
|
{
|
||||||
Token = c.Resolve<BotConfig>().Token,
|
Token = c.Resolve<BotConfig>().Token,
|
||||||
@ -82,9 +68,7 @@ namespace PluralKit.Bot
|
|||||||
builder.RegisterType<ReactionAdded>().As<IEventHandler<MessageReactionAddEvent>>();
|
builder.RegisterType<ReactionAdded>().As<IEventHandler<MessageReactionAddEvent>>();
|
||||||
|
|
||||||
// Event handler queue
|
// Event handler queue
|
||||||
builder.RegisterType<HandlerQueue<MessageCreateEventArgs>>().AsSelf().SingleInstance();
|
|
||||||
builder.RegisterType<HandlerQueue<MessageCreateEvent>>().AsSelf().SingleInstance();
|
builder.RegisterType<HandlerQueue<MessageCreateEvent>>().AsSelf().SingleInstance();
|
||||||
builder.RegisterType<HandlerQueue<MessageReactionAddEventArgs>>().AsSelf().SingleInstance();
|
|
||||||
builder.RegisterType<HandlerQueue<MessageReactionAddEvent>>().AsSelf().SingleInstance();
|
builder.RegisterType<HandlerQueue<MessageReactionAddEvent>>().AsSelf().SingleInstance();
|
||||||
|
|
||||||
// Bot services
|
// Bot services
|
||||||
@ -104,14 +88,13 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
// Sentry stuff
|
// Sentry stuff
|
||||||
builder.Register(_ => new Scope(null)).AsSelf().InstancePerLifetimeScope();
|
builder.Register(_ => new Scope(null)).AsSelf().InstancePerLifetimeScope();
|
||||||
// TODO:
|
builder.RegisterType<SentryEnricher>()
|
||||||
// builder.RegisterType<SentryEnricher>()
|
.As<ISentryEnricher<MessageCreateEvent>>()
|
||||||
// .As<ISentryEnricher<MessageCreateEvent>>()
|
.As<ISentryEnricher<MessageDeleteEvent>>()
|
||||||
// .As<ISentryEnricher<MessageDeleteEvent>>()
|
.As<ISentryEnricher<MessageUpdateEvent>>()
|
||||||
// .As<ISentryEnricher<MessageUpdateEvent>>()
|
.As<ISentryEnricher<MessageDeleteBulkEvent>>()
|
||||||
// .As<ISentryEnricher<MessageDeleteBulkEvent>>()
|
.As<ISentryEnricher<MessageReactionAddEvent>>()
|
||||||
// .As<ISentryEnricher<MessageReactionAddEvent>>()
|
.SingleInstance();
|
||||||
// .SingleInstance();
|
|
||||||
|
|
||||||
// Proxy stuff
|
// Proxy stuff
|
||||||
builder.RegisterType<ProxyMatcher>().AsSelf().SingleInstance();
|
builder.RegisterType<ProxyMatcher>().AsSelf().SingleInstance();
|
||||||
|
@ -4,7 +4,7 @@ using System.Collections.Generic;
|
|||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using DSharpPlus.Exceptions;
|
using Myriad.Rest.Exceptions;
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
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;
|
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.
|
// 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 BadRequestException bre && bre.ResponseBody.Contains("<center>nginx</center>")) return false;
|
||||||
if (e is NotFoundException ne && ne.WebResponse.Response.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.WebResponse.Response.Contains("<center>nginx</center>")) return false;
|
if (e is UnauthorizedException ue && ue.ResponseBody.Contains("<center>nginx</center>")) return false;
|
||||||
|
|
||||||
// 500s? also not our problem :^)
|
// 5xxs? also not our problem :^)
|
||||||
if (e is ServerErrorException) return false;
|
if (e is UnknownDiscordRequestException udre && (int) udre.StatusCode >= 500) return false;
|
||||||
|
|
||||||
// Webhook server errors are also *not our problem*
|
// Webhook server errors are also *not our problem*
|
||||||
// (this includes rate limit errors, WebhookRateLimited is a subclass)
|
// (this includes rate limit errors, WebhookRateLimited is a subclass)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user