From 9163510eee9e5f6270a6cec3b8dfa16d87e6d366 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Thu, 20 Jul 2017 05:10:39 +0200 Subject: [PATCH] .bce command added, you can now edit BotConfig without editing the database and restarting the bot. Cleanup --- src/NadekoBot/Common/Attributes/Aliases.cs | 1 - .../Common/Attributes/Description.cs | 1 - .../Common/Attributes/NadekoCommand.cs | 1 - src/NadekoBot/Common/Attributes/Usage.cs | 1 - src/NadekoBot/Common/BotConfigEditType.cs | 20 ++++ .../20170612094138_verbose-errors.cs | 4 +- .../20170612234751_repeat time of day.cs | 1 - .../20170613231358_maxdropamount.cs | 4 +- .../Migrations/20170616154106_crstartswith.cs | 4 +- .../Migrations/20170714021615_stream-role.cs | 1 - .../20170719023924_streamrole-kw-bl-wl.cs | 1 - .../NadekoSqliteContextModelSnapshot.cs | 2 - .../Modules/Administration/LogCommands.cs | 1 - .../SelfAssignedRolesCommands.cs | 1 - .../Modules/Administration/SelfCommands.cs | 12 +- .../Services/AdministrationService.cs | 1 - .../Services/GameVoiceChannelService.cs | 1 - .../Administration/Services/PruneService.cs | 1 - .../Administration/Services/SelfService.cs | 15 ++- .../CustomReactions/Extensions/Extensions.cs | 1 - .../Services/CustomReactionsService.cs | 8 +- .../Modules/Gambling/AnimalRacingCommands.cs | 17 ++- .../Modules/Gambling/Common/Cards.cs | 1 - .../Gambling/CurrencyEventsCommands.cs | 12 +- .../Modules/Gambling/FlipCoinCommands.cs | 15 ++- .../Modules/Gambling/FlowerShopCommands.cs | 12 +- src/NadekoBot/Modules/Gambling/Gambling.cs | 22 ++-- .../Modules/Gambling/SlotCommands.cs | 21 ++-- .../Modules/Gambling/WaifuClaimCommands.cs | 18 +-- .../Modules/Games/AcropobiaCommands.cs | 1 - .../Modules/Games/Common/ChatterBotSession.cs | 1 - .../Games/Common/Hangman/HangmanGame.cs | 1 - src/NadekoBot/Modules/Games/Common/Poll.cs | 1 - .../Modules/Games/Common/Trivia/TriviaGame.cs | 7 +- .../Games/Common/Trivia/TriviaQuestionPool.cs | 1 - .../Modules/Games/Common/TypingGame.cs | 1 - .../Modules/Games/PlantAndPickCommands.cs | 14 +-- .../Modules/Games/Services/GamesService.cs | 18 +-- .../Modules/Games/TicTacToeCommands.cs | 1 - src/NadekoBot/Modules/Games/TriviaCommands.cs | 6 +- src/NadekoBot/Modules/Help/Help.cs | 9 +- .../Modules/Help/Services/HelpService.cs | 9 +- .../Exceptions/NotInVoiceChannelException.cs | 5 - .../Modules/Music/Common/MusicPlayer.cs | 1 - .../Modules/Music/Common/MusicQueue.cs | 2 - src/NadekoBot/Modules/Music/Music.cs | 1 - .../Modules/Music/Services/MusicService.cs | 5 +- src/NadekoBot/Modules/NSFW/NSFW.cs | 1 - src/NadekoBot/Modules/NadekoModule.cs | 1 - .../Common/PermissionsCollection.cs | 1 - .../Modules/Permissions/FilterCommands.cs | 1 - .../Modules/Permissions/Permissions.cs | 1 - .../Permissions/ResetPermissionsCommands.cs | 2 - .../Permissions/Services/BlacklistService.cs | 7 +- .../Services/GlobalPermissionService.cs | 10 +- src/NadekoBot/Modules/Pokemon/Pokemon.cs | 16 +-- .../Searches/Common/SearchImageCacher.cs | 1 - .../Modules/Searches/JokeCommands.cs | 1 - src/NadekoBot/Modules/Searches/LoLCommands.cs | 2 - .../Modules/Searches/PlaceCommands.cs | 1 - .../Modules/Searches/XkcdCommands.cs | 1 - .../Modules/Utility/BotConfigCommands.cs | 39 ++++++ .../Exceptions/StreamRoleNotFoundException.cs | 4 - .../StreamRolePermissionException.cs | 4 - .../Modules/Utility/PatreonCommands.cs | 7 +- .../Modules/Utility/QuoteCommands.cs | 1 - .../Modules/Utility/Services/RemindService.cs | 6 +- .../Utility/Services/VerboseErrorsService.cs | 3 +- src/NadekoBot/NadekoBot.cs | 14 +-- src/NadekoBot/NadekoBot.csproj | 4 - src/NadekoBot/Resources/CommandStrings.resx | 9 ++ src/NadekoBot/Services/CommandHandler.cs | 4 +- src/NadekoBot/Services/CurrencyService.cs | 8 +- .../Database/Models/StreamRoleSettings.cs | 6 +- .../Repositories/IReminderRepository.cs | 1 - .../Repositories/Impl/ReminderRepository.cs | 1 - .../Repositories/Impl/WarningsRepository.cs | 1 - src/NadekoBot/Services/IBotConfigProvider.cs | 12 ++ src/NadekoBot/Services/IImagesService.cs | 3 +- src/NadekoBot/Services/INService.cs | 8 +- .../Services/Impl/BotConfigProvider.cs | 111 ++++++++++++++++++ src/NadekoBot/Services/Impl/ImagesService.cs | 1 - .../Services/Impl/SyncPreconditionService.cs | 8 +- src/NadekoBot/Services/LogSetup.cs | 5 - src/NadekoBot/Services/ServiceProvider.cs | 11 ++ src/NadekoBot/_Extensions/Extensions.cs | 1 - .../_strings/ResponseStrings.en-US.json | 2 + 87 files changed, 353 insertions(+), 251 deletions(-) create mode 100644 src/NadekoBot/Common/BotConfigEditType.cs create mode 100644 src/NadekoBot/Modules/Utility/BotConfigCommands.cs create mode 100644 src/NadekoBot/Services/IBotConfigProvider.cs create mode 100644 src/NadekoBot/Services/Impl/BotConfigProvider.cs diff --git a/src/NadekoBot/Common/Attributes/Aliases.cs b/src/NadekoBot/Common/Attributes/Aliases.cs index 21e7c2ba..7f365078 100644 --- a/src/NadekoBot/Common/Attributes/Aliases.cs +++ b/src/NadekoBot/Common/Attributes/Aliases.cs @@ -1,7 +1,6 @@ using System.Linq; using System.Runtime.CompilerServices; using Discord.Commands; -using NadekoBot.Services; using NadekoBot.Services.Impl; namespace NadekoBot.Common.Attributes diff --git a/src/NadekoBot/Common/Attributes/Description.cs b/src/NadekoBot/Common/Attributes/Description.cs index 2a071518..1b0e7957 100644 --- a/src/NadekoBot/Common/Attributes/Description.cs +++ b/src/NadekoBot/Common/Attributes/Description.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using Discord.Commands; -using NadekoBot.Services; using NadekoBot.Services.Impl; namespace NadekoBot.Common.Attributes diff --git a/src/NadekoBot/Common/Attributes/NadekoCommand.cs b/src/NadekoBot/Common/Attributes/NadekoCommand.cs index 566c2640..a471e007 100644 --- a/src/NadekoBot/Common/Attributes/NadekoCommand.cs +++ b/src/NadekoBot/Common/Attributes/NadekoCommand.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using Discord.Commands; -using NadekoBot.Services; using NadekoBot.Services.Impl; namespace NadekoBot.Common.Attributes diff --git a/src/NadekoBot/Common/Attributes/Usage.cs b/src/NadekoBot/Common/Attributes/Usage.cs index d7c88ea8..2991c6aa 100644 --- a/src/NadekoBot/Common/Attributes/Usage.cs +++ b/src/NadekoBot/Common/Attributes/Usage.cs @@ -1,6 +1,5 @@ using System.Runtime.CompilerServices; using Discord.Commands; -using NadekoBot.Services; using NadekoBot.Services.Impl; namespace NadekoBot.Common.Attributes diff --git a/src/NadekoBot/Common/BotConfigEditType.cs b/src/NadekoBot/Common/BotConfigEditType.cs new file mode 100644 index 00000000..32b1415c --- /dev/null +++ b/src/NadekoBot/Common/BotConfigEditType.cs @@ -0,0 +1,20 @@ +namespace NadekoBot.Common +{ + public enum BotConfigEditType + { + CurrencyGenerationChance, + CurrencyGenerationCooldown, + CurrencyName, + CurrencyPluralName, + CurrencySign, + DmHelpString, + HelpString, + CurrencyDropAmount, + CurrencyDropAmountMax, + MinimumBetAmount, + TriviaCurrencyReward, + + //ErrorColor, //after i fix the nadekobot.cs static variables + //OkColor + } +} diff --git a/src/NadekoBot/Migrations/20170612094138_verbose-errors.cs b/src/NadekoBot/Migrations/20170612094138_verbose-errors.cs index 3caf4aca..291e4e40 100644 --- a/src/NadekoBot/Migrations/20170612094138_verbose-errors.cs +++ b/src/NadekoBot/Migrations/20170612094138_verbose-errors.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; namespace NadekoBot.Migrations { diff --git a/src/NadekoBot/Migrations/20170612234751_repeat time of day.cs b/src/NadekoBot/Migrations/20170612234751_repeat time of day.cs index 076d69d3..a5a7bfac 100644 --- a/src/NadekoBot/Migrations/20170612234751_repeat time of day.cs +++ b/src/NadekoBot/Migrations/20170612234751_repeat time of day.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Migrations; namespace NadekoBot.Migrations diff --git a/src/NadekoBot/Migrations/20170613231358_maxdropamount.cs b/src/NadekoBot/Migrations/20170613231358_maxdropamount.cs index ea9d58c8..31495e9b 100644 --- a/src/NadekoBot/Migrations/20170613231358_maxdropamount.cs +++ b/src/NadekoBot/Migrations/20170613231358_maxdropamount.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; namespace NadekoBot.Migrations { diff --git a/src/NadekoBot/Migrations/20170616154106_crstartswith.cs b/src/NadekoBot/Migrations/20170616154106_crstartswith.cs index 53aa582f..0aeca5bb 100644 --- a/src/NadekoBot/Migrations/20170616154106_crstartswith.cs +++ b/src/NadekoBot/Migrations/20170616154106_crstartswith.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; namespace NadekoBot.Migrations { diff --git a/src/NadekoBot/Migrations/20170714021615_stream-role.cs b/src/NadekoBot/Migrations/20170714021615_stream-role.cs index 22f6abec..7cbce423 100644 --- a/src/NadekoBot/Migrations/20170714021615_stream-role.cs +++ b/src/NadekoBot/Migrations/20170714021615_stream-role.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Migrations; namespace NadekoBot.Migrations diff --git a/src/NadekoBot/Migrations/20170719023924_streamrole-kw-bl-wl.cs b/src/NadekoBot/Migrations/20170719023924_streamrole-kw-bl-wl.cs index d2ed14f1..7d18d3b3 100644 --- a/src/NadekoBot/Migrations/20170719023924_streamrole-kw-bl-wl.cs +++ b/src/NadekoBot/Migrations/20170719023924_streamrole-kw-bl-wl.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Migrations; namespace NadekoBot.Migrations diff --git a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs index 6b57437a..df766d57 100644 --- a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs +++ b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs @@ -2,9 +2,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; using NadekoBot.Services.Database; -using NadekoBot.Services.Database.Models; namespace NadekoBot.Migrations { diff --git a/src/NadekoBot/Modules/Administration/LogCommands.cs b/src/NadekoBot/Modules/Administration/LogCommands.cs index 3ee5fc5a..daffd9f7 100644 --- a/src/NadekoBot/Modules/Administration/LogCommands.cs +++ b/src/NadekoBot/Modules/Administration/LogCommands.cs @@ -1,7 +1,6 @@ using Discord; using Discord.Commands; using NadekoBot.Extensions; -using NadekoBot.Modules.Permissions; using NadekoBot.Services; using NadekoBot.Services.Database.Models; using System; diff --git a/src/NadekoBot/Modules/Administration/SelfAssignedRolesCommands.cs b/src/NadekoBot/Modules/Administration/SelfAssignedRolesCommands.cs index 2d568519..271ef2c0 100644 --- a/src/NadekoBot/Modules/Administration/SelfAssignedRolesCommands.cs +++ b/src/NadekoBot/Modules/Administration/SelfAssignedRolesCommands.cs @@ -5,7 +5,6 @@ using NadekoBot.Extensions; using NadekoBot.Services; using NadekoBot.Services.Database.Models; using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/NadekoBot/Modules/Administration/SelfCommands.cs b/src/NadekoBot/Modules/Administration/SelfCommands.cs index 96f175d0..9edc1684 100644 --- a/src/NadekoBot/Modules/Administration/SelfCommands.cs +++ b/src/NadekoBot/Modules/Administration/SelfCommands.cs @@ -29,14 +29,16 @@ namespace NadekoBot.Modules.Administration private readonly DiscordSocketClient _client; private readonly IImagesService _images; private readonly MusicService _music; + private readonly IBotConfigProvider _bc; public SelfCommands(DbService db, DiscordSocketClient client, - MusicService music, IImagesService images) + MusicService music, IImagesService images, IBotConfigProvider bc) { _db = db; _client = client; _images = images; _music = music; + _bc = bc; } [NadekoCommand, Usage, Description, Aliases] @@ -179,9 +181,11 @@ namespace NadekoBot.Modules.Administration using (var uow = _db.UnitOfWork) { var config = uow.BotConfig.GetOrCreate(); - _service.ForwardDMs = config.ForwardMessages = !config.ForwardMessages; + config.ForwardMessages = !config.ForwardMessages; uow.Complete(); } + _bc.Reload(); + if (_service.ForwardDMs) await ReplyConfirmLocalized("fwdm_start").ConfigureAwait(false); else @@ -196,9 +200,11 @@ namespace NadekoBot.Modules.Administration { var config = uow.BotConfig.GetOrCreate(); lock (_locker) - _service.ForwardDMsToAllOwners = config.ForwardToAllOwners = !config.ForwardToAllOwners; + config.ForwardToAllOwners = !config.ForwardToAllOwners; uow.Complete(); } + _bc.Reload(); + if (_service.ForwardDMsToAllOwners) await ReplyConfirmLocalized("fwall_start").ConfigureAwait(false); else diff --git a/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs b/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs index 104f9174..57ec29a8 100644 --- a/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs +++ b/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/NadekoBot/Modules/Administration/Services/GameVoiceChannelService.cs b/src/NadekoBot/Modules/Administration/Services/GameVoiceChannelService.cs index 523b1dac..79b1f3ac 100644 --- a/src/NadekoBot/Modules/Administration/Services/GameVoiceChannelService.cs +++ b/src/NadekoBot/Modules/Administration/Services/GameVoiceChannelService.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/NadekoBot/Modules/Administration/Services/PruneService.cs b/src/NadekoBot/Modules/Administration/Services/PruneService.cs index fd13daa5..4f25e3c3 100644 --- a/src/NadekoBot/Modules/Administration/Services/PruneService.cs +++ b/src/NadekoBot/Modules/Administration/Services/PruneService.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/NadekoBot/Modules/Administration/Services/SelfService.cs b/src/NadekoBot/Modules/Administration/Services/SelfService.cs index dd0e6735..c5ad3ce9 100644 --- a/src/NadekoBot/Modules/Administration/Services/SelfService.cs +++ b/src/NadekoBot/Modules/Administration/Services/SelfService.cs @@ -8,7 +8,6 @@ using NadekoBot.Common; using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Extensions; using NadekoBot.Services; -using NadekoBot.Services.Database.Models; using NadekoBot.Services.Impl; using NLog; @@ -16,8 +15,9 @@ namespace NadekoBot.Modules.Administration.Services { public class SelfService : ILateExecutor, INService { - public volatile bool ForwardDMs; - public volatile bool ForwardDMsToAllOwners; + //todo bot config + public bool ForwardDMs => _bc.BotConfig.ForwardMessages; + public bool ForwardDMsToAllOwners => _bc.BotConfig.ForwardToAllOwners; private readonly NadekoBot _bot; private readonly CommandHandler _cmdHandler; @@ -28,9 +28,10 @@ namespace NadekoBot.Modules.Administration.Services private readonly DiscordSocketClient _client; private readonly IBotCredentials _creds; private ImmutableArray> ownerChannels = new ImmutableArray>(); + private readonly IBotConfigProvider _bc; public SelfService(DiscordSocketClient client, NadekoBot bot, CommandHandler cmdHandler, DbService db, - BotConfig bc, ILocalization localization, NadekoStrings strings, IBotCredentials creds) + IBotConfigProvider bc, ILocalization localization, NadekoStrings strings, IBotCredentials creds) { _bot = bot; _cmdHandler = cmdHandler; @@ -40,15 +41,13 @@ namespace NadekoBot.Modules.Administration.Services _strings = strings; _client = client; _creds = creds; - - ForwardDMs = bc.ForwardMessages; - ForwardDMsToAllOwners = bc.ForwardToAllOwners; + _bc = bc; var _ = Task.Run(async () => { await bot.Ready.Task.ConfigureAwait(false); - foreach (var cmd in bc.StartupCommands) + foreach (var cmd in bc.BotConfig.StartupCommands) { await cmdHandler.ExecuteExternal(cmd.GuildId, cmd.ChannelId, cmd.CommandText); await Task.Delay(400).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/CustomReactions/Extensions/Extensions.cs b/src/NadekoBot/Modules/CustomReactions/Extensions/Extensions.cs index 25bbfce3..41d58d26 100644 --- a/src/NadekoBot/Modules/CustomReactions/Extensions/Extensions.cs +++ b/src/NadekoBot/Modules/CustomReactions/Extensions/Extensions.cs @@ -4,7 +4,6 @@ using Discord; using Discord.WebSocket; using NadekoBot.Extensions; using NadekoBot.Modules.CustomReactions.Services; -using NadekoBot.Services; using NadekoBot.Services.Database.Models; using System; using System.Collections.Generic; diff --git a/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs b/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs index 1241e664..cb595124 100644 --- a/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs +++ b/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs @@ -30,11 +30,11 @@ namespace NadekoBot.Modules.CustomReactions.Services private readonly DiscordSocketClient _client; private readonly PermissionService _perms; private readonly CommandHandler _cmd; - private readonly BotConfig _bc; + private readonly IBotConfigProvider _bc; private readonly NadekoStrings _strings; public CustomReactionsService(PermissionService perms, DbService db, NadekoStrings strings, - DiscordSocketClient client, CommandHandler cmd, BotConfig bc, IUnitOfWork uow) + DiscordSocketClient client, CommandHandler cmd, IBotConfigProvider bc, IUnitOfWork uow) { _log = LogManager.GetCurrentClassLogger(); _db = db; @@ -69,7 +69,7 @@ namespace NadekoBot.Modules.CustomReactions.Services var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%"); var trigger = cr.TriggerWithContext(umsg, _client).Trim().ToLowerInvariant(); - return ((hasTarget && content.StartsWith(trigger + " ")) || (_bc.CustomReactionsStartWith && content.StartsWith(trigger + " ")) || content == trigger); + return ((hasTarget && content.StartsWith(trigger + " ")) || (_bc.BotConfig.CustomReactionsStartWith && content.StartsWith(trigger + " ")) || content == trigger); }).ToArray(); if (rs.Length != 0) @@ -90,7 +90,7 @@ namespace NadekoBot.Modules.CustomReactions.Services return false; var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%"); var trigger = cr.TriggerWithContext(umsg, _client).Trim().ToLowerInvariant(); - return ((hasTarget && content.StartsWith(trigger + " ")) || (_bc.CustomReactionsStartWith && content.StartsWith(trigger + " ")) || content == trigger); + return ((hasTarget && content.StartsWith(trigger + " ")) || (_bc.BotConfig.CustomReactionsStartWith && content.StartsWith(trigger + " ")) || content == trigger); }).ToArray(); if (grs.Length == 0) return null; diff --git a/src/NadekoBot/Modules/Gambling/AnimalRacingCommands.cs b/src/NadekoBot/Modules/Gambling/AnimalRacingCommands.cs index 18411490..f322a517 100644 --- a/src/NadekoBot/Modules/Gambling/AnimalRacingCommands.cs +++ b/src/NadekoBot/Modules/Gambling/AnimalRacingCommands.cs @@ -3,7 +3,6 @@ using Discord.Commands; using Discord.WebSocket; using NadekoBot.Extensions; using NadekoBot.Services; -using NadekoBot.Services.Database.Models; using NLog; using System; using System.Collections.Concurrent; @@ -22,14 +21,14 @@ namespace NadekoBot.Modules.Gambling [Group] public class AnimalRacingCommands : NadekoSubmodule { - private readonly BotConfig _bc; + private readonly IBotConfigProvider _bc; private readonly CurrencyService _cs; private readonly DiscordSocketClient _client; public static ConcurrentDictionary AnimalRaces { get; } = new ConcurrentDictionary(); - public AnimalRacingCommands(BotConfig bc, CurrencyService cs, DiscordSocketClient client) + public AnimalRacingCommands(IBotConfigProvider bc, CurrencyService cs, DiscordSocketClient client) { _bc = bc; _cs = cs; @@ -82,7 +81,7 @@ namespace NadekoBot.Modules.Gambling private readonly Logger _log; private readonly ITextChannel _raceChannel; - private readonly BotConfig _bc; + private readonly IBotConfigProvider _bc; private readonly CurrencyService _cs; private readonly DiscordSocketClient _client; private readonly ILocalization _localization; @@ -90,7 +89,7 @@ namespace NadekoBot.Modules.Gambling public bool Started { get; private set; } - public AnimalRace(ulong serverId, ITextChannel channel, string prefix, BotConfig bc, + public AnimalRace(ulong serverId, ITextChannel channel, string prefix, IBotConfigProvider bc, CurrencyService cs, DiscordSocketClient client, ILocalization localization, NadekoStrings strings) { @@ -110,7 +109,7 @@ namespace NadekoBot.Modules.Gambling return; } - animals = new ConcurrentQueue(_bc.RaceAnimals.Select(ra => ra.Icon).Shuffle()); + animals = new ConcurrentQueue(_bc.BotConfig.RaceAnimals.Select(ra => ra.Icon).Shuffle()); var cancelSource = new CancellationTokenSource(); @@ -238,7 +237,7 @@ namespace NadekoBot.Modules.Gambling .ConfigureAwait(false); await _raceChannel.SendConfirmAsync(GetText("animal_race"), Format.Bold(GetText("animal_race_won_money", winner.User.Mention, - winner.Animal, wonAmount + _bc.CurrencySign))) + winner.Animal, wonAmount + _bc.BotConfig.CurrencySign))) .ConfigureAwait(false); } else @@ -295,13 +294,13 @@ namespace NadekoBot.Modules.Gambling if (amount > 0) if (!await _cs.RemoveAsync(u, "BetRace", amount, false).ConfigureAwait(false)) { - await _raceChannel.SendErrorAsync(GetText("not_enough", _bc.CurrencySign)).ConfigureAwait(false); + await _raceChannel.SendErrorAsync(GetText("not_enough", _bc.BotConfig.CurrencySign)).ConfigureAwait(false); return; } _participants.Add(p); string confStr; if (amount > 0) - confStr = GetText("animal_race_join_bet", u.Mention, p.Animal, amount + _bc.CurrencySign); + confStr = GetText("animal_race_join_bet", u.Mention, p.Animal, amount + _bc.BotConfig.CurrencySign); else confStr = GetText("animal_race_join", u.Mention, p.Animal); await _raceChannel.SendConfirmAsync(GetText("animal_race"), Format.Bold(confStr)).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Gambling/Common/Cards.cs b/src/NadekoBot/Modules/Gambling/Common/Cards.cs index b51765d0..41c39834 100644 --- a/src/NadekoBot/Modules/Gambling/Common/Cards.cs +++ b/src/NadekoBot/Modules/Gambling/Common/Cards.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using NadekoBot.Common; using NadekoBot.Extensions; -using NadekoBot.Services; namespace NadekoBot.Modules.Gambling.Common { diff --git a/src/NadekoBot/Modules/Gambling/CurrencyEventsCommands.cs b/src/NadekoBot/Modules/Gambling/CurrencyEventsCommands.cs index 7a4ecf42..a250a80d 100644 --- a/src/NadekoBot/Modules/Gambling/CurrencyEventsCommands.cs +++ b/src/NadekoBot/Modules/Gambling/CurrencyEventsCommands.cs @@ -3,7 +3,6 @@ using Discord.Commands; using NadekoBot.Extensions; using NadekoBot.Services; using System; -using System.Collections.Concurrent; using System.Linq; using System.Threading.Tasks; using Discord.WebSocket; @@ -12,7 +11,6 @@ using NadekoBot.Common; using NadekoBot.Common.Attributes; using NadekoBot.Common.Collections; using NLog; -using NadekoBot.Services.Database.Models; namespace NadekoBot.Modules.Gambling { @@ -37,10 +35,10 @@ namespace NadekoBot.Modules.Gambling private string _secretCode = string.Empty; private readonly DiscordSocketClient _client; - private readonly BotConfig _bc; + private readonly IBotConfigProvider _bc; private readonly CurrencyService _cs; - public CurrencyEventsCommands(DiscordSocketClient client, BotConfig bc, CurrencyService cs) + public CurrencyEventsCommands(DiscordSocketClient client, IBotConfigProvider bc, CurrencyService cs) { _client = client; _bc = bc; @@ -80,12 +78,12 @@ namespace NadekoBot.Modules.Gambling _secretCode += _sneakyGameStatusChars[rng.Next(0, _sneakyGameStatusChars.Length)]; } - await _client.SetGameAsync($"type {_secretCode} for " + _bc.CurrencyPluralName) + await _client.SetGameAsync($"type {_secretCode} for " + _bc.BotConfig.CurrencyPluralName) .ConfigureAwait(false); try { var title = GetText("sneakygamestatus_title"); - var desc = GetText("sneakygamestatus_desc", Format.Bold(100.ToString()) + _bc.CurrencySign, Format.Bold(num.ToString())); + var desc = GetText("sneakygamestatus_desc", Format.Bold(100.ToString()) + _bc.BotConfig.CurrencySign, Format.Bold(num.ToString())); await context.Channel.SendConfirmAsync(title, desc).ConfigureAwait(false); } catch @@ -133,7 +131,7 @@ namespace NadekoBot.Modules.Gambling amount = 100; var title = GetText("flowerreaction_title"); - var desc = GetText("flowerreaction_desc", "🌸", Format.Bold(amount.ToString()) + _bc.CurrencySign); + var desc = GetText("flowerreaction_desc", "🌸", Format.Bold(amount.ToString()) + _bc.BotConfig.CurrencySign); var footer = GetText("flowerreaction_footer", 24); var msg = await context.Channel.SendConfirmAsync(title, desc, footer: footer) diff --git a/src/NadekoBot/Modules/Gambling/FlipCoinCommands.cs b/src/NadekoBot/Modules/Gambling/FlipCoinCommands.cs index 21ff1411..96e69acf 100644 --- a/src/NadekoBot/Modules/Gambling/FlipCoinCommands.cs +++ b/src/NadekoBot/Modules/Gambling/FlipCoinCommands.cs @@ -2,7 +2,6 @@ using Discord; using Discord.Commands; using NadekoBot.Extensions; using NadekoBot.Services; -using NadekoBot.Services.Database.Models; using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -19,12 +18,12 @@ namespace NadekoBot.Modules.Gambling public class FlipCoinCommands : NadekoSubmodule { private readonly IImagesService _images; - private readonly BotConfig _bc; + private readonly IBotConfigProvider _bc; private readonly CurrencyService _cs; private readonly NadekoRandom rng = new NadekoRandom(); - public FlipCoinCommands(IImagesService images, CurrencyService cs, BotConfig bc) + public FlipCoinCommands(IImagesService images, CurrencyService cs, IBotConfigProvider bc) { _images = images; _bc = bc; @@ -89,15 +88,15 @@ namespace NadekoBot.Modules.Gambling [NadekoCommand, Usage, Description, Aliases] public async Task Betflip(int amount, BetFlipGuess guess) { - if (amount < _bc.MinimumBetAmount) + if (amount < _bc.BotConfig.MinimumBetAmount) { - await ReplyErrorLocalized("min_bet_limit", _bc.MinimumBetAmount + _bc.CurrencySign).ConfigureAwait(false); + await ReplyErrorLocalized("min_bet_limit", _bc.BotConfig.MinimumBetAmount + _bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } var removed = await _cs.RemoveAsync(Context.User, "Betflip Gamble", amount, false).ConfigureAwait(false); if (!removed) { - await ReplyErrorLocalized("not_enough", _bc.CurrencyPluralName).ConfigureAwait(false); + await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencyPluralName).ConfigureAwait(false); return; } BetFlipGuess result; @@ -116,8 +115,8 @@ namespace NadekoBot.Modules.Gambling string str; if (guess == result) { - var toWin = (int)Math.Round(amount * _bc.BetflipMultiplier); - str = Context.User.Mention + " " + GetText("flip_guess", toWin + _bc.CurrencySign); + var toWin = (int)Math.Round(amount * _bc.BotConfig.BetflipMultiplier); + str = Context.User.Mention + " " + GetText("flip_guess", toWin + _bc.BotConfig.CurrencySign); await _cs.AddAsync(Context.User, "Betflip Gamble", toWin, false).ConfigureAwait(false); } else diff --git a/src/NadekoBot/Modules/Gambling/FlowerShopCommands.cs b/src/NadekoBot/Modules/Gambling/FlowerShopCommands.cs index 27620ce6..9c285906 100644 --- a/src/NadekoBot/Modules/Gambling/FlowerShopCommands.cs +++ b/src/NadekoBot/Modules/Gambling/FlowerShopCommands.cs @@ -20,7 +20,7 @@ namespace NadekoBot.Modules.Gambling [Group] public class FlowerShopCommands : NadekoSubmodule { - private readonly BotConfig _bc; + private readonly IBotConfigProvider _bc; private readonly DbService _db; private readonly CurrencyService _cs; private readonly DiscordSocketClient _client; @@ -35,7 +35,7 @@ namespace NadekoBot.Modules.Gambling List } - public FlowerShopCommands(BotConfig bc, DbService db, CurrencyService cs, DiscordSocketClient client) + public FlowerShopCommands(IBotConfigProvider bc, DbService db, CurrencyService cs, DiscordSocketClient client) { _db = db; _bc = bc; @@ -65,12 +65,12 @@ namespace NadekoBot.Modules.Gambling return new EmbedBuilder().WithErrorColor() .WithDescription(GetText("shop_none")); var embed = new EmbedBuilder().WithOkColor() - .WithTitle(GetText("shop", _bc.CurrencySign)); + .WithTitle(GetText("shop", _bc.BotConfig.CurrencySign)); for (int i = 0; i < theseEntries.Length; i++) { var entry = entries[i]; - embed.AddField(efb => efb.WithName($"#{curPage * 9 + i + 1} - {entry.Price}{_bc.CurrencySign}").WithValue(EntryToString(entry)).WithIsInline(true)); + embed.AddField(efb => efb.WithName($"#{curPage * 9 + i + 1} - {entry.Price}{_bc.BotConfig.CurrencySign}").WithValue(EntryToString(entry)).WithIsInline(true)); } return embed; }, entries.Count / 9, true); @@ -130,7 +130,7 @@ namespace NadekoBot.Modules.Gambling } else { - await ReplyErrorLocalized("not_enough", _bc.CurrencySign).ConfigureAwait(false); + await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } } @@ -186,7 +186,7 @@ namespace NadekoBot.Modules.Gambling } else { - await ReplyErrorLocalized("not_enough", _bc.CurrencySign).ConfigureAwait(false); + await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } } diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index 46ecc8c5..07de5bc8 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -13,15 +13,15 @@ namespace NadekoBot.Modules.Gambling { public partial class Gambling : NadekoTopLevelModule { - private readonly BotConfig _bc; + private readonly IBotConfigProvider _bc; private readonly DbService _db; private readonly CurrencyService _currency; - private string CurrencyName => _bc.CurrencyName; - private string CurrencyPluralName => _bc.CurrencyPluralName; - private string CurrencySign => _bc.CurrencySign; + private string CurrencyName => _bc.BotConfig.CurrencyName; + private string CurrencyPluralName => _bc.BotConfig.CurrencyPluralName; + private string CurrencySign => _bc.BotConfig.CurrencySign; - public Gambling(BotConfig bc, DbService db, CurrencyService currency) + public Gambling(IBotConfigProvider bc, DbService db, CurrencyService currency) { _bc = bc; _db = db; @@ -230,21 +230,21 @@ namespace NadekoBot.Modules.Gambling { if (rnd < 91) { - str += GetText("br_win", (amount * _bc.Betroll67Multiplier) + CurrencySign, 66); + str += GetText("br_win", (amount * _bc.BotConfig.Betroll67Multiplier) + CurrencySign, 66); await _currency.AddAsync(Context.User, "Betroll Gamble", - (int) (amount * _bc.Betroll67Multiplier), false).ConfigureAwait(false); + (int) (amount * _bc.BotConfig.Betroll67Multiplier), false).ConfigureAwait(false); } else if (rnd < 100) { - str += GetText("br_win", (amount * _bc.Betroll91Multiplier) + CurrencySign, 90); + str += GetText("br_win", (amount * _bc.BotConfig.Betroll91Multiplier) + CurrencySign, 90); await _currency.AddAsync(Context.User, "Betroll Gamble", - (int) (amount * _bc.Betroll91Multiplier), false).ConfigureAwait(false); + (int) (amount * _bc.BotConfig.Betroll91Multiplier), false).ConfigureAwait(false); } else { - str += GetText("br_win", (amount * _bc.Betroll100Multiplier) + CurrencySign, 100) + " 👑"; + str += GetText("br_win", (amount * _bc.BotConfig.Betroll100Multiplier) + CurrencySign, 100) + " 👑"; await _currency.AddAsync(Context.User, "Betroll Gamble", - (int) (amount * _bc.Betroll100Multiplier), false).ConfigureAwait(false); + (int) (amount * _bc.BotConfig.Betroll100Multiplier), false).ConfigureAwait(false); } } await Context.Channel.SendConfirmAsync(str).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Gambling/SlotCommands.cs b/src/NadekoBot/Modules/Gambling/SlotCommands.cs index c51dc2c8..43cfb8d4 100644 --- a/src/NadekoBot/Modules/Gambling/SlotCommands.cs +++ b/src/NadekoBot/Modules/Gambling/SlotCommands.cs @@ -3,7 +3,6 @@ using Discord.Commands; using ImageSharp; using NadekoBot.Extensions; using NadekoBot.Services; -using NadekoBot.Services.Database.Models; using System; using System.Collections.Generic; using System.Linq; @@ -25,7 +24,7 @@ namespace NadekoBot.Modules.Gambling private static int _totalPaidOut; private static readonly HashSet _runningUsers = new HashSet(); - private readonly BotConfig _bc; + private readonly IBotConfigProvider _bc; private const int _alphaCutOut = byte.MaxValue / 3; @@ -36,7 +35,7 @@ namespace NadekoBot.Modules.Gambling private readonly IImagesService _images; private readonly CurrencyService _cs; - public SlotCommands(IImagesService images, BotConfig bc, CurrencyService cs) + public SlotCommands(IImagesService images, IBotConfigProvider bc, CurrencyService cs) { _images = images; _bc = bc; @@ -148,20 +147,20 @@ namespace NadekoBot.Modules.Gambling { if (amount < 1) { - await ReplyErrorLocalized("min_bet_limit", 1 + _bc.CurrencySign).ConfigureAwait(false); + await ReplyErrorLocalized("min_bet_limit", 1 + _bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } const int maxAmount = 9999; if (amount > maxAmount) { - GetText("slot_maxbet", maxAmount + _bc.CurrencySign); - await ReplyErrorLocalized("max_bet_limit", maxAmount + _bc.CurrencySign).ConfigureAwait(false); + GetText("slot_maxbet", maxAmount + _bc.BotConfig.CurrencySign); + await ReplyErrorLocalized("max_bet_limit", maxAmount + _bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } if (!await _cs.RemoveAsync(Context.User, "Slot Machine", amount, false)) { - await ReplyErrorLocalized("not_enough", _bc.CurrencySign).ConfigureAwait(false); + await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } Interlocked.Add(ref _totalBet, amount); @@ -202,7 +201,7 @@ namespace NadekoBot.Modules.Gambling var digit = printAmount % 10; using (var fs = _images.SlotNumbers[digit].ToStream()) using (var img = ImageSharp.Image.Load(fs)) - { + { bgImage.DrawImage(img, 100, default(Size), new Point(395 - n * 16, 462)); } n++; @@ -214,16 +213,16 @@ namespace NadekoBot.Modules.Gambling await _cs.AddAsync(Context.User, $"Slot Machine x{result.Multiplier}", amount * result.Multiplier, false); Interlocked.Add(ref _totalPaidOut, amount * result.Multiplier); if (result.Multiplier == 1) - msg = GetText("slot_single", _bc.CurrencySign, 1); + msg = GetText("slot_single", _bc.BotConfig.CurrencySign, 1); else if (result.Multiplier == 4) - msg = GetText("slot_two", _bc.CurrencySign, 4); + msg = GetText("slot_two", _bc.BotConfig.CurrencySign, 4); else if (result.Multiplier == 10) msg = GetText("slot_three", 10); else if (result.Multiplier == 30) msg = GetText("slot_jackpot", 30); } - await Context.Channel.SendFileAsync(bgImage.ToStream(), "result.png", Context.User.Mention + " " + msg + $"\n`{GetText("slot_bet")}:`{amount} `{GetText("slot_won")}:` {amount * result.Multiplier}{_bc.CurrencySign}").ConfigureAwait(false); + await Context.Channel.SendFileAsync(bgImage.ToStream(), "result.png", Context.User.Mention + " " + msg + $"\n`{GetText("slot_bet")}:`{amount} `{GetText("slot_won")}:` {amount * result.Multiplier}{_bc.BotConfig.CurrencySign}").ConfigureAwait(false); } } finally diff --git a/src/NadekoBot/Modules/Gambling/WaifuClaimCommands.cs b/src/NadekoBot/Modules/Gambling/WaifuClaimCommands.cs index 43113928..baa1781b 100644 --- a/src/NadekoBot/Modules/Gambling/WaifuClaimCommands.cs +++ b/src/NadekoBot/Modules/Gambling/WaifuClaimCommands.cs @@ -58,7 +58,7 @@ namespace NadekoBot.Modules.Gambling InsufficientAmount } - public WaifuClaimCommands(BotConfig bc, CurrencyService cs, DbService db) + public WaifuClaimCommands(IBotConfigProvider bc, CurrencyService cs, DbService db) { _bc = bc; _cs = cs; @@ -71,7 +71,7 @@ namespace NadekoBot.Modules.Gambling { if (amount < 50) { - await ReplyErrorLocalized("waifu_isnt_cheap", 50 + _bc.CurrencySign).ConfigureAwait(false); + await ReplyErrorLocalized("waifu_isnt_cheap", 50 + _bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } @@ -173,14 +173,14 @@ namespace NadekoBot.Modules.Gambling } if (result == WaifuClaimResult.NotEnoughFunds) { - await ReplyErrorLocalized("not_enough", _bc.CurrencySign).ConfigureAwait(false); + await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } var msg = GetText("waifu_claimed", Format.Bold(target.ToString()), - amount + _bc.CurrencySign); + amount + _bc.BotConfig.CurrencySign); if (w.Affinity?.UserId == Context.User.Id) - msg += "\n" + GetText("waifu_fulfilled", target, w.Price + _bc.CurrencySign); + msg += "\n" + GetText("waifu_fulfilled", target, w.Price + _bc.BotConfig.CurrencySign); else msg = " " + msg; await Context.Channel.SendConfirmAsync(Context.User.Mention + msg).ConfigureAwait(false); @@ -258,11 +258,11 @@ namespace NadekoBot.Modules.Gambling if (result == DivorceResult.SucessWithPenalty) { - await ReplyConfirmLocalized("waifu_divorced_like", Format.Bold(w.Waifu.ToString()), amount + _bc.CurrencySign).ConfigureAwait(false); + await ReplyConfirmLocalized("waifu_divorced_like", Format.Bold(w.Waifu.ToString()), amount + _bc.BotConfig.CurrencySign).ConfigureAwait(false); } else if (result == DivorceResult.Success) { - await ReplyConfirmLocalized("waifu_divorced_notlike", amount + _bc.CurrencySign).ConfigureAwait(false); + await ReplyConfirmLocalized("waifu_divorced_notlike", amount + _bc.BotConfig.CurrencySign).ConfigureAwait(false); } else if (result == DivorceResult.NotYourWife) { @@ -278,7 +278,7 @@ namespace NadekoBot.Modules.Gambling } private static readonly TimeSpan _affinityLimit = TimeSpan.FromMinutes(30); - private readonly BotConfig _bc; + private readonly IBotConfigProvider _bc; private readonly CurrencyService _cs; private readonly DbService _db; @@ -406,7 +406,7 @@ namespace NadekoBot.Modules.Gambling var w = waifus[i]; var j = i; - embed.AddField(efb => efb.WithName("#" + ((page * 9) + j + 1) + " - " + w.Price + _bc.CurrencySign).WithValue(w.ToString()).WithIsInline(false)); + embed.AddField(efb => efb.WithName("#" + ((page * 9) + j + 1) + " - " + w.Price + _bc.BotConfig.CurrencySign).WithValue(w.ToString()).WithIsInline(false)); } await Context.Channel.EmbedAsync(embed).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Games/AcropobiaCommands.cs b/src/NadekoBot/Modules/Games/AcropobiaCommands.cs index f905a4eb..e66578fa 100644 --- a/src/NadekoBot/Modules/Games/AcropobiaCommands.cs +++ b/src/NadekoBot/Modules/Games/AcropobiaCommands.cs @@ -2,7 +2,6 @@ using Discord.Commands; using Discord.WebSocket; using NadekoBot.Extensions; -using NadekoBot.Services; using NLog; using System; using System.Collections.Concurrent; diff --git a/src/NadekoBot/Modules/Games/Common/ChatterBotSession.cs b/src/NadekoBot/Modules/Games/Common/ChatterBotSession.cs index 4c3ad823..256d3d05 100644 --- a/src/NadekoBot/Modules/Games/Common/ChatterBotSession.cs +++ b/src/NadekoBot/Modules/Games/Common/ChatterBotSession.cs @@ -2,7 +2,6 @@ using System.Threading.Tasks; using NadekoBot.Common; using NadekoBot.Extensions; -using NadekoBot.Services; using Newtonsoft.Json; namespace NadekoBot.Modules.Games.Common diff --git a/src/NadekoBot/Modules/Games/Common/Hangman/HangmanGame.cs b/src/NadekoBot/Modules/Games/Common/Hangman/HangmanGame.cs index 540821b7..f0f5c820 100644 --- a/src/NadekoBot/Modules/Games/Common/Hangman/HangmanGame.cs +++ b/src/NadekoBot/Modules/Games/Common/Hangman/HangmanGame.cs @@ -7,7 +7,6 @@ using Discord; using Discord.WebSocket; using NadekoBot.Common; using NadekoBot.Extensions; -using NadekoBot.Services; using Newtonsoft.Json; using NLog; diff --git a/src/NadekoBot/Modules/Games/Common/Poll.cs b/src/NadekoBot/Modules/Games/Common/Poll.cs index c14a490d..816e2101 100644 --- a/src/NadekoBot/Modules/Games/Common/Poll.cs +++ b/src/NadekoBot/Modules/Games/Common/Poll.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using Discord; using Discord.WebSocket; using NadekoBot.Extensions; -using NadekoBot.Services; using NadekoBot.Services.Impl; namespace NadekoBot.Modules.Games.Common diff --git a/src/NadekoBot/Modules/Games/Common/Trivia/TriviaGame.cs b/src/NadekoBot/Modules/Games/Common/Trivia/TriviaGame.cs index 90effc81..77714d58 100644 --- a/src/NadekoBot/Modules/Games/Common/Trivia/TriviaGame.cs +++ b/src/NadekoBot/Modules/Games/Common/Trivia/TriviaGame.cs @@ -10,7 +10,6 @@ using Discord.Net; using Discord.WebSocket; using NadekoBot.Extensions; using NadekoBot.Services; -using NadekoBot.Services.Database.Models; using NadekoBot.Services.Impl; using NLog; @@ -22,7 +21,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia private readonly Logger _log; private readonly NadekoStrings _strings; private readonly DiscordSocketClient _client; - private readonly BotConfig _bc; + private readonly IBotConfigProvider _bc; private readonly CurrencyService _cs; public IGuild Guild { get; } @@ -44,7 +43,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia public int WinRequirement { get; } - public TriviaGame(NadekoStrings strings, DiscordSocketClient client, BotConfig bc, + public TriviaGame(NadekoStrings strings, DiscordSocketClient client, IBotConfigProvider bc, CurrencyService cs, IGuild guild, ITextChannel channel, bool showHints, int winReq, bool isPokemon) { @@ -232,7 +231,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia { // ignored } - var reward = _bc.TriviaCurrencyReward; + var reward = _bc.BotConfig.TriviaCurrencyReward; if (reward > 0) await _cs.AddAsync(guildUser, "Won trivia", reward, true).ConfigureAwait(false); return; diff --git a/src/NadekoBot/Modules/Games/Common/Trivia/TriviaQuestionPool.cs b/src/NadekoBot/Modules/Games/Common/Trivia/TriviaQuestionPool.cs index 22d38fe9..2307c209 100644 --- a/src/NadekoBot/Modules/Games/Common/Trivia/TriviaQuestionPool.cs +++ b/src/NadekoBot/Modules/Games/Common/Trivia/TriviaQuestionPool.cs @@ -5,7 +5,6 @@ using System.IO; using System.Linq; using NadekoBot.Common; using NadekoBot.Extensions; -using NadekoBot.Services; using Newtonsoft.Json; namespace NadekoBot.Modules.Games.Common.Trivia diff --git a/src/NadekoBot/Modules/Games/Common/TypingGame.cs b/src/NadekoBot/Modules/Games/Common/TypingGame.cs index c07484bc..f2d2980a 100644 --- a/src/NadekoBot/Modules/Games/Common/TypingGame.cs +++ b/src/NadekoBot/Modules/Games/Common/TypingGame.cs @@ -8,7 +8,6 @@ using Discord.WebSocket; using NadekoBot.Common; using NadekoBot.Extensions; using NadekoBot.Modules.Games.Services; -using NadekoBot.Services; using NLog; namespace NadekoBot.Modules.Games.Common diff --git a/src/NadekoBot/Modules/Games/PlantAndPickCommands.cs b/src/NadekoBot/Modules/Games/PlantAndPickCommands.cs index 19b792fc..1ebb7357 100644 --- a/src/NadekoBot/Modules/Games/PlantAndPickCommands.cs +++ b/src/NadekoBot/Modules/Games/PlantAndPickCommands.cs @@ -25,11 +25,11 @@ namespace NadekoBot.Modules.Games public class PlantPickCommands : NadekoSubmodule { private readonly CurrencyService _cs; - private readonly BotConfig _bc; + private readonly IBotConfigProvider _bc; private readonly GamesService _games; private readonly DbService _db; - public PlantPickCommands(BotConfig bc, CurrencyService cs, GamesService games, + public PlantPickCommands(IBotConfigProvider bc, CurrencyService cs, GamesService games, DbService db) { _bc = bc; @@ -54,8 +54,8 @@ namespace NadekoBot.Modules.Games await Task.WhenAll(msgs.Where(m => m != null).Select(toDelete => toDelete.DeleteAsync())).ConfigureAwait(false); - await _cs.AddAsync((IGuildUser)Context.User, $"Picked {_bc.CurrencyPluralName}", msgs.Count, false).ConfigureAwait(false); - var msg = await ReplyConfirmLocalized("picked", msgs.Count + _bc.CurrencySign) + await _cs.AddAsync((IGuildUser)Context.User, $"Picked {_bc.BotConfig.CurrencyPluralName}", msgs.Count, false).ConfigureAwait(false); + var msg = await ReplyConfirmLocalized("picked", msgs.Count + _bc.BotConfig.CurrencySign) .ConfigureAwait(false); msg.DeleteAfter(10); } @@ -67,10 +67,10 @@ namespace NadekoBot.Modules.Games if (amount < 1) return; - var removed = await _cs.RemoveAsync((IGuildUser)Context.User, $"Planted a {_bc.CurrencyName}", amount, false).ConfigureAwait(false); + var removed = await _cs.RemoveAsync((IGuildUser)Context.User, $"Planted a {_bc.BotConfig.CurrencyName}", amount, false).ConfigureAwait(false); if (!removed) { - await ReplyErrorLocalized("not_enough", _bc.CurrencySign).ConfigureAwait(false); + await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } @@ -79,7 +79,7 @@ namespace NadekoBot.Modules.Games //todo 81 upload all currency images to transfer.sh and use that one as cdn var msgToSend = GetText("planted", Format.Bold(Context.User.ToString()), - amount + _bc.CurrencySign, + amount + _bc.BotConfig.CurrencySign, Prefix); if (amount > 1) diff --git a/src/NadekoBot/Modules/Games/Services/GamesService.cs b/src/NadekoBot/Modules/Games/Services/GamesService.cs index 6381156b..f09c606b 100644 --- a/src/NadekoBot/Modules/Games/Services/GamesService.cs +++ b/src/NadekoBot/Modules/Games/Services/GamesService.cs @@ -22,7 +22,7 @@ namespace NadekoBot.Modules.Games.Services { public class GamesService : INService { - private readonly BotConfig _bc; + private readonly IBotConfigProvider _bc; public readonly ConcurrentDictionary GirlRatings = new ConcurrentDictionary(); public readonly ImmutableArray EightBallResponses; @@ -38,7 +38,7 @@ namespace NadekoBot.Modules.Games.Services public List TypingArticles { get; } = new List(); - public GamesService(DiscordSocketClient client, BotConfig bc, IEnumerable gcs, + public GamesService(DiscordSocketClient client, IBotConfigProvider bc, IEnumerable gcs, NadekoStrings strings, IImagesService images, CommandHandler cmdHandler) { _bc = bc; @@ -49,7 +49,7 @@ namespace NadekoBot.Modules.Games.Services _log = LogManager.GetCurrentClassLogger(); //8ball - EightBallResponses = _bc.EightBallResponses.Select(ebr => ebr.Text).ToImmutableArray(); + EightBallResponses = _bc.BotConfig.EightBallResponses.Select(ebr => ebr.Text).ToImmutableArray(); //girl ratings _t = new Timer((_) => @@ -122,14 +122,14 @@ namespace NadekoBot.Modules.Games.Services var lastGeneration = LastGenerations.GetOrAdd(channel.Id, DateTime.MinValue); var rng = new NadekoRandom(); - if (DateTime.UtcNow - TimeSpan.FromSeconds(_bc.CurrencyGenerationCooldown) < lastGeneration) //recently generated in this channel, don't generate again + if (DateTime.UtcNow - TimeSpan.FromSeconds(_bc.BotConfig.CurrencyGenerationCooldown) < lastGeneration) //recently generated in this channel, don't generate again return; - var num = rng.Next(1, 101) + _bc.CurrencyGenerationChance * 100; + var num = rng.Next(1, 101) + _bc.BotConfig.CurrencyGenerationChance * 100; if (num > 100 && LastGenerations.TryUpdate(channel.Id, DateTime.UtcNow, lastGeneration)) { - var dropAmount = _bc.CurrencyDropAmount; - var dropAmountMax = _bc.CurrencyDropAmountMax; + var dropAmount = _bc.BotConfig.CurrencyDropAmount; + var dropAmountMax = _bc.BotConfig.CurrencyDropAmountMax; if (dropAmountMax != null && dropAmountMax > dropAmount) dropAmount = new NadekoRandom().Next(dropAmount, dropAmountMax.Value + 1); @@ -139,9 +139,9 @@ namespace NadekoBot.Modules.Games.Services var msgs = new IUserMessage[dropAmount]; var prefix = _cmdHandler.GetPrefix(channel.Guild.Id); var toSend = dropAmount == 1 - ? GetText(channel, "curgen_sn", _bc.CurrencySign) + ? GetText(channel, "curgen_sn", _bc.BotConfig.CurrencySign) + " " + GetText(channel, "pick_sn", prefix) - : GetText(channel, "curgen_pl", dropAmount, _bc.CurrencySign) + : GetText(channel, "curgen_pl", dropAmount, _bc.BotConfig.CurrencySign) + " " + GetText(channel, "pick_pl", prefix); var file = GetRandomCurrencyImage(); using (var fileStream = file.Data.ToStream()) diff --git a/src/NadekoBot/Modules/Games/TicTacToeCommands.cs b/src/NadekoBot/Modules/Games/TicTacToeCommands.cs index 3f2237f7..539d9cdd 100644 --- a/src/NadekoBot/Modules/Games/TicTacToeCommands.cs +++ b/src/NadekoBot/Modules/Games/TicTacToeCommands.cs @@ -2,7 +2,6 @@ using Discord.Commands; using Discord.WebSocket; using NadekoBot.Extensions; -using NadekoBot.Services; using System; using System.Collections.Generic; using System.Text; diff --git a/src/NadekoBot/Modules/Games/TriviaCommands.cs b/src/NadekoBot/Modules/Games/TriviaCommands.cs index 86560835..3360c87f 100644 --- a/src/NadekoBot/Modules/Games/TriviaCommands.cs +++ b/src/NadekoBot/Modules/Games/TriviaCommands.cs @@ -3,13 +3,11 @@ using Discord.Commands; using Discord.WebSocket; using NadekoBot.Extensions; using NadekoBot.Services; -using NadekoBot.Services.Database.Models; using System.Collections.Concurrent; using System.Threading.Tasks; using NadekoBot.Common.Attributes; using NadekoBot.Modules.Games.Common.Trivia; - namespace NadekoBot.Modules.Games { public partial class Games @@ -19,11 +17,11 @@ namespace NadekoBot.Modules.Games { private readonly CurrencyService _cs; private readonly DiscordSocketClient _client; - private readonly BotConfig _bc; + private readonly IBotConfigProvider _bc; public static ConcurrentDictionary RunningTrivias { get; } = new ConcurrentDictionary(); - public TriviaCommands(DiscordSocketClient client, BotConfig bc, CurrencyService cs) + public TriviaCommands(DiscordSocketClient client, IBotConfigProvider bc, CurrencyService cs) { _cs = cs; _client = client; diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index a1d6cb0f..0f1376e0 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -9,7 +9,6 @@ using System.IO; using System.Text; using System.Collections.Generic; using NadekoBot.Common.Attributes; -using NadekoBot.Services.Database.Models; using NadekoBot.Modules.Help.Services; using NadekoBot.Modules.Permissions.Services; @@ -20,14 +19,14 @@ namespace NadekoBot.Modules.Help public const string PatreonUrl = "https://patreon.com/nadekobot"; public const string PaypalUrl = "https://paypal.me/Kwoth"; private readonly IBotCredentials _creds; - private readonly BotConfig _config; + private readonly IBotConfigProvider _config; private readonly CommandService _cmds; private readonly GlobalPermissionService _perms; - public string HelpString => String.Format(_config.HelpString, _creds.ClientId, Prefix); - public string DMHelpString => _config.DMHelpString; + public string HelpString => String.Format(_config.BotConfig.HelpString, _creds.ClientId, Prefix); + public string DMHelpString => _config.BotConfig.DMHelpString; - public Help(IBotCredentials creds, GlobalPermissionService perms, BotConfig config, CommandService cmds) + public Help(IBotCredentials creds, GlobalPermissionService perms, IBotConfigProvider config, CommandService cmds) { _creds = creds; _config = config; diff --git a/src/NadekoBot/Modules/Help/Services/HelpService.cs b/src/NadekoBot/Modules/Help/Services/HelpService.cs index 2e5cd937..88220154 100644 --- a/src/NadekoBot/Modules/Help/Services/HelpService.cs +++ b/src/NadekoBot/Modules/Help/Services/HelpService.cs @@ -1,5 +1,4 @@ -using NadekoBot.Services.Database.Models; -using System.Threading.Tasks; +using System.Threading.Tasks; using Discord; using Discord.WebSocket; using System; @@ -15,11 +14,11 @@ namespace NadekoBot.Modules.Help.Services { public class HelpService : ILateExecutor, INService { - private readonly BotConfig _bc; + private readonly IBotConfigProvider _bc; private readonly CommandHandler _ch; private readonly NadekoStrings _strings; - public HelpService(BotConfig bc, CommandHandler ch, NadekoStrings strings) + public HelpService(IBotConfigProvider bc, CommandHandler ch, NadekoStrings strings) { _bc = bc; _ch = ch; @@ -31,7 +30,7 @@ namespace NadekoBot.Modules.Help.Services try { if(guild == null) - await msg.Channel.SendMessageAsync(_bc.DMHelpString).ConfigureAwait(false); + await msg.Channel.SendMessageAsync(_bc.BotConfig.DMHelpString).ConfigureAwait(false); } catch (Exception) { diff --git a/src/NadekoBot/Modules/Music/Common/Exceptions/NotInVoiceChannelException.cs b/src/NadekoBot/Modules/Music/Common/Exceptions/NotInVoiceChannelException.cs index b4fbe8a4..7e2a7706 100644 --- a/src/NadekoBot/Modules/Music/Common/Exceptions/NotInVoiceChannelException.cs +++ b/src/NadekoBot/Modules/Music/Common/Exceptions/NotInVoiceChannelException.cs @@ -2,13 +2,8 @@ namespace NadekoBot.Modules.Music.Common.Exceptions { - // todo use this public class NotInVoiceChannelException : Exception { - public NotInVoiceChannelException(string message) : base(message) - { - } - public NotInVoiceChannelException() : base("You're not in the voice channel on this server.") { } } } diff --git a/src/NadekoBot/Modules/Music/Common/MusicPlayer.cs b/src/NadekoBot/Modules/Music/Common/MusicPlayer.cs index 49327512..00e38c98 100644 --- a/src/NadekoBot/Modules/Music/Common/MusicPlayer.cs +++ b/src/NadekoBot/Modules/Music/Common/MusicPlayer.cs @@ -5,7 +5,6 @@ using System.Threading; using System.Threading.Tasks; using NLog; using System.Linq; -using System.Collections.Concurrent; using NadekoBot.Extensions; using System.Diagnostics; using NadekoBot.Common.Collections; diff --git a/src/NadekoBot/Modules/Music/Common/MusicQueue.cs b/src/NadekoBot/Modules/Music/Common/MusicQueue.cs index bcdc59f7..4927b21e 100644 --- a/src/NadekoBot/Modules/Music/Common/MusicQueue.cs +++ b/src/NadekoBot/Modules/Music/Common/MusicQueue.cs @@ -1,10 +1,8 @@ using NadekoBot.Extensions; using NadekoBot.Modules.Music.Common.Exceptions; -using NadekoBot.Services; using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading.Tasks; using NadekoBot.Common; diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 6b337f41..6b5499f3 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -8,7 +8,6 @@ using System.Linq; using NadekoBot.Extensions; using System.Collections.Generic; using NadekoBot.Services.Database.Models; -using System.Collections.Concurrent; using System.IO; using System.Net.Http; using NadekoBot.Common; diff --git a/src/NadekoBot/Modules/Music/Services/MusicService.cs b/src/NadekoBot/Modules/Music/Services/MusicService.cs index c585abb1..6b7fffc5 100644 --- a/src/NadekoBot/Modules/Music/Services/MusicService.cs +++ b/src/NadekoBot/Modules/Music/Services/MusicService.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Concurrent; +using System.Collections.Concurrent; using System.Linq; using System.Threading.Tasks; using Discord; @@ -88,7 +87,7 @@ namespace NadekoBot.Modules.Music.Services { await textCh.SendErrorAsync(GetText("must_be_in_voice")).ConfigureAwait(false); } - throw new ArgumentException(nameof(voiceCh)); + throw new NotInVoiceChannelException(); } _log.Info("Get or add"); return MusicPlayers.GetOrAdd(guildId, _ => diff --git a/src/NadekoBot/Modules/NSFW/NSFW.cs b/src/NadekoBot/Modules/NSFW/NSFW.cs index 238071d9..686c8c33 100644 --- a/src/NadekoBot/Modules/NSFW/NSFW.cs +++ b/src/NadekoBot/Modules/NSFW/NSFW.cs @@ -4,7 +4,6 @@ using Newtonsoft.Json.Linq; using System; using System.Linq; using System.Threading.Tasks; -using NadekoBot.Services; using System.Net.Http; using NadekoBot.Extensions; using System.Threading; diff --git a/src/NadekoBot/Modules/NadekoModule.cs b/src/NadekoBot/Modules/NadekoModule.cs index 62ad29f9..f6f06afd 100644 --- a/src/NadekoBot/Modules/NadekoModule.cs +++ b/src/NadekoBot/Modules/NadekoModule.cs @@ -5,7 +5,6 @@ using NadekoBot.Services; using NLog; using System.Globalization; using System.Threading.Tasks; -using System; using Discord.WebSocket; using NadekoBot.Services.Impl; diff --git a/src/NadekoBot/Modules/Permissions/Common/PermissionsCollection.cs b/src/NadekoBot/Modules/Permissions/Common/PermissionsCollection.cs index cf4e41b2..0f6ab6b9 100644 --- a/src/NadekoBot/Modules/Permissions/Common/PermissionsCollection.cs +++ b/src/NadekoBot/Modules/Permissions/Common/PermissionsCollection.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using NadekoBot.Common; using NadekoBot.Common.Collections; using NadekoBot.Services.Database.Models; diff --git a/src/NadekoBot/Modules/Permissions/FilterCommands.cs b/src/NadekoBot/Modules/Permissions/FilterCommands.cs index 79b068fd..22e22c82 100644 --- a/src/NadekoBot/Modules/Permissions/FilterCommands.cs +++ b/src/NadekoBot/Modules/Permissions/FilterCommands.cs @@ -4,7 +4,6 @@ using Discord.WebSocket; using Microsoft.EntityFrameworkCore; using NadekoBot.Extensions; using NadekoBot.Services; -using System.Collections.Concurrent; using System.Linq; using System.Threading.Tasks; using NadekoBot.Common.Attributes; diff --git a/src/NadekoBot/Modules/Permissions/Permissions.cs b/src/NadekoBot/Modules/Permissions/Permissions.cs index e451eea4..ce7f6fa9 100644 --- a/src/NadekoBot/Modules/Permissions/Permissions.cs +++ b/src/NadekoBot/Modules/Permissions/Permissions.cs @@ -7,7 +7,6 @@ using Discord; using NadekoBot.Services.Database.Models; using System.Collections.Generic; using Discord.WebSocket; -using NadekoBot.Common; using NadekoBot.Common.Attributes; using NadekoBot.Common.TypeReaders; using NadekoBot.Common.TypeReaders.Models; diff --git a/src/NadekoBot/Modules/Permissions/ResetPermissionsCommands.cs b/src/NadekoBot/Modules/Permissions/ResetPermissionsCommands.cs index d11f523f..91e4a9c2 100644 --- a/src/NadekoBot/Modules/Permissions/ResetPermissionsCommands.cs +++ b/src/NadekoBot/Modules/Permissions/ResetPermissionsCommands.cs @@ -1,7 +1,5 @@ using Discord; using Discord.Commands; -using NadekoBot.Services; -using NadekoBot.Services.Database.Models; using System.Threading.Tasks; using NadekoBot.Common.Attributes; using NadekoBot.Modules.Permissions.Services; diff --git a/src/NadekoBot/Modules/Permissions/Services/BlacklistService.cs b/src/NadekoBot/Modules/Permissions/Services/BlacklistService.cs index 0c06b4b1..3c2128dc 100644 --- a/src/NadekoBot/Modules/Permissions/Services/BlacklistService.cs +++ b/src/NadekoBot/Modules/Permissions/Services/BlacklistService.cs @@ -1,5 +1,4 @@ -using System.Collections.Concurrent; -using System.Linq; +using System.Linq; using System.Threading.Tasks; using Discord; using NadekoBot.Common.Collections; @@ -15,9 +14,9 @@ namespace NadekoBot.Modules.Permissions.Services public ConcurrentHashSet BlacklistedGuilds { get; } public ConcurrentHashSet BlacklistedChannels { get; } - public BlacklistService(BotConfig bc) + public BlacklistService(IBotConfigProvider bc) { - var blacklist = bc.Blacklist; + var blacklist = bc.BotConfig.Blacklist; BlacklistedUsers = new ConcurrentHashSet(blacklist.Where(bi => bi.Type == BlacklistType.User).Select(c => c.ItemId)); BlacklistedGuilds = new ConcurrentHashSet(blacklist.Where(bi => bi.Type == BlacklistType.Server).Select(c => c.ItemId)); BlacklistedChannels = new ConcurrentHashSet(blacklist.Where(bi => bi.Type == BlacklistType.Channel).Select(c => c.ItemId)); diff --git a/src/NadekoBot/Modules/Permissions/Services/GlobalPermissionService.cs b/src/NadekoBot/Modules/Permissions/Services/GlobalPermissionService.cs index 0bd2267e..18d5337f 100644 --- a/src/NadekoBot/Modules/Permissions/Services/GlobalPermissionService.cs +++ b/src/NadekoBot/Modules/Permissions/Services/GlobalPermissionService.cs @@ -1,12 +1,10 @@ -using System.Collections.Concurrent; -using System.Linq; +using System.Linq; using System.Threading.Tasks; using Discord; using Discord.WebSocket; using NadekoBot.Common.Collections; using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Services; -using NadekoBot.Services.Database.Models; namespace NadekoBot.Modules.Permissions.Services { @@ -15,10 +13,10 @@ namespace NadekoBot.Modules.Permissions.Services public readonly ConcurrentHashSet BlockedModules; public readonly ConcurrentHashSet BlockedCommands; - public GlobalPermissionService(BotConfig bc) + public GlobalPermissionService(IBotConfigProvider bc) { - BlockedModules = new ConcurrentHashSet(bc.BlockedModules.Select(x => x.Name)); - BlockedCommands = new ConcurrentHashSet(bc.BlockedCommands.Select(x => x.Name)); + BlockedModules = new ConcurrentHashSet(bc.BotConfig.BlockedModules.Select(x => x.Name)); + BlockedCommands = new ConcurrentHashSet(bc.BotConfig.BlockedCommands.Select(x => x.Name)); } public async Task TryBlockLate(DiscordSocketClient client, IUserMessage msg, IGuild guild, IMessageChannel channel, IUser user, string moduleName, string commandName) diff --git a/src/NadekoBot/Modules/Pokemon/Pokemon.cs b/src/NadekoBot/Modules/Pokemon/Pokemon.cs index ba62465f..0389e1b0 100644 --- a/src/NadekoBot/Modules/Pokemon/Pokemon.cs +++ b/src/NadekoBot/Modules/Pokemon/Pokemon.cs @@ -16,10 +16,10 @@ namespace NadekoBot.Modules.Pokemon public class Pokemon : NadekoTopLevelModule { private readonly DbService _db; - private readonly BotConfig _bc; + private readonly IBotConfigProvider _bc; private readonly CurrencyService _cs; - public Pokemon(DbService db, BotConfig bc, CurrencyService cs) + public Pokemon(DbService db, IBotConfigProvider bc, CurrencyService cs) { _db = db; _bc = bc; @@ -230,7 +230,7 @@ namespace NadekoBot.Modules.Pokemon { if (!await _cs.RemoveAsync(user, $"Poke-Heal {target}", amount, true).ConfigureAwait(false)) { - await ReplyErrorLocalized("no_currency", _bc.CurrencySign).ConfigureAwait(false); + await ReplyErrorLocalized("no_currency", _bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } } @@ -243,13 +243,13 @@ namespace NadekoBot.Modules.Pokemon _service.Stats[targetUser.Id].Hp = (targetStats.MaxHp / 2); if (target == "yourself") { - await ReplyConfirmLocalized("revive_yourself", _bc.CurrencySign).ConfigureAwait(false); + await ReplyConfirmLocalized("revive_yourself", _bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } - await ReplyConfirmLocalized("revive_other", Format.Bold(targetUser.ToString()), _bc.CurrencySign).ConfigureAwait(false); + await ReplyConfirmLocalized("revive_other", Format.Bold(targetUser.ToString()), _bc.BotConfig.CurrencySign).ConfigureAwait(false); } - await ReplyConfirmLocalized("healed", Format.Bold(targetUser.ToString()), _bc.CurrencySign).ConfigureAwait(false); + await ReplyConfirmLocalized("healed", Format.Bold(targetUser.ToString()), _bc.BotConfig.CurrencySign).ConfigureAwait(false); } else { @@ -296,7 +296,7 @@ namespace NadekoBot.Modules.Pokemon { if (!await _cs.RemoveAsync(user, $"{user} change type to {typeTargeted}", amount, true).ConfigureAwait(false)) { - await ReplyErrorLocalized("no_currency", _bc.CurrencySign).ConfigureAwait(false); + await ReplyErrorLocalized("no_currency", _bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } } @@ -330,7 +330,7 @@ namespace NadekoBot.Modules.Pokemon //Now for the response await ReplyConfirmLocalized("settype_success", targetType, - _bc.CurrencySign).ConfigureAwait(false); + _bc.BotConfig.CurrencySign).ConfigureAwait(false); } } } diff --git a/src/NadekoBot/Modules/Searches/Common/SearchImageCacher.cs b/src/NadekoBot/Modules/Searches/Common/SearchImageCacher.cs index bf2582e7..cc446af0 100644 --- a/src/NadekoBot/Modules/Searches/Common/SearchImageCacher.cs +++ b/src/NadekoBot/Modules/Searches/Common/SearchImageCacher.cs @@ -8,7 +8,6 @@ using System.Threading.Tasks; using System.Xml; using NadekoBot.Common; using NadekoBot.Extensions; -using NadekoBot.Services; using Newtonsoft.Json; using NLog; diff --git a/src/NadekoBot/Modules/Searches/JokeCommands.cs b/src/NadekoBot/Modules/Searches/JokeCommands.cs index 83dbbd76..3565b482 100644 --- a/src/NadekoBot/Modules/Searches/JokeCommands.cs +++ b/src/NadekoBot/Modules/Searches/JokeCommands.cs @@ -2,7 +2,6 @@ using Discord.Commands; using NadekoBot.Extensions; using NadekoBot.Modules.Searches.Services; -using NadekoBot.Services; using Newtonsoft.Json.Linq; using System.Linq; using System.Net.Http; diff --git a/src/NadekoBot/Modules/Searches/LoLCommands.cs b/src/NadekoBot/Modules/Searches/LoLCommands.cs index 9d1e58cf..78b6928c 100644 --- a/src/NadekoBot/Modules/Searches/LoLCommands.cs +++ b/src/NadekoBot/Modules/Searches/LoLCommands.cs @@ -1,7 +1,5 @@ using Discord; using NadekoBot.Extensions; -using NadekoBot.Services; -using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; diff --git a/src/NadekoBot/Modules/Searches/PlaceCommands.cs b/src/NadekoBot/Modules/Searches/PlaceCommands.cs index 62dd4964..92260965 100644 --- a/src/NadekoBot/Modules/Searches/PlaceCommands.cs +++ b/src/NadekoBot/Modules/Searches/PlaceCommands.cs @@ -1,6 +1,5 @@ using Discord.Commands; using NadekoBot.Extensions; -using NadekoBot.Services; using System; using System.Threading.Tasks; using NadekoBot.Common; diff --git a/src/NadekoBot/Modules/Searches/XkcdCommands.cs b/src/NadekoBot/Modules/Searches/XkcdCommands.cs index 5814ff5e..d5027656 100644 --- a/src/NadekoBot/Modules/Searches/XkcdCommands.cs +++ b/src/NadekoBot/Modules/Searches/XkcdCommands.cs @@ -1,7 +1,6 @@ using Discord; using Discord.Commands; using NadekoBot.Extensions; -using NadekoBot.Services; using Newtonsoft.Json; using System.Net.Http; using System.Threading.Tasks; diff --git a/src/NadekoBot/Modules/Utility/BotConfigCommands.cs b/src/NadekoBot/Modules/Utility/BotConfigCommands.cs new file mode 100644 index 00000000..6262bf98 --- /dev/null +++ b/src/NadekoBot/Modules/Utility/BotConfigCommands.cs @@ -0,0 +1,39 @@ +using Discord; +using Discord.Commands; +using NadekoBot.Common; +using NadekoBot.Common.Attributes; +using NadekoBot.Services; +using System; +using System.Threading.Tasks; + +namespace NadekoBot.Modules.Utility +{ + public partial class Utility + { + public class BotConfigCommands : NadekoSubmodule + { + [NadekoCommand, Usage, Description, Aliases] + [OwnerOnly] + public async Task BotConfigEdit() + { + var names = Enum.GetNames(typeof(BotConfigEditType)); + await ReplyAsync(string.Join(", ", names)).ConfigureAwait(false); + } + + [NadekoCommand, Usage, Description, Aliases] + [OwnerOnly] + public async Task BotConfigEdit(BotConfigEditType type, [Remainder]string newValue = null) + { + if (string.IsNullOrWhiteSpace(newValue)) + newValue = null; + + var success = _service.Edit(type, newValue); + + if (!success) + await ReplyErrorLocalized("bot_config_edit_fail", Format.Bold(type.ToString()), Format.Bold(newValue ?? "NULL")).ConfigureAwait(false); + else + await ReplyConfirmLocalized("bot_config_edit_success", Format.Bold(type.ToString()), Format.Bold(newValue ?? "NULL")).ConfigureAwait(false); + } + } + } +} diff --git a/src/NadekoBot/Modules/Utility/Common/Exceptions/StreamRoleNotFoundException.cs b/src/NadekoBot/Modules/Utility/Common/Exceptions/StreamRoleNotFoundException.cs index ca73e920..d6ac31cf 100644 --- a/src/NadekoBot/Modules/Utility/Common/Exceptions/StreamRoleNotFoundException.cs +++ b/src/NadekoBot/Modules/Utility/Common/Exceptions/StreamRoleNotFoundException.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace NadekoBot.Modules.Utility.Common.Exceptions { diff --git a/src/NadekoBot/Modules/Utility/Common/Exceptions/StreamRolePermissionException.cs b/src/NadekoBot/Modules/Utility/Common/Exceptions/StreamRolePermissionException.cs index a921f3ce..b0fd0dbe 100644 --- a/src/NadekoBot/Modules/Utility/Common/Exceptions/StreamRolePermissionException.cs +++ b/src/NadekoBot/Modules/Utility/Common/Exceptions/StreamRolePermissionException.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace NadekoBot.Modules.Utility.Common.Exceptions { diff --git a/src/NadekoBot/Modules/Utility/PatreonCommands.cs b/src/NadekoBot/Modules/Utility/PatreonCommands.cs index bbfa2f24..96ac04c4 100644 --- a/src/NadekoBot/Modules/Utility/PatreonCommands.cs +++ b/src/NadekoBot/Modules/Utility/PatreonCommands.cs @@ -2,7 +2,6 @@ using Discord.Commands; using System; using NadekoBot.Services; -using NadekoBot.Services.Database.Models; using NadekoBot.Extensions; using Discord; using NadekoBot.Common.Attributes; @@ -16,11 +15,11 @@ namespace NadekoBot.Modules.Utility public class PatreonCommands : NadekoSubmodule { private readonly IBotCredentials _creds; - private readonly BotConfig _config; + private readonly IBotConfigProvider _config; private readonly DbService _db; private readonly CurrencyService _currency; - public PatreonCommands(IBotCredentials creds, BotConfig config, DbService db, CurrencyService currency) + public PatreonCommands(IBotCredentials creds, IBotConfigProvider config, DbService db, CurrencyService currency) { _creds = creds; _config = config; @@ -64,7 +63,7 @@ namespace NadekoBot.Modules.Utility if (amount > 0) { - await ReplyConfirmLocalized("clpa_success", amount + _config.CurrencySign).ConfigureAwait(false); + await ReplyConfirmLocalized("clpa_success", amount + _config.BotConfig.CurrencySign).ConfigureAwait(false); return; } var rem = (_service.Interval - (DateTime.UtcNow - _service.LastUpdate)); diff --git a/src/NadekoBot/Modules/Utility/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/QuoteCommands.cs index 141c4783..8b4a6752 100644 --- a/src/NadekoBot/Modules/Utility/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/QuoteCommands.cs @@ -3,7 +3,6 @@ using Discord.Commands; using NadekoBot.Extensions; using NadekoBot.Services; using NadekoBot.Services.Database.Models; -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/NadekoBot/Modules/Utility/Services/RemindService.cs b/src/NadekoBot/Modules/Utility/Services/RemindService.cs index 43e809a6..0e3b2206 100644 --- a/src/NadekoBot/Modules/Utility/Services/RemindService.cs +++ b/src/NadekoBot/Modules/Utility/Services/RemindService.cs @@ -25,11 +25,11 @@ namespace NadekoBot.Modules.Utility.Services private readonly Logger _log; private readonly CancellationTokenSource cancelSource; private readonly CancellationToken cancelAllToken; - private readonly BotConfig _config; + private readonly IBotConfigProvider _config; private readonly DiscordSocketClient _client; private readonly DbService _db; - public RemindService(DiscordSocketClient client, BotConfig config, DbService db, + public RemindService(DiscordSocketClient client, IBotConfigProvider config, DbService db, StartingGuildsService guilds, IUnitOfWork uow) { _config = config; @@ -41,7 +41,7 @@ namespace NadekoBot.Modules.Utility.Services cancelAllToken = cancelSource.Token; var reminders = uow.Reminders.GetIncludedReminders(guilds).ToList(); - RemindMessageFormat = _config.RemindMessageFormat; + RemindMessageFormat = _config.BotConfig.RemindMessageFormat; foreach (var r in reminders) { diff --git a/src/NadekoBot/Modules/Utility/Services/VerboseErrorsService.cs b/src/NadekoBot/Modules/Utility/Services/VerboseErrorsService.cs index a3f573bd..9f438128 100644 --- a/src/NadekoBot/Modules/Utility/Services/VerboseErrorsService.cs +++ b/src/NadekoBot/Modules/Utility/Services/VerboseErrorsService.cs @@ -1,5 +1,4 @@ -using System.Collections.Concurrent; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Discord; diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index 8870820e..b49b0562 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -8,7 +8,6 @@ using System; using System.Linq; using System.Reflection; using System.Threading.Tasks; -using NadekoBot.Modules.Permissions; using System.Collections.Immutable; using System.Diagnostics; using NadekoBot.Services.Database.Models; @@ -34,7 +33,6 @@ namespace NadekoBot public CommandService CommandService { get; } public DbService Db { get; } - public BotConfig BotConfig { get; } public ImmutableArray AllGuildConfigs { get; private set; } /* I don't know how to make this not be static @@ -54,6 +52,8 @@ namespace NadekoBot private readonly ShardComClient _comClient; + private readonly BotConfig _botConfig; + public NadekoBot(int shardId, int parentProcessId, int? port = null) { if (shardId < 0) @@ -85,9 +85,9 @@ namespace NadekoBot using (var uow = Db.UnitOfWork) { - BotConfig = uow.BotConfig.GetOrCreate(); - OkColor = new Color(Convert.ToUInt32(BotConfig.OkColor, 16)); - ErrorColor = new Color(Convert.ToUInt32(BotConfig.ErrorColor, 16)); + _botConfig = uow.BotConfig.GetOrCreate(); + OkColor = new Color(Convert.ToUInt32(_botConfig.OkColor, 16)); + ErrorColor = new Color(Convert.ToUInt32(_botConfig.ErrorColor, 16)); } SetupShard(parentProcessId, port.Value); @@ -124,13 +124,13 @@ namespace NadekoBot { AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs(startingGuildIdList).ToImmutableArray(); - var localization = new Localization(BotConfig.Locale, AllGuildConfigs.ToDictionary(x => x.GuildId, x => x.Locale), Db); + var localization = new Localization(_botConfig.Locale, AllGuildConfigs.ToDictionary(x => x.GuildId, x => x.Locale), Db); //initialize Services Services = new NServiceProvider.ServiceProviderBuilder() .AddManual(Credentials) .AddManual(Db) - .AddManual(BotConfig) + .AddManual(_botConfig) .AddManual(Client) .AddManual(CommandService) .AddManual(localization) diff --git a/src/NadekoBot/NadekoBot.csproj b/src/NadekoBot/NadekoBot.csproj index 6d719b32..810fa907 100644 --- a/src/NadekoBot/NadekoBot.csproj +++ b/src/NadekoBot/NadekoBot.csproj @@ -91,8 +91,4 @@ - - - - diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index e1635531..03aaed3c 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -3573,4 +3573,13 @@ Adds or removes a whitelisted user. Whitelisted users will receive the stream role even if they don't have the specified keyword in their stream title. + + botconfigedit bce + + + `{0}bce CurrencyName b1nzy` or `{0}bce` + + + Sets one of available bot config settings to a specified value. Use the command without any parameters to get a list of available settings. + diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index 81a70da2..b1a25463 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -50,7 +50,7 @@ namespace NadekoBot.Services public ConcurrentHashSet UsersOnShortCooldown { get; } = new ConcurrentHashSet(); private readonly Timer _clearUsersOnShortCooldown; - public CommandHandler(DiscordSocketClient client, DbService db, BotConfig bc, IEnumerable gcs, CommandService commandService, IBotCredentials credentials, NadekoBot bot) + public CommandHandler(DiscordSocketClient client, DbService db, IBotConfigProvider bc, IEnumerable gcs, CommandService commandService, IBotCredentials credentials, NadekoBot bot) { _client = client; _commandService = commandService; @@ -65,7 +65,7 @@ namespace NadekoBot.Services UsersOnShortCooldown.Clear(); }, null, GlobalCommandsCooldown, GlobalCommandsCooldown); - DefaultPrefix = bc.DefaultPrefix; + DefaultPrefix = bc.BotConfig.DefaultPrefix; _prefixes = gcs .Where(x => x.Prefix != null) .ToDictionary(x => x.GuildId, x => x.Prefix) diff --git a/src/NadekoBot/Services/CurrencyService.cs b/src/NadekoBot/Services/CurrencyService.cs index fb664d62..d7306a81 100644 --- a/src/NadekoBot/Services/CurrencyService.cs +++ b/src/NadekoBot/Services/CurrencyService.cs @@ -9,10 +9,10 @@ namespace NadekoBot.Services { public class CurrencyService : INService { - private readonly BotConfig _config; + private readonly IBotConfigProvider _config; private readonly DbService _db; - public CurrencyService(BotConfig config, DbService db) + public CurrencyService(IBotConfigProvider config, DbService db) { _config = config; _db = db; @@ -23,7 +23,7 @@ namespace NadekoBot.Services var success = await RemoveAsync(author.Id, reason, amount); if (success && sendMessage) - try { await author.SendErrorAsync($"`You lost:` {amount} {_config.CurrencySign}\n`Reason:` {reason}").ConfigureAwait(false); } catch { } + try { await author.SendErrorAsync($"`You lost:` {amount} {_config.BotConfig.CurrencySign}\n`Reason:` {reason}").ConfigureAwait(false); } catch { } return success; } @@ -65,7 +65,7 @@ namespace NadekoBot.Services await AddAsync(author.Id, reason, amount); if (sendMessage) - try { await author.SendConfirmAsync($"`You received:` {amount} {_config.CurrencySign}\n`Reason:` {reason}").ConfigureAwait(false); } catch { } + try { await author.SendConfirmAsync($"`You received:` {amount} {_config.BotConfig.CurrencySign}\n`Reason:` {reason}").ConfigureAwait(false); } catch { } } public async Task AddAsync(ulong receiverId, string reason, long amount, IUnitOfWork uow = null) diff --git a/src/NadekoBot/Services/Database/Models/StreamRoleSettings.cs b/src/NadekoBot/Services/Database/Models/StreamRoleSettings.cs index 05449039..8ef5b690 100644 --- a/src/NadekoBot/Services/Database/Models/StreamRoleSettings.cs +++ b/src/NadekoBot/Services/Database/Models/StreamRoleSettings.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; namespace NadekoBot.Services.Database.Models { diff --git a/src/NadekoBot/Services/Database/Repositories/IReminderRepository.cs b/src/NadekoBot/Services/Database/Repositories/IReminderRepository.cs index a4812775..dc757dbc 100644 --- a/src/NadekoBot/Services/Database/Repositories/IReminderRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/IReminderRepository.cs @@ -1,5 +1,4 @@ using NadekoBot.Services.Database.Models; -using System.Collections; using System.Collections.Generic; namespace NadekoBot.Services.Database.Repositories diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/ReminderRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/ReminderRepository.cs index b2b13a2b..e29cc3f2 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/ReminderRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/ReminderRepository.cs @@ -1,6 +1,5 @@ using NadekoBot.Services.Database.Models; using Microsoft.EntityFrameworkCore; -using System; using System.Collections.Generic; using System.Linq; diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/WarningsRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/WarningsRepository.cs index ef27ebd9..cb2cc089 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/WarningsRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/WarningsRepository.cs @@ -2,7 +2,6 @@ using Microsoft.EntityFrameworkCore; using System.Linq; using System.Threading.Tasks; -using System; namespace NadekoBot.Services.Database.Repositories.Impl { diff --git a/src/NadekoBot/Services/IBotConfigProvider.cs b/src/NadekoBot/Services/IBotConfigProvider.cs new file mode 100644 index 00000000..1e65f202 --- /dev/null +++ b/src/NadekoBot/Services/IBotConfigProvider.cs @@ -0,0 +1,12 @@ +using NadekoBot.Common; +using NadekoBot.Services.Database.Models; + +namespace NadekoBot.Services +{ + public interface IBotConfigProvider : INService + { + BotConfig BotConfig { get; } + void Reload(); + bool Edit(BotConfigEditType type, string newValue); + } +} diff --git a/src/NadekoBot/Services/IImagesService.cs b/src/NadekoBot/Services/IImagesService.cs index 5678191c..08d8f504 100644 --- a/src/NadekoBot/Services/IImagesService.cs +++ b/src/NadekoBot/Services/IImagesService.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Immutable; +using System.Collections.Immutable; namespace NadekoBot.Services { diff --git a/src/NadekoBot/Services/INService.cs b/src/NadekoBot/Services/INService.cs index 76c30abb..13bbbeea 100644 --- a/src/NadekoBot/Services/INService.cs +++ b/src/NadekoBot/Services/INService.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NadekoBot.Services +namespace NadekoBot.Services { /// /// All services must implement this interface in order to be auto-discovered by the DI system diff --git a/src/NadekoBot/Services/Impl/BotConfigProvider.cs b/src/NadekoBot/Services/Impl/BotConfigProvider.cs new file mode 100644 index 00000000..c18a0e1a --- /dev/null +++ b/src/NadekoBot/Services/Impl/BotConfigProvider.cs @@ -0,0 +1,111 @@ +using System; +using NadekoBot.Common; +using NadekoBot.Services.Database.Models; +using NadekoBot.Services; + +namespace NadekoBot.Services.Impl +{ + public class BotConfigProvider : IBotConfigProvider + { + private readonly DbService _db; + public BotConfig BotConfig { get; private set; } + + public BotConfigProvider(DbService db, BotConfig bc) + { + _db = db; + BotConfig = bc; + } + + public void Reload() + { + using (var uow = _db.UnitOfWork) + { + BotConfig = uow.BotConfig.GetOrCreate(); + } + } + + public bool Edit(BotConfigEditType type, string newValue) + { + using (var uow = _db.UnitOfWork) + { + var bc = uow.BotConfig.GetOrCreate(); + switch (type) + { + case BotConfigEditType.CurrencyGenerationChance: + if (float.TryParse(newValue, out var chance) + && chance >= 0 + && chance <= 1) + { + bc.CurrencyGenerationChance = chance; + } + else + { + return false; + } + break; + case BotConfigEditType.CurrencyGenerationCooldown: + if (int.TryParse(newValue, out var cd) && cd >= 1) + { + bc.CurrencyGenerationCooldown = cd; + } + else + { + return false; + } + break; + case BotConfigEditType.CurrencyName: + bc.CurrencyName = newValue ?? "-"; + break; + case BotConfigEditType.CurrencyPluralName: + bc.CurrencyPluralName = newValue ?? bc.CurrencyName + "s"; + break; + case BotConfigEditType.CurrencySign: + bc.CurrencySign = newValue ?? "-"; + break; + case BotConfigEditType.DmHelpString: + bc.DMHelpString = string.IsNullOrWhiteSpace(newValue) + ? "-" + : newValue; + break; + case BotConfigEditType.HelpString: + bc.HelpString = string.IsNullOrWhiteSpace(newValue) + ? "-" + : newValue; + break; + case BotConfigEditType.CurrencyDropAmount: + if (int.TryParse(newValue, out var amount) && amount > 0) + bc.CurrencyDropAmount = amount; + else + return false; + break; + case BotConfigEditType.CurrencyDropAmountMax: + if (newValue == null) + bc.CurrencyDropAmountMax = null; + else if (int.TryParse(newValue, out var maxAmount) && maxAmount > 0) + bc.CurrencyDropAmountMax = maxAmount; + else + return false; + break; + case BotConfigEditType.MinimumBetAmount: + if (int.TryParse(newValue, out var minBetAmount) && minBetAmount > 0) + bc.MinimumBetAmount = minBetAmount; + else + return false; + break; + case BotConfigEditType.TriviaCurrencyReward: + if (int.TryParse(newValue, out var triviaReward) && triviaReward > 0) + bc.TriviaCurrencyReward = triviaReward; + else + return false; + break; + default: + return false; + } + + BotConfig = bc; + uow.Complete(); + } + return true; + } + } +} diff --git a/src/NadekoBot/Services/Impl/ImagesService.cs b/src/NadekoBot/Services/Impl/ImagesService.cs index 95930464..7153328f 100644 --- a/src/NadekoBot/Services/Impl/ImagesService.cs +++ b/src/NadekoBot/Services/Impl/ImagesService.cs @@ -1,7 +1,6 @@ using NLog; using System; using System.Collections.Immutable; -using System.Diagnostics; using System.IO; using System.Linq; diff --git a/src/NadekoBot/Services/Impl/SyncPreconditionService.cs b/src/NadekoBot/Services/Impl/SyncPreconditionService.cs index 30d5b48a..b6a47133 100644 --- a/src/NadekoBot/Services/Impl/SyncPreconditionService.cs +++ b/src/NadekoBot/Services/Impl/SyncPreconditionService.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NadekoBot.Services.Impl +namespace NadekoBot.Services.Impl { public class SyncPreconditionService { diff --git a/src/NadekoBot/Services/LogSetup.cs b/src/NadekoBot/Services/LogSetup.cs index 159b447e..0d3234ee 100644 --- a/src/NadekoBot/Services/LogSetup.cs +++ b/src/NadekoBot/Services/LogSetup.cs @@ -1,11 +1,6 @@ using NLog; using NLog.Config; using NLog.Targets; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace NadekoBot.Services { diff --git a/src/NadekoBot/Services/ServiceProvider.cs b/src/NadekoBot/Services/ServiceProvider.cs index 6e0c642b..32a8419d 100644 --- a/src/NadekoBot/Services/ServiceProvider.cs +++ b/src/NadekoBot/Services/ServiceProvider.cs @@ -48,6 +48,8 @@ namespace NadekoBot.Services var interfaces = new HashSet(allTypes .Where(x => x.GetInterfaces().Contains(typeof(INService)) && x.GetTypeInfo().IsInterface)); + var alreadyFailed = new Dictionary(); + var sw = Stopwatch.StartNew(); var swInstance = new Stopwatch(); while (services.Count > 0) @@ -71,11 +73,20 @@ namespace NadekoBot.Services else //if i failed getting it, add it to the end, and break { services.Enqueue(type); + if (alreadyFailed.ContainsKey(type)) + { + alreadyFailed[type]++; + if (alreadyFailed[type] > 3) + _log.Warn(type.Name + " wasn't instantiated in the first 3 attempts. Missing " + arg.Name + " type"); + } + else + alreadyFailed.Add(type, 1); break; } } if (args.Count != argTypes.Length) continue; + // _log.Info("Loading " + type.Name); swInstance.Restart(); var instance = ctor.Invoke(args.ToArray()); swInstance.Stop(); diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index b7d95c69..77522709 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -16,7 +16,6 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using NadekoBot.Common.Collections; using SixLabors.Primitives; -using ImageSharp.PixelFormats; namespace NadekoBot.Extensions { diff --git a/src/NadekoBot/_strings/ResponseStrings.en-US.json b/src/NadekoBot/_strings/ResponseStrings.en-US.json index 3ca43151..f9e47119 100644 --- a/src/NadekoBot/_strings/ResponseStrings.en-US.json +++ b/src/NadekoBot/_strings/ResponseStrings.en-US.json @@ -626,6 +626,8 @@ "utility_activity_users_total": "{0} users total.", "utility_author": "Author", "utility_botid": "Bot ID", + "utility_bot_config_edit_fail": "Failed setting {0} to the value {1}", + "utility_bot_config_edit_success": "The value of {0} is set to {1}", "utility_calcops": "List of functions in {0}calc command", "utility_channelid": "{0} of this channel is {1}", "utility_channel_topic": "Channel topic",