Allow the same guess after 24h again with !roll

This commit is contained in:
runebaas 2018-07-22 15:02:53 +02:00
parent 83f3c61661
commit 948c48909e
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
2 changed files with 11 additions and 8 deletions

View file

@ -34,15 +34,18 @@ namespace Geekbot.net.Commands.Games
var transDict = _translation.GetDict(Context); var transDict = _translation.GetDict(Context);
if (guess <= 100 && guess > 0) if (guess <= 100 && guess > 0)
{ {
var prevRoll = _redis.HashGet($"{Context.Guild.Id}:RollsPrevious", Context.Message.Author.Id); var prevRoll = _redis.HashGet($"{Context.Guild.Id}:RollsPrevious2", Context.Message.Author.Id).ToString()?.Split('|');
if (!prevRoll.IsNullOrEmpty && prevRoll.ToString() == guess.ToString()) if (prevRoll?.Length == 2)
{
if (prevRoll[0] == guess.ToString() && DateTime.Parse(prevRoll[1]) > DateTime.Now.AddDays(-1))
{ {
await ReplyAsync(string.Format(transDict["NoPrevGuess"], Context.Message.Author.Mention)); await ReplyAsync(string.Format(transDict["NoPrevGuess"], Context.Message.Author.Mention));
return; return;
} }
}
_redis.HashSet($"{Context.Guild.Id}:RollsPrevious", _redis.HashSet($"{Context.Guild.Id}:RollsPrevious2",
new[] {new HashEntry(Context.Message.Author.Id, guess)}); new[] {new HashEntry(Context.Message.Author.Id, $"{guess}|{DateTime.Now}")});
await ReplyAsync(string.Format(transDict["Rolled"], Context.Message.Author.Mention, number, guess)); await ReplyAsync(string.Format(transDict["Rolled"], Context.Message.Author.Mention, number, guess));
if (guess == number) if (guess == number)
{ {

View file

@ -93,8 +93,8 @@
"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 within 24 hours",
"CHDE": ":red_circle: {0}, du chasch nid nomol es gliche rate" "CHDE": ":red_circle: {0}, du chasch nid nomol es gliche rate innerhalb vo 24 stund"
} }
} }
} }