mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
Base for 4.3 work. Split Nadeko.Common into a separate project
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#nullable disable
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using NadekoBot.Modules.Games.Common;
|
||||
using NadekoBot.Modules.Games.Common.Acrophobia;
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using Image = SixLabors.ImageSharp.Image;
|
||||
|
@@ -1,3 +1,4 @@
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Modules.Games.Hangman;
|
||||
|
||||
namespace NadekoBot.Modules.Games;
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#nullable disable
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using NadekoBot.Db;
|
||||
using NadekoBot.Modules.Games.Common;
|
||||
|
33
src/NadekoBot/Modules/Games/Trivia/DefaultQuestionPool.cs
Normal file
33
src/NadekoBot/Modules/Games/Trivia/DefaultQuestionPool.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
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?> GetRandomQuestionAsync(ISet<TriviaQuestion> exclude)
|
||||
{
|
||||
TriviaQuestion randomQuestion;
|
||||
var pool = await _cache.GetTriviaQuestionsAsync();
|
||||
|
||||
if(pool is null)
|
||||
return default;
|
||||
|
||||
while (exclude.Contains(randomQuestion = new(pool[_rng.Next(0, pool.Length)])))
|
||||
{
|
||||
// if too many questions are excluded, clear the exclusion list and start over
|
||||
if (exclude.Count > pool.Length / 10 * 9)
|
||||
{
|
||||
exclude.Clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return randomQuestion;
|
||||
}
|
||||
}
|
6
src/NadekoBot/Modules/Games/Trivia/IQuestionPool.cs
Normal file
6
src/NadekoBot/Modules/Games/Trivia/IQuestionPool.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace NadekoBot.Modules.Games.Common.Trivia;
|
||||
|
||||
public interface IQuestionPool
|
||||
{
|
||||
Task<TriviaQuestion?> GetRandomQuestionAsync(ISet<TriviaQuestion> exclude);
|
||||
}
|
32
src/NadekoBot/Modules/Games/Trivia/PokemonQuestionPool.cs
Normal file
32
src/NadekoBot/Modules/Games/Trivia/PokemonQuestionPool.cs
Normal 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?> GetRandomQuestionAsync(ISet<TriviaQuestion> exclude)
|
||||
{
|
||||
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"
|
||||
});
|
||||
}
|
||||
}
|
@@ -234,9 +234,9 @@ public class TriviaGame
|
||||
|
||||
if (!guess)
|
||||
return;
|
||||
|
||||
triviaCancelSource.Cancel();
|
||||
|
||||
|
||||
if (_options.WinRequirement != 0 && Users[guildUser] == _options.WinRequirement)
|
||||
{
|
||||
ShouldStopGame = true;
|
||||
|
Reference in New Issue
Block a user