Add the timeout in !roll back

This commit is contained in:
runebaas 2020-06-14 17:27:07 +02:00
parent 8018d5e750
commit 0898e9b6bd
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
3 changed files with 22 additions and 11 deletions

View file

@ -10,7 +10,7 @@ using Geekbot.net.Lib.KvInMemoryStore;
using Geekbot.net.Lib.Localization; using Geekbot.net.Lib.Localization;
using Geekbot.net.Lib.RandomNumberGenerator; using Geekbot.net.Lib.RandomNumberGenerator;
namespace Geekbot.net.Commands.Games namespace Geekbot.net.Commands.Games.Roll
{ {
public class Roll : ModuleBase public class Roll : ModuleBase
{ {
@ -42,17 +42,18 @@ namespace Geekbot.net.Commands.Games
{ {
var kvKey = $"{Context.Guild.Id}:{Context.User.Id}:RollsPrevious"; var kvKey = $"{Context.Guild.Id}:{Context.User.Id}:RollsPrevious";
var prevRoll = _kvInMemoryStore.Get<int>(kvKey); var prevRoll = _kvInMemoryStore.Get<RollTimeout>(kvKey);
if (prevRoll > 0)
if (prevRoll?.LastGuess == guess && prevRoll?.GuessedOn.AddDays(1) > DateTime.Now)
{ {
if (prevRoll == guess) await ReplyAsync(transContext.GetString(
{ "NoPrevGuess",
await ReplyAsync(transContext.GetString("NoPrevGuess", Context.Message.Author.Mention)); Context.Message.Author.Mention,
transContext.FormatDateTimeAsRemaining(prevRoll.GuessedOn.AddDays(1))));
return; return;
} }
}
_kvInMemoryStore.Set(kvKey, guess); _kvInMemoryStore.Set(kvKey, new RollTimeout { LastGuess = guess, GuessedOn = DateTime.Now });
await ReplyAsync(transContext.GetString("Rolled", Context.Message.Author.Mention, number, guess)); await ReplyAsync(transContext.GetString("Rolled", Context.Message.Author.Mention, number, guess));
if (guess == number) if (guess == number)

View file

@ -0,0 +1,10 @@
using System;
namespace Geekbot.net.Commands.Games.Roll
{
public class RollTimeout
{
public int LastGuess { get; set; }
public DateTime GuessedOn { get; set; }
}
}

View file

@ -83,8 +83,8 @@ roll:
EN: "{0}, you rolled {1}" EN: "{0}, you rolled {1}"
CHDE: "{0}, du hesch {1} grollt" CHDE: "{0}, du hesch {1} grollt"
NoPrevGuess: NoPrevGuess:
EN: ":red_circle: {0}, you can't guess the same number again" EN: ":red_circle: {0}, you can't guess the same number again, guess another number or wait {1}"
CHDE: ":red_circle: {0}, du chasch nid nomol es gliche rate" CHDE: ":red_circle: {0}, du chasch nid nomol es gliche rate, rate öppis anders oder warte {1}"
cookies: &cookiesAlias cookies: &cookiesAlias
GetCookies: GetCookies:
EN: "You got {0} cookies, there are now {1} cookies in you cookie jar" EN: "You got {0} cookies, there are now {1} cookies in you cookie jar"