Fixed exclusion list after restarts, closes #1571

This commit is contained in:
Master Kwoth 2017-09-11 00:21:14 +02:00
parent 3de9a40ffd
commit 927e98514a
3 changed files with 36 additions and 9 deletions

View File

@ -27,11 +27,11 @@ namespace NadekoBot.Modules.Games.Common.Trivia
public IGuild Guild { get; }
public ITextChannel Channel { get; }
private int questionDurationMiliseconds { get; } = 30000;
private int hintTimeoutMiliseconds { get; } = 6000;
private readonly int _questionDurationMiliseconds = 30000;
private readonly int _hintTimeoutMiliseconds = 6000;
public bool ShowHints { get; }
public bool IsPokemon { get; }
private CancellationTokenSource triviaCancelSource { get; set; }
private CancellationTokenSource _triviaCancelSource;
public TriviaQuestion CurrentQuestion { get; private set; }
public HashSet<TriviaQuestion> OldQuestions { get; } = new HashSet<TriviaQuestion>();
@ -71,7 +71,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
while (!ShouldStopGame)
{
// reset the cancellation source
triviaCancelSource = new CancellationTokenSource();
_triviaCancelSource = new CancellationTokenSource();
// load question
CurrentQuestion = TriviaQuestionPool.Instance.GetRandomQuestion(OldQuestions, IsPokemon);
@ -118,7 +118,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
try
{
//hint
await Task.Delay(hintTimeoutMiliseconds, triviaCancelSource.Token).ConfigureAwait(false);
await Task.Delay(_hintTimeoutMiliseconds, _triviaCancelSource.Token).ConfigureAwait(false);
if (ShowHints)
try
{
@ -132,7 +132,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
catch (Exception ex) { _log.Warn(ex); }
//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
@ -142,7 +142,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
GameActive = false;
_client.MessageReceived -= PotentialGuess;
}
if (!triviaCancelSource.IsCancellationRequested)
if (!_triviaCancelSource.IsCancellationRequested)
{
try
{
@ -202,7 +202,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
await _guessLock.WaitAsync().ConfigureAwait(false);
try
{
if (GameActive && CurrentQuestion.IsAnswerCorrect(umsg.Content) && !triviaCancelSource.IsCancellationRequested)
if (GameActive && CurrentQuestion.IsAnswerCorrect(umsg.Content) && !_triviaCancelSource.IsCancellationRequested)
{
Users.AddOrUpdate(guildUser, 1, (gu, old) => ++old);
guess = true;
@ -210,7 +210,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
}
finally { _guessLock.Release(); }
if (!guess) return;
triviaCancelSource.Cancel();
_triviaCancelSource.Cancel();
if (Users[guildUser] == WinRequirement)

View File

@ -78,6 +78,31 @@ namespace NadekoBot.Modules.Xp.Services
_log = LogManager.GetCurrentClassLogger();
_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
_fonts = new FontCollection();
if (Directory.Exists("data/fonts"))

View File

@ -47,6 +47,8 @@ namespace NadekoBot.Services.Database.Repositories.Impl
.Include(gc => gc.FollowedStreams)
.Include(gc => gc.StreamRole)
.Include(gc => gc.NsfwBlacklistedTags)
.Include(gc => gc.XpSettings)
.ThenInclude(x => x.ExclusionList)
.ToList();
/// <summary>