diff --git a/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs b/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs index b2e8115f..e454809a 100644 --- a/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs @@ -27,12 +27,8 @@ namespace NadekoBot.Modules.Administration { _log = LogManager.GetCurrentClassLogger(); - using (var uow = DbHandler.UnitOfWork()) - { - var conf = uow.BotConfig.GetOrCreate(); - RotatingStatusMessages = conf.RotatingStatusMessages; - RotatingStatuses = conf.RotatingStatuses; - } + RotatingStatusMessages = NadekoBot.BotConfig.RotatingStatusMessages; + RotatingStatuses = NadekoBot.BotConfig.RotatingStatuses; var t = Task.Run(async () => { diff --git a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs index 9acd88e4..8c5b0243 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs @@ -77,7 +77,7 @@ namespace NadekoBot.Modules.Gambling using (var uow = DbHandler.UnitOfWork()) { - animals = new ConcurrentQueue(uow.BotConfig.GetOrCreate().RaceAnimals.Select(ra => ra.Icon).Shuffle()); + animals = new ConcurrentQueue(NadekoBot.BotConfig.RaceAnimals.Select(ra => ra.Icon).Shuffle()); } diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index bbff2239..401f6995 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -20,14 +20,9 @@ namespace NadekoBot.Modules.Gambling static Gambling() { - using (var uow = DbHandler.UnitOfWork()) - { - var conf = uow.BotConfig.GetOrCreate(); - - CurrencyName = conf.CurrencyName; - CurrencySign = conf.CurrencySign; - CurrencyPluralName = conf.CurrencyPluralName; - } + CurrencyName = NadekoBot.BotConfig.CurrencyName; + CurrencyPluralName = NadekoBot.BotConfig.CurrencyPluralName; + CurrencySign = NadekoBot.BotConfig.CurrencySign; } public static long GetCurrency(ulong id) diff --git a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs index 015b4328..29a996fc 100644 --- a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs @@ -38,32 +38,17 @@ namespace NadekoBot.Modules.Games private static ConcurrentHashSet usersRecentlyPicked { get; } = new ConcurrentHashSet(); - private static float chance { get; } - private static int cooldown { get; } private static Logger _log { get; } static PlantPickCommands() { _log = LogManager.GetCurrentClassLogger(); - var sw = Stopwatch.StartNew(); - #if !GLOBAL_NADEKO NadekoBot.Client.MessageReceived += PotentialFlowerGeneration; #endif - - using (var uow = DbHandler.UnitOfWork()) - { - var conf = uow.BotConfig.GetOrCreate(); - var x = - generationChannels = new ConcurrentHashSet(NadekoBot.AllGuildConfigs - .SelectMany(c => c.GenerateCurrencyChannelIds.Select(obj => obj.ChannelId))); - chance = conf.CurrencyGenerationChance; - cooldown = conf.CurrencyGenerationCooldown; - } - - sw.Stop(); - _log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s"); + generationChannels = new ConcurrentHashSet(NadekoBot.AllGuildConfigs + .SelectMany(c => c.GenerateCurrencyChannelIds.Select(obj => obj.ChannelId))); } private static async void PotentialFlowerGeneration(SocketMessage imsg) @@ -84,10 +69,10 @@ namespace NadekoBot.Modules.Games var lastGeneration = lastGenerations.GetOrAdd(channel.Id, DateTime.MinValue); var rng = new NadekoRandom(); - if (DateTime.Now - TimeSpan.FromSeconds(cooldown) < lastGeneration) //recently generated in this channel, don't generate again + if (DateTime.Now - TimeSpan.FromSeconds(NadekoBot.BotConfig.CurrencyGenerationCooldown) < lastGeneration) //recently generated in this channel, don't generate again return; - var num = rng.Next(1, 101) + chance * 100; + var num = rng.Next(1, 101) + NadekoBot.BotConfig.CurrencyGenerationChance * 100; if (num > 100) { diff --git a/src/NadekoBot/Modules/Games/Games.cs b/src/NadekoBot/Modules/Games/Games.cs index 3278518e..10d652b4 100644 --- a/src/NadekoBot/Modules/Games/Games.cs +++ b/src/NadekoBot/Modules/Games/Games.cs @@ -13,14 +13,7 @@ namespace NadekoBot.Modules.Games [NadekoModule("Games", ">")] public partial class Games : DiscordModule { - private IEnumerable _8BallResponses { - get { - using (var uow = DbHandler.UnitOfWork()) - { - return uow.BotConfig.GetOrCreate().EightBallResponses.Select(ebr => ebr.Text); - } - } - } + private static IEnumerable _8BallResponses { get; } = NadekoBot.BotConfig.EightBallResponses.Select(ebr => ebr.Text); [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 87f31de0..4fee9ae6 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -15,26 +15,10 @@ namespace NadekoBot.Modules.Help [NadekoModule("Help", "-")] public partial class Help : DiscordModule { - private static string helpString { get; } + private static string helpString { get; } = NadekoBot.BotConfig.HelpString; public static string HelpString => String.Format(helpString, NadekoBot.Credentials.ClientId, NadekoBot.ModulePrefixes[typeof(Help).Name]); - public static string DMHelpString { get; } - - static Help() - { - - //todo don't cache this, just query db when someone wants -h - using (var uow = DbHandler.UnitOfWork()) - { - var config = uow.BotConfig.GetOrCreate(); - helpString = config.HelpString; - DMHelpString = config.DMHelpString; - } - } - - public Help() : base() - { - } + public static string DMHelpString { get; } = NadekoBot.BotConfig.DMHelpString; [NadekoCommand, Usage, Description, Aliases] public async Task Modules() diff --git a/src/NadekoBot/Modules/Utility/Commands/Remind.cs b/src/NadekoBot/Modules/Utility/Commands/Remind.cs index 58660bce..7d371c22 100644 --- a/src/NadekoBot/Modules/Utility/Commands/Remind.cs +++ b/src/NadekoBot/Modules/Utility/Commands/Remind.cs @@ -40,9 +40,8 @@ namespace NadekoBot.Modules.Utility using (var uow = DbHandler.UnitOfWork()) { reminders = uow.Reminders.GetAll().ToList(); - - RemindMessageFormat = uow.BotConfig.GetOrCreate().RemindMessageFormat; } + RemindMessageFormat = NadekoBot.BotConfig.RemindMessageFormat; foreach (var r in reminders) { diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index 9f72a07f..a0bce533 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -38,6 +38,7 @@ namespace NadekoBot public static bool Ready { get; private set; } public static IEnumerable AllGuildConfigs { get; } + public static BotConfig BotConfig { get; } static NadekoBot() { @@ -47,6 +48,7 @@ namespace NadekoBot using (var uow = DbHandler.UnitOfWork()) { AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs(); + BotConfig = uow.BotConfig.GetOrCreate(); } } @@ -98,10 +100,9 @@ namespace NadekoBot _log.Info("Connected"); //load commands and prefixes - using (var uow = DbHandler.UnitOfWork()) - { - ModulePrefixes = new ConcurrentDictionary(uow.BotConfig.GetOrCreate().ModulePrefixes.OrderByDescending(mp => mp.Prefix.Length).ToDictionary(m => m.ModuleName, m => m.Prefix)); - } + + ModulePrefixes = new ConcurrentDictionary(NadekoBot.BotConfig.ModulePrefixes.OrderByDescending(mp => mp.Prefix.Length).ToDictionary(m => m.ModuleName, m => m.Prefix)); + // start handling messages received in commandhandler await CommandHandler.StartHandling().ConfigureAwait(false);