Translate common commands and fix bug in !urban

This commit is contained in:
Runebaas 2017-11-16 17:19:43 +01:00
parent 119ce579b7
commit 14fcf74aea
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
11 changed files with 182 additions and 44 deletions

View file

@ -121,7 +121,7 @@ namespace Geekbot.net.Commands
if (success)
{
var trans = _translation.GetDict(Context);
await ReplyAsync(trans["Confirm"]);
await ReplyAsync(trans["NewLanguageSet"]);
return;
}
await ReplyAsync(

View file

@ -9,11 +9,13 @@ namespace Geekbot.net.Commands
{
private readonly Random _rnd;
private readonly IErrorHandler _errorHandler;
private readonly ITranslationHandler _translation;
public Choose(Random RandomClient, IErrorHandler errorHandler)
public Choose(Random RandomClient, IErrorHandler errorHandler, ITranslationHandler translation)
{
_rnd = RandomClient;
_errorHandler = errorHandler;
_translation = translation;
}
[Command("choose", RunMode = RunMode.Async)]
@ -23,9 +25,10 @@ namespace Geekbot.net.Commands
{
try
{
var transDict = _translation.GetDict(Context);
var choicesArray = choices.Split(';');
var choice = _rnd.Next(choicesArray.Length);
await ReplyAsync($"I choose **{choicesArray[choice]}**");
await ReplyAsync(string.Format(transDict["Choice"], choicesArray[choice]));
}
catch (Exception e)
{

View file

@ -12,11 +12,13 @@ namespace Geekbot.net.Commands
{
private readonly IDatabase _redis;
private readonly IErrorHandler _errorHandler;
private readonly ITranslationHandler _translation;
public Counters(IDatabase redis, IErrorHandler errorHandler)
public Counters(IDatabase redis, IErrorHandler errorHandler, ITranslationHandler translation)
{
_redis = redis;
_errorHandler = errorHandler;
_translation = translation;
}
[Command("good", RunMode = RunMode.Async)]
@ -26,18 +28,18 @@ namespace Geekbot.net.Commands
{
try
{
var transDict = _translation.GetDict(Context);
var lastKarmaFromRedis = _redis.HashGet($"{Context.Guild.Id}:KarmaTimeout", Context.User.Id.ToString());
var lastKarma = ConvertToDateTimeOffset(lastKarmaFromRedis.ToString());
if (user.Id == Context.User.Id)
{
await ReplyAsync($"Sorry {Context.User.Username}, but you can't lower your own karma");
await ReplyAsync(string.Format(transDict["CannotChangeOwn"], Context.User.Username));
}
else if (TimeoutFinished(lastKarma))
{
await ReplyAsync(
$"Sorry {Context.User.Username}, but you have to wait {GetTimeLeft(lastKarma)} before you can give karma again...");
await ReplyAsync(string.Format(transDict["WaitUntill"], Context.User.Username, GetTimeLeft(lastKarma)));
}
else
else
{
var newKarma = _redis.HashIncrement($"{Context.Guild.Id}:Karma", user.Id.ToString());
_redis.HashSet($"{Context.Guild.Id}:KarmaTimeout",
@ -49,10 +51,10 @@ namespace Geekbot.net.Commands
.WithName(user.Username));
eb.WithColor(new Color(138, 219, 146));
eb.Title = "Karma Increased";
eb.AddInlineField("By", Context.User.Username);
eb.AddInlineField("amount", "+1");
eb.AddInlineField("Current Karma", newKarma);
eb.Title = transDict["Increased"];
eb.AddInlineField(transDict["By"], Context.User.Username);
eb.AddInlineField(transDict["Amount"], "+1");
eb.AddInlineField(transDict["Current"], newKarma);
await ReplyAsync("", false, eb.Build());
}
}
@ -69,16 +71,16 @@ namespace Geekbot.net.Commands
{
try
{
var transDict = _translation.GetDict(Context);
var lastKarmaFromRedis = _redis.HashGet($"{Context.Guild.Id}:KarmaTimeout", Context.User.Id.ToString());
var lastKarma = ConvertToDateTimeOffset(lastKarmaFromRedis.ToString());
if (user.Id == Context.User.Id)
{
await ReplyAsync($"Sorry {Context.User.Username}, but you can't lower your own karma");
await ReplyAsync(string.Format(transDict["CannotChangeOwn"], Context.User.Username));
}
else if (TimeoutFinished(lastKarma))
{
await ReplyAsync(
$"Sorry {Context.User.Username}, but you have to wait {GetTimeLeft(lastKarma)} before you can take karma again...");
await ReplyAsync(string.Format(transDict["WaitUntill"], Context.User.Username, GetTimeLeft(lastKarma)));
}
else
{
@ -92,10 +94,10 @@ namespace Geekbot.net.Commands
.WithName(user.Username));
eb.WithColor(new Color(138, 219, 146));
eb.Title = "Karma Decreased";
eb.AddInlineField("By", Context.User.Username);
eb.AddInlineField("amount", "-1");
eb.AddInlineField("Current Karma", newKarma);
eb.Title = transDict["Decreased"];
eb.AddInlineField(transDict["By"], Context.User.Username);
eb.AddInlineField(transDict["Amount"], "-1");
eb.AddInlineField(transDict["Current"], newKarma);
await ReplyAsync("", false, eb.Build());
}
}

View file

@ -8,13 +8,17 @@ namespace Geekbot.net.Commands
{
public class Roll : ModuleBase
{
private readonly IDatabase redis;
private readonly Random rnd;
private readonly IDatabase _redis;
private readonly Random _rnd;
private readonly ITranslationHandler _translation;
private readonly IErrorHandler _errorHandler;
public Roll(IDatabase redis, Random RandomClient)
public Roll(IDatabase redis, Random RandomClient, IErrorHandler errorHandler, ITranslationHandler translation)
{
this.redis = redis;
rnd = RandomClient;
_redis = redis;
_rnd = RandomClient;
_translation = translation;
_errorHandler = errorHandler;
}
[Command("roll", RunMode = RunMode.Async)]
@ -22,21 +26,29 @@ namespace Geekbot.net.Commands
[Summary("Guess which number the bot will roll (1-100")]
public async Task RollCommand([Remainder] [Summary("guess")] string stuff = "noGuess")
{
var number = rnd.Next(1, 100);
var guess = 1000;
int.TryParse(stuff, out guess);
if (guess <= 100 && guess > 0)
try
{
await ReplyAsync($"{Context.Message.Author.Mention} you rolled {number}, your guess was {guess}");
if (guess == number)
var number = _rnd.Next(1, 100);
var guess = 1000;
int.TryParse(stuff, out guess);
var transDict = _translation.GetDict(Context);
if (guess <= 100 && guess > 0)
{
await ReplyAsync($"Congratulations {Context.User.Username}, your guess was correct!");
redis.HashIncrement($"{Context.Guild.Id}:Rolls", Context.User.Id.ToString());
await ReplyAsync(string.Format(transDict["Rolled"], Context.Message.Author.Mention, number, guess));
if (guess == number)
{
await ReplyAsync(string.Format(transDict["Gratz"], Context.Message.Author));
_redis.HashIncrement($"{Context.Guild.Id}:Rolls", Context.User.Id.ToString());
}
}
else
{
await ReplyAsync(string.Format(transDict["RolledNoGuess"], Context.Message.Author.Mention, number));
}
}
else
catch (Exception e)
{
await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number);
_errorHandler.HandleCommandException(e, Context);
}
}
}

View file

@ -39,7 +39,7 @@ namespace Geekbot.net.Commands
await ReplyAsync("That word hasn't been defined...");
return;
}
var definition = definitions.list.First();
var definition = definitions.list.First(e => !string.IsNullOrWhiteSpace(e.example));
var eb = new EmbedBuilder();
eb.WithAuthor(new EmbedAuthorBuilder()

View file

@ -62,7 +62,7 @@ namespace Geekbot.net.Commands
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context, "Something went wrong...");
_errorHandler.HandleCommandException(e, Context);
}
}
@ -111,7 +111,7 @@ namespace Geekbot.net.Commands
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context, "Something went wrong...");
_errorHandler.HandleCommandException(e, Context);
}
}
}