From 0f0c0684c62c2e385fd941d122bef7d81406d63e Mon Sep 17 00:00:00 2001 From: runebaas Date: Sun, 12 May 2019 00:32:07 +0200 Subject: [PATCH] Convert karma command to use new GuildContext for translations --- Geekbot.net/Commands/User/Karma.cs | 38 +++++++++++++----------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/Geekbot.net/Commands/User/Karma.cs b/Geekbot.net/Commands/User/Karma.cs index e2a4739..ed221ff 100644 --- a/Geekbot.net/Commands/User/Karma.cs +++ b/Geekbot.net/Commands/User/Karma.cs @@ -32,16 +32,16 @@ namespace Geekbot.net.Commands.User { try { - var transDict = await _translation.GetDict(Context); + var transContext = await _translation.GetGuildContext(Context); var actor = await GetUser(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)) { - await ReplyAsync(string.Format(transDict["WaitUntill"], Context.User.Username, - GetTimeLeft(actor.TimeOut))); + var formatedWaitTime = transContext.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3)); + await ReplyAsync(transContext.GetString("WaitUntill", Context.User.Username, formatedWaitTime)); } else { @@ -60,10 +60,10 @@ namespace Geekbot.net.Commands.User .WithName(user.Username)); eb.WithColor(new Color(138, 219, 146)); - eb.Title = transDict["Increased"]; - eb.AddInlineField(transDict["By"], Context.User.Username); - eb.AddInlineField(transDict["Amount"], "+1"); - eb.AddInlineField(transDict["Current"], target.Karma); + eb.Title = transContext.GetString("Increased"); + eb.AddInlineField(transContext.GetString("By"), Context.User.Username); + eb.AddInlineField(transContext.GetString("Amount"), "+1"); + eb.AddInlineField(transContext.GetString("Current"), target.Karma); await ReplyAsync("", false, eb.Build()); } } @@ -79,16 +79,16 @@ namespace Geekbot.net.Commands.User { try { - var transDict = await _translation.GetDict(Context); + var transContext = await _translation.GetGuildContext(Context); var actor = await GetUser(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)) { - await ReplyAsync(string.Format(transDict["WaitUntill"], Context.User.Username, - GetTimeLeft(actor.TimeOut))); + var formatedWaitTime = transContext.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3)); + await ReplyAsync(transContext.GetString("WaitUntill", Context.User.Username, formatedWaitTime)); } else { @@ -107,10 +107,10 @@ namespace Geekbot.net.Commands.User .WithName(user.Username)); eb.WithColor(new Color(138, 219, 146)); - eb.Title = transDict["Decreased"]; - eb.AddInlineField(transDict["By"], Context.User.Username); - eb.AddInlineField(transDict["Amount"], "-1"); - eb.AddInlineField(transDict["Current"], target.Karma); + eb.Title = transContext.GetString("Decreased"); + eb.AddInlineField(transContext.GetString("By"), Context.User.Username); + eb.AddInlineField(transContext.GetString("Amount"), "-1"); + eb.AddInlineField(transContext.GetString("Current"), target.Karma); await ReplyAsync("", false, eb.Build()); } } @@ -125,12 +125,6 @@ namespace Geekbot.net.Commands.User 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 GetUser(ulong userId) { var user = _database.Karma.FirstOrDefault(u =>u.GuildId.Equals(Context.Guild.Id.AsLong()) && u.UserId.Equals(userId.AsLong())) ?? await CreateNewRow(userId);