From 93480f9b4d2bce4ac532631fa931c38f8ef47c87 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 13 Oct 2016 00:32:11 +0200 Subject: [PATCH] Clash of clans crashfix --- src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs | 5 ++++- src/NadekoBot/NadekoBot.cs | 2 ++ src/NadekoBot/Services/CommandHandler.cs | 2 +- .../Database/Repositories/IClashOfClansRepository.cs | 2 +- .../Database/Repositories/Impl/ClashOfClansRepository.cs | 6 ++++++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs index 6bc586fe..89c77f11 100644 --- a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs +++ b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs @@ -25,13 +25,16 @@ namespace NadekoBot.Modules.ClashOfClans { ClashWars = new ConcurrentDictionary>( uow.ClashOfClans - .GetAll() + .GetAllWars() .Select(cw => { + if (cw == null || cw.Bases == null) + return null; cw.Channel = NadekoBot.Client.GetGuild(cw.GuildId) ?.GetTextChannel(cw.ChannelId); cw.Bases.Capacity = cw.Size; return cw; }) + .Where(cw => cw?.Channel != null) .GroupBy(cw => cw.GuildId) .ToDictionary(g => g.Key, g => g.ToList())); } diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index 584f7cbc..f43193ba 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -36,6 +36,7 @@ namespace NadekoBot public static StatsService Stats { get; private set; } public static ConcurrentDictionary ModulePrefixes { get; private set; } + public static bool Ready { get; private set; } public async Task RunAsync(string[] args) { @@ -97,6 +98,7 @@ namespace NadekoBot #if !GLOBAL_NADEKO await CommandService.Load(new Music(Localizer, CommandService, Client, Google)).ConfigureAwait(false); #endif + Ready = true; Console.WriteLine(await Stats.Print().ConfigureAwait(false)); await Task.Delay(-1); diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index db833d29..21bce20e 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -72,7 +72,7 @@ namespace NadekoBot.Services if (usrMsg == null) return; - if (usrMsg.Author.IsBot) //no bots + if (usrMsg.Author.IsBot || !NadekoBot.Ready) //no bots return; var guild = (msg.Channel as ITextChannel)?.Guild; diff --git a/src/NadekoBot/Services/Database/Repositories/IClashOfClansRepository.cs b/src/NadekoBot/Services/Database/Repositories/IClashOfClansRepository.cs index 1d395d4d..31a4574c 100644 --- a/src/NadekoBot/Services/Database/Repositories/IClashOfClansRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/IClashOfClansRepository.cs @@ -9,6 +9,6 @@ namespace NadekoBot.Services.Database.Repositories { public interface IClashOfClansRepository : IRepository { - + IEnumerable GetAllWars(); } } diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/ClashOfClansRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/ClashOfClansRepository.cs index c2016800..78b2aaf3 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/ClashOfClansRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/ClashOfClansRepository.cs @@ -13,5 +13,11 @@ namespace NadekoBot.Services.Database.Repositories.Impl public ClashOfClansRepository(DbContext context) : base(context) { } + + public IEnumerable GetAllWars() + { + return _set.Include(cw => cw.Bases) + .ToList(); + } } }