mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
Fixed images not automatically reloading on startup if the keys don't exist
This commit is contained in:
@@ -11,11 +11,12 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using Serilog;
|
||||
|
||||
namespace NadekoBot.Services
|
||||
{
|
||||
public sealed class RedisImagesCache : IImageCache
|
||||
public sealed class RedisImagesCache : IImageCache, IReadyExecutor
|
||||
{
|
||||
private readonly ConnectionMultiplexer _con;
|
||||
private readonly IBotCredentials _creds;
|
||||
@@ -73,6 +74,14 @@ namespace NadekoBot.Services
|
||||
Currency,
|
||||
}
|
||||
|
||||
public async Task OnReadyAsync()
|
||||
{
|
||||
if (await AllKeysExist())
|
||||
return;
|
||||
|
||||
await Reload();
|
||||
}
|
||||
|
||||
public RedisImagesCache(ConnectionMultiplexer con, IBotCredentials creds)
|
||||
{
|
||||
_con = con;
|
||||
|
@@ -5,7 +5,6 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
|
||||
namespace NadekoBot.Services
|
||||
@@ -20,12 +19,13 @@ namespace NadekoBot.Services
|
||||
private readonly string _redisKey;
|
||||
private readonly EndPoint _redisEndpoint;
|
||||
|
||||
public RedisCache(ConnectionMultiplexer redis, IBotCredentials creds, DiscordSocketClient client)
|
||||
public RedisCache(ConnectionMultiplexer redis, IBotCredentials creds,
|
||||
IImageCache imageCache, ILocalDataCache dataCache)
|
||||
{
|
||||
Redis = redis;
|
||||
_redisEndpoint = Redis.GetEndPoints().First();
|
||||
LocalImages = new RedisImagesCache(Redis, creds);
|
||||
LocalData = new RedisLocalDataCache(Redis, creds, client.ShardId);
|
||||
LocalImages = imageCache;
|
||||
LocalData = dataCache;
|
||||
_redisKey = creds.RedisKey();
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using Serilog;
|
||||
|
||||
namespace NadekoBot.Services
|
||||
@@ -25,56 +27,33 @@ namespace NadekoBot.Services
|
||||
|
||||
public IReadOnlyDictionary<string, SearchPokemon> Pokemons
|
||||
{
|
||||
get
|
||||
{
|
||||
return Get<Dictionary<string, SearchPokemon>>("pokemon_list");
|
||||
}
|
||||
private set
|
||||
{
|
||||
Set("pokemon_list", value);
|
||||
}
|
||||
get => Get<Dictionary<string, SearchPokemon>>("pokemon_list");
|
||||
private set => Set("pokemon_list", value);
|
||||
}
|
||||
|
||||
public IReadOnlyDictionary<string, SearchPokemonAbility> PokemonAbilities
|
||||
{
|
||||
get
|
||||
{
|
||||
return Get<Dictionary<string, SearchPokemonAbility>>("pokemon_abilities");
|
||||
}
|
||||
private set
|
||||
{
|
||||
Set("pokemon_abilities", value);
|
||||
}
|
||||
get => Get<Dictionary<string, SearchPokemonAbility>>("pokemon_abilities");
|
||||
private set => Set("pokemon_abilities", value);
|
||||
}
|
||||
|
||||
public TriviaQuestion[] TriviaQuestions
|
||||
{
|
||||
get
|
||||
{
|
||||
return Get<TriviaQuestion[]>("trivia_questions");
|
||||
}
|
||||
private set
|
||||
{
|
||||
Set("trivia_questions", value);
|
||||
}
|
||||
get => Get<TriviaQuestion[]>("trivia_questions");
|
||||
private set => Set("trivia_questions", value);
|
||||
}
|
||||
|
||||
public IReadOnlyDictionary<int, string> PokemonMap
|
||||
{
|
||||
get
|
||||
{
|
||||
return Get<Dictionary<int, string>>("pokemon_map");
|
||||
}
|
||||
private set
|
||||
{
|
||||
Set("pokemon_map", value);
|
||||
}
|
||||
get => Get<Dictionary<int, string>>("pokemon_map");
|
||||
private set => Set("pokemon_map", value);
|
||||
}
|
||||
|
||||
public RedisLocalDataCache(ConnectionMultiplexer con, IBotCredentials creds, int shardId)
|
||||
public RedisLocalDataCache(ConnectionMultiplexer con, IBotCredentials creds, DiscordSocketClient client)
|
||||
{
|
||||
_con = con;
|
||||
_creds = creds;
|
||||
var shardId = client.ShardId;
|
||||
|
||||
if (shardId == 0)
|
||||
{
|
||||
|
Reference in New Issue
Block a user