Fixed exclusion list after restarts, closes #1571
This commit is contained in:
parent
3de9a40ffd
commit
927e98514a
@ -27,11 +27,11 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
|||||||
public IGuild Guild { get; }
|
public IGuild Guild { get; }
|
||||||
public ITextChannel Channel { get; }
|
public ITextChannel Channel { get; }
|
||||||
|
|
||||||
private int questionDurationMiliseconds { get; } = 30000;
|
private readonly int _questionDurationMiliseconds = 30000;
|
||||||
private int hintTimeoutMiliseconds { get; } = 6000;
|
private readonly int _hintTimeoutMiliseconds = 6000;
|
||||||
public bool ShowHints { get; }
|
public bool ShowHints { get; }
|
||||||
public bool IsPokemon { get; }
|
public bool IsPokemon { get; }
|
||||||
private CancellationTokenSource triviaCancelSource { get; set; }
|
private CancellationTokenSource _triviaCancelSource;
|
||||||
|
|
||||||
public TriviaQuestion CurrentQuestion { get; private set; }
|
public TriviaQuestion CurrentQuestion { get; private set; }
|
||||||
public HashSet<TriviaQuestion> OldQuestions { get; } = new HashSet<TriviaQuestion>();
|
public HashSet<TriviaQuestion> OldQuestions { get; } = new HashSet<TriviaQuestion>();
|
||||||
@ -71,7 +71,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
|||||||
while (!ShouldStopGame)
|
while (!ShouldStopGame)
|
||||||
{
|
{
|
||||||
// reset the cancellation source
|
// reset the cancellation source
|
||||||
triviaCancelSource = new CancellationTokenSource();
|
_triviaCancelSource = new CancellationTokenSource();
|
||||||
|
|
||||||
// load question
|
// load question
|
||||||
CurrentQuestion = TriviaQuestionPool.Instance.GetRandomQuestion(OldQuestions, IsPokemon);
|
CurrentQuestion = TriviaQuestionPool.Instance.GetRandomQuestion(OldQuestions, IsPokemon);
|
||||||
@ -118,7 +118,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//hint
|
//hint
|
||||||
await Task.Delay(hintTimeoutMiliseconds, triviaCancelSource.Token).ConfigureAwait(false);
|
await Task.Delay(_hintTimeoutMiliseconds, _triviaCancelSource.Token).ConfigureAwait(false);
|
||||||
if (ShowHints)
|
if (ShowHints)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -132,7 +132,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
|||||||
catch (Exception ex) { _log.Warn(ex); }
|
catch (Exception ex) { _log.Warn(ex); }
|
||||||
|
|
||||||
//timeout
|
//timeout
|
||||||
await Task.Delay(questionDurationMiliseconds - hintTimeoutMiliseconds, triviaCancelSource.Token).ConfigureAwait(false);
|
await Task.Delay(_questionDurationMiliseconds - _hintTimeoutMiliseconds, _triviaCancelSource.Token).ConfigureAwait(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (TaskCanceledException) { } //means someone guessed the answer
|
catch (TaskCanceledException) { } //means someone guessed the answer
|
||||||
@ -142,7 +142,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
|||||||
GameActive = false;
|
GameActive = false;
|
||||||
_client.MessageReceived -= PotentialGuess;
|
_client.MessageReceived -= PotentialGuess;
|
||||||
}
|
}
|
||||||
if (!triviaCancelSource.IsCancellationRequested)
|
if (!_triviaCancelSource.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -202,7 +202,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
|||||||
await _guessLock.WaitAsync().ConfigureAwait(false);
|
await _guessLock.WaitAsync().ConfigureAwait(false);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (GameActive && CurrentQuestion.IsAnswerCorrect(umsg.Content) && !triviaCancelSource.IsCancellationRequested)
|
if (GameActive && CurrentQuestion.IsAnswerCorrect(umsg.Content) && !_triviaCancelSource.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
Users.AddOrUpdate(guildUser, 1, (gu, old) => ++old);
|
Users.AddOrUpdate(guildUser, 1, (gu, old) => ++old);
|
||||||
guess = true;
|
guess = true;
|
||||||
@ -210,7 +210,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
|||||||
}
|
}
|
||||||
finally { _guessLock.Release(); }
|
finally { _guessLock.Release(); }
|
||||||
if (!guess) return;
|
if (!guess) return;
|
||||||
triviaCancelSource.Cancel();
|
_triviaCancelSource.Cancel();
|
||||||
|
|
||||||
|
|
||||||
if (Users[guildUser] == WinRequirement)
|
if (Users[guildUser] == WinRequirement)
|
||||||
|
@ -78,6 +78,31 @@ namespace NadekoBot.Modules.Xp.Services
|
|||||||
_log = LogManager.GetCurrentClassLogger();
|
_log = LogManager.GetCurrentClassLogger();
|
||||||
_strings = strings;
|
_strings = strings;
|
||||||
|
|
||||||
|
//load settings
|
||||||
|
_excludedChannels = allGuildConfigs
|
||||||
|
.ToDictionary(
|
||||||
|
x => x.GuildId,
|
||||||
|
x => new ConcurrentHashSet<ulong>(x.XpSettings
|
||||||
|
.ExclusionList
|
||||||
|
.Where(ex => ex.ItemType == ExcludedItemType.Channel)
|
||||||
|
.Select(ex => ex.ItemId)
|
||||||
|
.Distinct()))
|
||||||
|
.ToConcurrent();
|
||||||
|
|
||||||
|
_excludedRoles = allGuildConfigs
|
||||||
|
.ToDictionary(
|
||||||
|
x => x.GuildId,
|
||||||
|
x => new ConcurrentHashSet<ulong>(x.XpSettings
|
||||||
|
.ExclusionList
|
||||||
|
.Where(ex => ex.ItemType == ExcludedItemType.Role)
|
||||||
|
.Select(ex => ex.ItemId)
|
||||||
|
.Distinct()))
|
||||||
|
.ToConcurrent();
|
||||||
|
|
||||||
|
_excludedServers = new ConcurrentHashSet<ulong>(
|
||||||
|
allGuildConfigs.Where(x => x.XpSettings.ServerExcluded)
|
||||||
|
.Select(x => x.GuildId));
|
||||||
|
|
||||||
//todo 60 move to font provider or somethign
|
//todo 60 move to font provider or somethign
|
||||||
_fonts = new FontCollection();
|
_fonts = new FontCollection();
|
||||||
if (Directory.Exists("data/fonts"))
|
if (Directory.Exists("data/fonts"))
|
||||||
|
@ -47,6 +47,8 @@ namespace NadekoBot.Services.Database.Repositories.Impl
|
|||||||
.Include(gc => gc.FollowedStreams)
|
.Include(gc => gc.FollowedStreams)
|
||||||
.Include(gc => gc.StreamRole)
|
.Include(gc => gc.StreamRole)
|
||||||
.Include(gc => gc.NsfwBlacklistedTags)
|
.Include(gc => gc.NsfwBlacklistedTags)
|
||||||
|
.Include(gc => gc.XpSettings)
|
||||||
|
.ThenInclude(x => x.ExclusionList)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user