mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
Trivia game cleanup
This commit is contained in:
@@ -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)]);
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
namespace NadekoBot.Modules.Games.Common.Trivia;
|
||||
|
||||
public interface IQuestionPool
|
||||
{
|
||||
Task<TriviaQuestion?> GetQuestionAsync();
|
||||
}
|
@@ -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"
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user