From e8c5401b15e62b44f5763559da151d4148cdc581 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Wed, 5 Oct 2016 04:03:57 +0200 Subject: [PATCH] Fixed up the pr --- .../Administration/Commands/Migration.cs | 62 ++----------------- .../Administration/Commands/Migration/0_9..cs | 48 ++++++++++++++ .../Commands/Migration/MigrationException.cs | 13 ++++ 3 files changed, 67 insertions(+), 56 deletions(-) create mode 100644 src/NadekoBot/Modules/Administration/Commands/Migration/0_9..cs create mode 100644 src/NadekoBot/Modules/Administration/Commands/Migration/MigrationException.cs diff --git a/src/NadekoBot/Modules/Administration/Commands/Migration.cs b/src/NadekoBot/Modules/Administration/Commands/Migration.cs index ad8d0168..d6898502 100644 --- a/src/NadekoBot/Modules/Administration/Commands/Migration.cs +++ b/src/NadekoBot/Modules/Administration/Commands/Migration.cs @@ -11,6 +11,7 @@ using NadekoBot.Services; using NadekoBot.Services.Database.Models; using Newtonsoft.Json; using NLog; +using NadekoBot.Modules.Administration.Commands.Migration; namespace NadekoBot.Modules.Administration { @@ -46,7 +47,7 @@ namespace NadekoBot.Modules.Administration switch (i) { case 0: - Migrate0_9To1_0(); + await Migrate0_9To1_0(); break; } } @@ -54,11 +55,11 @@ namespace NadekoBot.Modules.Administration } catch (MigrationException) { - await umsg.Channel.SendMessageAsync("Error while migrating, check logs for more informations").ConfigureAwait(false); + await umsg.Channel.SendMessageAsync(":warning: Error while migrating, check logs for more informations.").ConfigureAwait(false); } } - private void Migrate0_9To1_0() + private async Task Migrate0_9To1_0() { Config0_9 oldData; try @@ -67,13 +68,7 @@ namespace NadekoBot.Modules.Administration } catch (FileNotFoundException) { - _log.Warn("config.json not found, assuming not needed"); - using (var uow = DbHandler.UnitOfWork()) - { - var botConfig = uow.BotConfig.GetOrCreate(); - botConfig.MigrationVersion = 1; - uow.CompleteAsync().ConfigureAwait(false); - } + _log.Warn("config.json not found"); return; } catch (Exception) @@ -167,54 +162,9 @@ namespace NadekoBot.Modules.Administration //NOW save it botConfig.MigrationVersion = 1; - uow.CompleteAsync(); + await uow.CompleteAsync().ConfigureAwait(false); } } - - private class MigrationException : Exception - { - } - - protected class CommandPrefixes0_9 - { - public string Administration { get; set; } - public string Searches { get; set; } - public string NSFW { get; set; } - public string Conversations { get; set; } - public string ClashOfClans { get; set; } - public string Help { get; set; } - public string Music { get; set; } - public string Trello { get; set; } - public string Games { get; set; } - public string Gambling { get; set; } - public string Permissions { get; set; } - public string Programming { get; set; } - public string Pokemon { get; set; } - public string Utility { get; set; } - } - - protected class Config0_9 - { - public bool DontJoinServers { get; set; } - public bool ForwardMessages { get; set; } - public bool ForwardToAllOwners { get; set; } - public bool IsRotatingStatus { get; set; } - public int BufferSize { get; set; } - public List RaceAnimals { get; set; } - public string RemindMessageFormat { get; set; } - public Dictionary> CustomReactions { get; set; } - public List RotatingStatuses { get; set; } - public CommandPrefixes0_9 CommandPrefixes { get; set; } - public List ServerBlacklist { get; set; } - public List ChannelBlacklist { get; set; } - public List UserBlacklist { get; set; } - public List _8BallResponses { get; set; } - public string CurrencySign { get; set; } - public string CurrencyName { get; set; } - public string DMHelpString { get; set; } - public string HelpString { get; set; } - } - } } } diff --git a/src/NadekoBot/Modules/Administration/Commands/Migration/0_9..cs b/src/NadekoBot/Modules/Administration/Commands/Migration/0_9..cs new file mode 100644 index 00000000..87a18f9b --- /dev/null +++ b/src/NadekoBot/Modules/Administration/Commands/Migration/0_9..cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NadekoBot.Modules.Administration.Commands.Migration +{ + public class CommandPrefixes0_9 + { + public string Administration { get; set; } + public string Searches { get; set; } + public string NSFW { get; set; } + public string Conversations { get; set; } + public string ClashOfClans { get; set; } + public string Help { get; set; } + public string Music { get; set; } + public string Trello { get; set; } + public string Games { get; set; } + public string Gambling { get; set; } + public string Permissions { get; set; } + public string Programming { get; set; } + public string Pokemon { get; set; } + public string Utility { get; set; } + } + + public class Config0_9 + { + public bool DontJoinServers { get; set; } + public bool ForwardMessages { get; set; } + public bool ForwardToAllOwners { get; set; } + public bool IsRotatingStatus { get; set; } + public int BufferSize { get; set; } + public List RaceAnimals { get; set; } + public string RemindMessageFormat { get; set; } + public Dictionary> CustomReactions { get; set; } + public List RotatingStatuses { get; set; } + public CommandPrefixes0_9 CommandPrefixes { get; set; } + public List ServerBlacklist { get; set; } + public List ChannelBlacklist { get; set; } + public List UserBlacklist { get; set; } + public List _8BallResponses { get; set; } + public string CurrencySign { get; set; } + public string CurrencyName { get; set; } + public string DMHelpString { get; set; } + public string HelpString { get; set; } + } +} \ No newline at end of file diff --git a/src/NadekoBot/Modules/Administration/Commands/Migration/MigrationException.cs b/src/NadekoBot/Modules/Administration/Commands/Migration/MigrationException.cs new file mode 100644 index 00000000..1b26d161 --- /dev/null +++ b/src/NadekoBot/Modules/Administration/Commands/Migration/MigrationException.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NadekoBot.Modules.Administration.Commands.Migration +{ + public class MigrationException : Exception + { + + } +}