Trivia game cleanup

This commit is contained in:
Kwoth
2022-07-11 23:11:45 +00:00
parent ff779ad494
commit ea8e444b10
14 changed files with 494 additions and 444 deletions

View File

@@ -0,0 +1,22 @@
namespace NadekoBot.Modules.Games.Common.Trivia;
public sealed class DefaultQuestionPool : IQuestionPool
{
private readonly ILocalDataCache _cache;
private readonly NadekoRandom _rng;
public DefaultQuestionPool(ILocalDataCache cache)
{
_cache = cache;
_rng = new NadekoRandom();
}
public async Task<TriviaQuestion?> GetQuestionAsync()
{
var pool = await _cache.GetTriviaQuestionsAsync();
if(pool is null or {Length: 0})
return default;
return new(pool[_rng.Next(0, pool.Length)]);
}
}

View File

@@ -0,0 +1,6 @@
namespace NadekoBot.Modules.Games.Common.Trivia;
public interface IQuestionPool
{
Task<TriviaQuestion?> GetQuestionAsync();
}

View File

@@ -0,0 +1,32 @@
namespace NadekoBot.Modules.Games.Common.Trivia;
public sealed class PokemonQuestionPool : IQuestionPool
{
public int QuestionsCount => 721; // xd
private readonly NadekoRandom _rng;
private readonly ILocalDataCache _cache;
public PokemonQuestionPool(ILocalDataCache cache)
{
_cache = cache;
_rng = new NadekoRandom();
}
public async Task<TriviaQuestion?> GetQuestionAsync()
{
var pokes = await _cache.GetPokemonMapAsync();
if (pokes is null or { Count: 0 })
return default;
var num = _rng.Next(1, QuestionsCount + 1);
return new(new()
{
Question = "Who's That Pokémon?",
Answer = pokes[num].ToTitleCase(),
Category = "Pokemon",
ImageUrl = $@"https://nadeko.bot/images/pokemon/shadows/{num}.png",
AnswerImageUrl = $@"https://nadeko.bot/images/pokemon/real/{num}.png"
});
}
}