Abstract away redis even more with AlmostRedis.cs

This commit is contained in:
Runebaas 2018-05-26 02:33:45 +02:00
parent f53258e348
commit 35f0a5c8f8
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
10 changed files with 153 additions and 78 deletions

View file

@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using Discord.Commands;
using Geekbot.net.Lib.AlmostRedis;
using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.Localization;
using StackExchange.Redis;
@ -10,10 +11,10 @@ namespace Geekbot.net.Commands.Games
public class Roll : ModuleBase
{
private readonly IErrorHandler _errorHandler;
private readonly IDatabase _redis;
private readonly IAlmostRedis _redis;
private readonly ITranslationHandler _translation;
public Roll(IDatabase redis, IErrorHandler errorHandler, ITranslationHandler translation)
public Roll(IAlmostRedis redis, IErrorHandler errorHandler, ITranslationHandler translation)
{
_redis = redis;
_translation = translation;
@ -32,20 +33,20 @@ namespace Geekbot.net.Commands.Games
var transDict = _translation.GetDict(Context);
if (guess <= 100 && guess > 0)
{
var prevRoll = _redis.HashGet($"{Context.Guild.Id}:RollsPrevious", Context.Message.Author.Id);
var prevRoll = _redis.Db.HashGet($"{Context.Guild.Id}:RollsPrevious", Context.Message.Author.Id);
if (!prevRoll.IsNullOrEmpty && prevRoll.ToString() == guess.ToString())
{
await ReplyAsync(string.Format(transDict["NoPrevGuess"], Context.Message.Author.Mention));
return;
}
_redis.HashSet($"{Context.Guild.Id}:RollsPrevious",
_redis.Db.HashSet($"{Context.Guild.Id}:RollsPrevious",
new[] {new HashEntry(Context.Message.Author.Id, guess)});
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());
_redis.Db.HashIncrement($"{Context.Guild.Id}:Rolls", Context.User.Id.ToString());
}
}
else