diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index 17a74f35..46176fcf 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -36,7 +36,7 @@ namespace NadekoBot.Modules.Administration { using (var uow = DbHandler.UnitOfWork()) { - var configs = uow.GuildConfigs.GetAll(); + var configs = NadekoBot.AllGuildConfigs; GuildMuteRoles = new ConcurrentDictionary(configs .Where(c=>!string.IsNullOrWhiteSpace(c.MuteRoleName)) .ToDictionary(c => c.GuildId, c => c.MuteRoleName)); diff --git a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs index 1ee43243..40ac1a5d 100644 --- a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs @@ -41,8 +41,7 @@ namespace NadekoBot.Modules.Administration using (var uow = DbHandler.UnitOfWork()) { - GuildLogSettings = new ConcurrentDictionary(uow.GuildConfigs - .GetAll() + GuildLogSettings = new ConcurrentDictionary(NadekoBot.AllGuildConfigs .ToDictionary(g => g.GuildId, g => g.LogSetting)); } diff --git a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs index d9451afc..cd9b4bc2 100644 --- a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs @@ -25,7 +25,7 @@ namespace NadekoBot.Modules.Administration { using (var uow = DbHandler.UnitOfWork()) { - voicePlusTextCache = new ConcurrentHashSet(uow.GuildConfigs.GetAll().Where(g => g.VoicePlusTextEnabled).Select(g => g.GuildId)); + voicePlusTextCache = new ConcurrentHashSet(NadekoBot.AllGuildConfigs.Where(g => g.VoicePlusTextEnabled).Select(g => g.GuildId)); } NadekoBot.Client.UserVoiceStateUpdated += UserUpdatedEventHandler; } diff --git a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs index c6ab6c12..4f78c620 100644 --- a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs @@ -54,7 +54,7 @@ namespace NadekoBot.Modules.Games { var conf = uow.BotConfig.GetOrCreate(); var x = - generationChannels = new ConcurrentHashSet(uow.GuildConfigs.GetAll() + generationChannels = new ConcurrentHashSet(NadekoBot.AllGuildConfigs .SelectMany(c => c.GenerateCurrencyChannelIds.Select(obj=>obj.ChannelId))); chance = conf.CurrencyGenerationChance; cooldown = conf.CurrencyGenerationCooldown; diff --git a/src/NadekoBot/Modules/Permissions/Commands/CmdCdsCommands.cs b/src/NadekoBot/Modules/Permissions/Commands/CmdCdsCommands.cs index 9cdd092b..97728db1 100644 --- a/src/NadekoBot/Modules/Permissions/Commands/CmdCdsCommands.cs +++ b/src/NadekoBot/Modules/Permissions/Commands/CmdCdsCommands.cs @@ -33,7 +33,7 @@ namespace NadekoBot.Modules.Permissions { using (var uow = DbHandler.UnitOfWork()) { - var configs = uow.GuildConfigs.GetAll(); + var configs = NadekoBot.AllGuildConfigs; commandCooldowns = new ConcurrentDictionary>(configs.ToDictionary(k => k.GuildId, v => new ConcurrentHashSet(v.CommandCooldowns))); } } diff --git a/src/NadekoBot/Modules/Permissions/Commands/FilterCommands.cs b/src/NadekoBot/Modules/Permissions/Commands/FilterCommands.cs index a6894929..006ecac9 100644 --- a/src/NadekoBot/Modules/Permissions/Commands/FilterCommands.cs +++ b/src/NadekoBot/Modules/Permissions/Commands/FilterCommands.cs @@ -46,7 +46,7 @@ namespace NadekoBot.Modules.Permissions { using (var uow = DbHandler.UnitOfWork()) { - var guildConfigs = uow.GuildConfigs.GetAll(); + var guildConfigs = NadekoBot.AllGuildConfigs; InviteFilteringServers = new ConcurrentHashSet(guildConfigs.Where(gc => gc.FilterInvites).Select(gc => gc.GuildId)); InviteFilteringChannels = new ConcurrentHashSet(guildConfigs.SelectMany(gc => gc.FilterInvitesChannelIds.Select(fci => fci.ChannelId))); diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index a50dd94c..31da82ab 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -19,6 +19,7 @@ using Module = Discord.Commands.Module; using NadekoBot.TypeReaders; using System.Collections.Concurrent; using NadekoBot.Modules.Music; +using NadekoBot.Services.Database.Models; namespace NadekoBot { @@ -38,6 +39,16 @@ namespace NadekoBot public static ConcurrentDictionary ModulePrefixes { get; private set; } public static bool Ready { get; private set; } + public static IEnumerable AllGuildConfigs { get; } + + static NadekoBot() + { + using (var uow = DbHandler.UnitOfWork()) + { + AllGuildConfigs = uow.GuildConfigs.GetAll(); + } + } + public async Task RunAsync(string[] args) { SetupLogger(); diff --git a/src/NadekoBot/Services/DbHandler.cs b/src/NadekoBot/Services/DbHandler.cs index ee1833dd..a2349560 100644 --- a/src/NadekoBot/Services/DbHandler.cs +++ b/src/NadekoBot/Services/DbHandler.cs @@ -19,18 +19,19 @@ namespace NadekoBot.Services static DbHandler() { } private DbHandler() { - switch (NadekoBot.Credentials.Db.Type.ToUpperInvariant()) - { - case "SQLITE": - dbType = typeof(NadekoSqliteContext); - break; - //case "SQLSERVER": - // dbType = typeof(NadekoSqlServerContext); - // break; - default: - break; + dbType = typeof(NadekoSqliteContext); + //switch (NadekoBot.Credentials.Db.Type.ToUpperInvariant()) + //{ + // case "SQLITE": + // dbType = typeof(NadekoSqliteContext); + // break; + // //case "SQLSERVER": + // // dbType = typeof(NadekoSqlServerContext); + // // break; + // default: + // break; - } + //} } public NadekoContext GetDbContext() =>