Delete the TranslationHandler and the old translations file. Refactor GeekbotCommandBase to get the server language from guild settings. Create DateLocalization to create a localized relative time remaining string.
This commit is contained in:
parent
078c884df7
commit
33829e91bc
22 changed files with 156 additions and 579 deletions
|
@ -1,9 +1,6 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Discord.Net;
|
||||
using Geekbot.Core.Localization;
|
||||
using Geekbot.Core.Logger;
|
||||
using SharpRaven;
|
||||
using SharpRaven.Data;
|
||||
|
@ -14,14 +11,14 @@ namespace Geekbot.Core.ErrorHandling
|
|||
public class ErrorHandler : IErrorHandler
|
||||
{
|
||||
private readonly IGeekbotLogger _logger;
|
||||
private readonly ITranslationHandler _translation;
|
||||
private readonly Func<string> _getDefaultErrorText;
|
||||
private readonly IRavenClient _raven;
|
||||
private readonly bool _errorsInChat;
|
||||
|
||||
public ErrorHandler(IGeekbotLogger logger, ITranslationHandler translation, RunParameters runParameters)
|
||||
public ErrorHandler(IGeekbotLogger logger, RunParameters runParameters, Func<string> getDefaultErrorText)
|
||||
{
|
||||
_logger = logger;
|
||||
_translation = translation;
|
||||
_getDefaultErrorText = getDefaultErrorText;
|
||||
_errorsInChat = runParameters.ExposeErrors;
|
||||
|
||||
var sentryDsn = runParameters.SentryEndpoint;
|
||||
|
@ -40,7 +37,9 @@ namespace Geekbot.Core.ErrorHandling
|
|||
{
|
||||
try
|
||||
{
|
||||
var errorString = errorMessage == "def" ? await _translation.GetString(context.Guild?.Id ?? 0, "errorHandler", "SomethingWentWrong") : errorMessage;
|
||||
var errorString = errorMessage == "def"
|
||||
? _getDefaultErrorText()
|
||||
: errorMessage;
|
||||
var errorObj = SimpleConextConverter.ConvertContext(context);
|
||||
if (e.Message.Contains("50007")) return;
|
||||
if (e.Message.Contains("50013")) return;
|
||||
|
@ -76,17 +75,6 @@ namespace Geekbot.Core.ErrorHandling
|
|||
}
|
||||
}
|
||||
|
||||
public async Task HandleHttpException(HttpException e, ICommandContext context)
|
||||
{
|
||||
var errorStrings = await _translation.GetDict(context, "httpErrors");
|
||||
switch(e.HttpCode)
|
||||
{
|
||||
case HttpStatusCode.Forbidden:
|
||||
await context.Channel.SendMessageAsync(errorStrings["403"]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ReportExternal(Exception e, MessageDto errorObj)
|
||||
{
|
||||
if (_raven == null) return;
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Discord.Net;
|
||||
|
||||
namespace Geekbot.Core.ErrorHandling
|
||||
{
|
||||
public interface IErrorHandler
|
||||
{
|
||||
Task HandleCommandException(Exception e, ICommandContext context, string errorMessage = "def");
|
||||
Task HandleHttpException(HttpException e, ICommandContext context);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue