Convert karma command to use new GuildContext for translations

This commit is contained in:
runebaas 2019-05-12 00:32:07 +02:00
parent 8effc42f92
commit 0f0c0684c6
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6

View file

@ -32,16 +32,16 @@ namespace Geekbot.net.Commands.User
{ {
try try
{ {
var transDict = await _translation.GetDict(Context); var transContext = await _translation.GetGuildContext(Context);
var actor = await GetUser(Context.User.Id); var actor = await GetUser(Context.User.Id);
if (user.Id == Context.User.Id) if (user.Id == Context.User.Id)
{ {
await ReplyAsync(string.Format(transDict["CannotChangeOwn"], Context.User.Username)); await ReplyAsync(transContext.GetString("CannotChangeOwn", Context.User.Username));
} }
else if (TimeoutFinished(actor.TimeOut)) else if (TimeoutFinished(actor.TimeOut))
{ {
await ReplyAsync(string.Format(transDict["WaitUntill"], Context.User.Username, var formatedWaitTime = transContext.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3));
GetTimeLeft(actor.TimeOut))); await ReplyAsync(transContext.GetString("WaitUntill", Context.User.Username, formatedWaitTime));
} }
else else
{ {
@ -60,10 +60,10 @@ namespace Geekbot.net.Commands.User
.WithName(user.Username)); .WithName(user.Username));
eb.WithColor(new Color(138, 219, 146)); eb.WithColor(new Color(138, 219, 146));
eb.Title = transDict["Increased"]; eb.Title = transContext.GetString("Increased");
eb.AddInlineField(transDict["By"], Context.User.Username); eb.AddInlineField(transContext.GetString("By"), Context.User.Username);
eb.AddInlineField(transDict["Amount"], "+1"); eb.AddInlineField(transContext.GetString("Amount"), "+1");
eb.AddInlineField(transDict["Current"], target.Karma); eb.AddInlineField(transContext.GetString("Current"), target.Karma);
await ReplyAsync("", false, eb.Build()); await ReplyAsync("", false, eb.Build());
} }
} }
@ -79,16 +79,16 @@ namespace Geekbot.net.Commands.User
{ {
try try
{ {
var transDict = await _translation.GetDict(Context); var transContext = await _translation.GetGuildContext(Context);
var actor = await GetUser(Context.User.Id); var actor = await GetUser(Context.User.Id);
if (user.Id == Context.User.Id) if (user.Id == Context.User.Id)
{ {
await ReplyAsync(string.Format(transDict["CannotChangeOwn"], Context.User.Username)); await ReplyAsync(transContext.GetString("CannotChangeOwn", Context.User.Username));
} }
else if (TimeoutFinished(actor.TimeOut)) else if (TimeoutFinished(actor.TimeOut))
{ {
await ReplyAsync(string.Format(transDict["WaitUntill"], Context.User.Username, var formatedWaitTime = transContext.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3));
GetTimeLeft(actor.TimeOut))); await ReplyAsync(transContext.GetString("WaitUntill", Context.User.Username, formatedWaitTime));
} }
else else
{ {
@ -107,10 +107,10 @@ namespace Geekbot.net.Commands.User
.WithName(user.Username)); .WithName(user.Username));
eb.WithColor(new Color(138, 219, 146)); eb.WithColor(new Color(138, 219, 146));
eb.Title = transDict["Decreased"]; eb.Title = transContext.GetString("Decreased");
eb.AddInlineField(transDict["By"], Context.User.Username); eb.AddInlineField(transContext.GetString("By"), Context.User.Username);
eb.AddInlineField(transDict["Amount"], "-1"); eb.AddInlineField(transContext.GetString("Amount"), "-1");
eb.AddInlineField(transDict["Current"], target.Karma); eb.AddInlineField(transContext.GetString("Current"), target.Karma);
await ReplyAsync("", false, eb.Build()); await ReplyAsync("", false, eb.Build());
} }
} }
@ -125,12 +125,6 @@ namespace Geekbot.net.Commands.User
return lastKarma.AddMinutes(3) > DateTimeOffset.Now; return lastKarma.AddMinutes(3) > DateTimeOffset.Now;
} }
private string GetTimeLeft(DateTimeOffset lastKarma)
{
var dt = lastKarma.AddMinutes(3).Subtract(DateTimeOffset.Now);
return $"{dt.Minutes} Minutes and {dt.Seconds} Seconds";
}
private async Task<KarmaModel> GetUser(ulong userId) private async Task<KarmaModel> GetUser(ulong userId)
{ {
var user = _database.Karma.FirstOrDefault(u =>u.GuildId.Equals(Context.Guild.Id.AsLong()) && u.UserId.Equals(userId.AsLong())) ?? await CreateNewRow(userId); var user = _database.Karma.FirstOrDefault(u =>u.GuildId.Equals(Context.Guild.Id.AsLong()) && u.UserId.Equals(userId.AsLong())) ?? await CreateNewRow(userId);