Translate common commands and fix bug in !urban
This commit is contained in:
parent
119ce579b7
commit
14fcf74aea
11 changed files with 182 additions and 44 deletions
|
@ -8,16 +8,19 @@ namespace Geekbot.net.Lib
|
|||
public class ErrorHandler : IErrorHandler
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ITranslationHandler _translation;
|
||||
|
||||
public ErrorHandler(ILogger logger)
|
||||
public ErrorHandler(ILogger logger, ITranslationHandler translation)
|
||||
{
|
||||
_logger = logger;
|
||||
_translation = translation;
|
||||
}
|
||||
|
||||
public void HandleCommandException(Exception e, ICommandContext Context, string errorMessage = "Something went wrong :confused:")
|
||||
public void HandleCommandException(Exception e, ICommandContext Context, string errorMessage = "def")
|
||||
{
|
||||
try
|
||||
{
|
||||
var errorString = errorMessage == "def" ? _translation.GetString(Context.Guild.Id, "errorHandler", "SomethingWentWrong") : errorMessage;
|
||||
var errorObj = new ErrorObject()
|
||||
{
|
||||
Message = new ErrorMessage()
|
||||
|
@ -50,7 +53,7 @@ namespace Geekbot.net.Lib
|
|||
_logger.Error(e, errorJson);
|
||||
if (!string.IsNullOrEmpty(errorMessage))
|
||||
{
|
||||
Context.Channel.SendMessageAsync(errorMessage);
|
||||
Context.Channel.SendMessageAsync(errorString);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -87,6 +90,6 @@ namespace Geekbot.net.Lib
|
|||
|
||||
public interface IErrorHandler
|
||||
{
|
||||
void HandleCommandException(Exception e, ICommandContext Context, string errorMessage = "Something went wrong :confused:");
|
||||
void HandleCommandException(Exception e, ICommandContext Context, string errorMessage = "def");
|
||||
}
|
||||
}
|
|
@ -117,6 +117,19 @@ namespace Geekbot.net.Lib
|
|||
return new Dictionary<string, string>();
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, string> GetDict(ICommandContext context, string command)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _translations[_serverLanguages[context.Guild.Id]][command];
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(e, "lol nope");
|
||||
return new Dictionary<string, string>();
|
||||
}
|
||||
}
|
||||
|
||||
public bool SetLanguage(ulong guildId, string language)
|
||||
{
|
||||
|
@ -144,6 +157,7 @@ namespace Geekbot.net.Lib
|
|||
{
|
||||
string GetString(ulong guildId, string command, string stringName);
|
||||
Dictionary<string, string> GetDict(ICommandContext context);
|
||||
Dictionary<string, string> GetDict(ICommandContext context, string command);
|
||||
bool SetLanguage(ulong guildId, string language);
|
||||
List<string> GetSupportedLanguages();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue