diff --git a/src/NadekoBot/Migrations/20161011031532_first.Designer.cs b/src/NadekoBot/Migrations/20161011200458_first.Designer.cs similarity index 98% rename from src/NadekoBot/Migrations/20161011031532_first.Designer.cs rename to src/NadekoBot/Migrations/20161011200458_first.Designer.cs index 9c5398ec..3cb606dd 100644 --- a/src/NadekoBot/Migrations/20161011031532_first.Designer.cs +++ b/src/NadekoBot/Migrations/20161011200458_first.Designer.cs @@ -8,7 +8,7 @@ using NadekoBot.Services.Database.Impl; namespace NadekoBot.Migrations { [DbContext(typeof(NadekoSqliteContext))] - [Migration("20161011031532_first")] + [Migration("20161011200458_first")] partial class first { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -53,8 +53,6 @@ namespace NadekoBot.Migrations b.Property("DMHelpString"); - b.Property("DontJoinServers"); - b.Property("ForwardMessages"); b.Property("ForwardToAllOwners"); @@ -440,7 +438,7 @@ namespace NadekoBot.Migrations b.Property("Id") .ValueGeneratedOnAdd(); - b.Property("BotConfigId"); + b.Property("BotConfigId"); b.Property("ModuleName"); @@ -723,10 +721,9 @@ namespace NadekoBot.Migrations modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b => { - b.HasOne("NadekoBot.Services.Database.Models.BotConfig", "BotConfig") + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") .WithMany("ModulePrefixes") - .HasForeignKey("BotConfigId") - .OnDelete(DeleteBehavior.Cascade); + .HasForeignKey("BotConfigId"); }); modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b => diff --git a/src/NadekoBot/Migrations/20161011031532_first.cs b/src/NadekoBot/Migrations/20161011200458_first.cs similarity index 99% rename from src/NadekoBot/Migrations/20161011031532_first.cs rename to src/NadekoBot/Migrations/20161011200458_first.cs index 2a346ba7..155508a6 100644 --- a/src/NadekoBot/Migrations/20161011031532_first.cs +++ b/src/NadekoBot/Migrations/20161011200458_first.cs @@ -21,7 +21,6 @@ namespace NadekoBot.Migrations CurrencyPluralName = table.Column(nullable: true), CurrencySign = table.Column(nullable: true), DMHelpString = table.Column(nullable: true), - DontJoinServers = table.Column(nullable: false), ForwardMessages = table.Column(nullable: false), ForwardToAllOwners = table.Column(nullable: false), HelpString = table.Column(nullable: true), @@ -292,7 +291,7 @@ namespace NadekoBot.Migrations { Id = table.Column(nullable: false) .Annotation("Autoincrement", true), - BotConfigId = table.Column(nullable: false), + BotConfigId = table.Column(nullable: true), ModuleName = table.Column(nullable: true), Prefix = table.Column(nullable: true) }, @@ -304,7 +303,7 @@ namespace NadekoBot.Migrations column: x => x.BotConfigId, principalTable: "BotConfig", principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( diff --git a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs index 19a4d2e1..ee91013c 100644 --- a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs +++ b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs @@ -52,8 +52,6 @@ namespace NadekoBot.Migrations b.Property("DMHelpString"); - b.Property("DontJoinServers"); - b.Property("ForwardMessages"); b.Property("ForwardToAllOwners"); @@ -439,7 +437,7 @@ namespace NadekoBot.Migrations b.Property("Id") .ValueGeneratedOnAdd(); - b.Property("BotConfigId"); + b.Property("BotConfigId"); b.Property("ModuleName"); @@ -722,10 +720,9 @@ namespace NadekoBot.Migrations modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b => { - b.HasOne("NadekoBot.Services.Database.Models.BotConfig", "BotConfig") + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") .WithMany("ModulePrefixes") - .HasForeignKey("BotConfigId") - .OnDelete(DeleteBehavior.Cascade); + .HasForeignKey("BotConfigId"); }); modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b => diff --git a/src/NadekoBot/Modules/Administration/Commands/Migration.cs b/src/NadekoBot/Modules/Administration/Commands/Migration.cs index 0bf99725..3d5ea9ad 100644 --- a/src/NadekoBot/Modules/Administration/Commands/Migration.cs +++ b/src/NadekoBot/Modules/Administration/Commands/Migration.cs @@ -15,6 +15,7 @@ using NadekoBot.Modules.Administration.Commands.Migration; using System.Collections.Concurrent; using NadekoBot.Extensions; using NadekoBot.Services.Database; +using Microsoft.Data.Sqlite; namespace NadekoBot.Modules.Administration { @@ -67,9 +68,10 @@ namespace NadekoBot.Modules.Administration using (var uow = DbHandler.UnitOfWork()) { var botConfig = uow.BotConfig.GetOrCreate(); - MigrateConfig0_9(botConfig); + MigrateConfig0_9(uow, botConfig); MigratePermissions0_9(uow); MigrateServerSpecificConfigs0_9(uow); + MigrateDb0_9(uow); //NOW save it botConfig.MigrationVersion = 1; @@ -77,6 +79,59 @@ namespace NadekoBot.Modules.Administration } } + private void MigrateDb0_9(IUnitOfWork uow) + { + var db = new SqliteConnection("Data Source=data/nadekobot.sqlite;Version=3;"); + db.Open(); + + var com = db.CreateCommand(); + com.CommandText = "SELECT * FROM Announcement"; + + var reader = com.ExecuteReader(); + while(reader.Read()) + { + var gid = (ulong)reader["ServerId"]; + var greet = (bool)reader["Greet"]; + var greetDM = (bool)reader["GreetPM"]; + var greetChannel = (ulong)reader["GreetChannelId"]; + var greetMsg = (string)reader["GreetText"]; + var bye = (bool)reader["Bye"]; + var byeDM = (bool)reader["ByePM"]; + var byeChannel = (ulong)reader["ByeChannelId"]; + var byeMsg = (string)reader["ByeText"]; + bool grdel = (bool)reader["DeleteGreetMessages"]; + var byedel = grdel; + var gc = uow.GuildConfigs.For(gid); + + if (greetDM) + gc.SendDmGreetMessage = greet; + else + gc.SendChannelGreetMessage = greet; + gc.GreetMessageChannelId = greetChannel; + gc.ChannelGreetMessageText = greetMsg; + + gc.SendChannelByeMessage = bye; + gc.ByeMessageChannelId = byeChannel; + gc.ChannelByeMessageText = byeMsg; + + gc.AutoDeleteByeMessages = gc.AutoDeleteGreetMessages = grdel; + } + + var com2 = db.CreateCommand(); + com.CommandText = "SELECT * FROM Announcement"; + + var reader2 = com.ExecuteReader(); + while (reader2.Read()) + { + uow.Currency.Add(new Currency() + { + Amount = (long)reader2["Value"], + UserId = (ulong)reader2["UserId"] + }); + } + db.Close(); + } + private void MigrateServerSpecificConfigs0_9(IUnitOfWork uow) { const string specificConfigsPath = "data/ServerSpecificConfigs.json"; @@ -119,6 +174,11 @@ namespace NadekoBot.Modules.Administration guildConfig.LogSetting.IsLogging = data.LogChannel != null; guildConfig.LogSetting.ChannelId = data.LogChannel ?? 0; guildConfig.LogSetting.IgnoredChannels = new HashSet(data.LogserverIgnoreChannels.Select(id => new IgnoredLogChannel() { ChannelId = id })); + + guildConfig.LogSetting.LogUserPresence = data.LogPresenceChannel != null; + guildConfig.LogSetting.UserPresenceChannelId = data.LogPresenceChannel ?? 0; + + guildConfig.FollowedStreams = new HashSet(data.ObservingStreams.Select(x => { FollowedStream.FollowedStreamType type = FollowedStream.FollowedStreamType.Twitch; @@ -212,7 +272,7 @@ namespace NadekoBot.Modules.Administration } - private void MigrateConfig0_9(BotConfig botConfig) + private void MigrateConfig0_9(IUnitOfWork uow, BotConfig botConfig) { Config0_9 oldConfig; const string configPath = "data/config.json"; @@ -255,52 +315,52 @@ namespace NadekoBot.Modules.Administration botConfig.RaceAnimals = races; //Prefix - var prefix = new HashSet + botConfig.ModulePrefixes.Clear(); + botConfig.ModulePrefixes.AddRange(new HashSet + { + new ModulePrefix() { - new ModulePrefix() - { - ModuleName = "Administration", - Prefix = oldConfig.CommandPrefixes.Administration - }, - new ModulePrefix() - { - ModuleName = "Searches", - Prefix = oldConfig.CommandPrefixes.Searches - }, - new ModulePrefix() {ModuleName = "NSFW", Prefix = oldConfig.CommandPrefixes.NSFW}, - new ModulePrefix() - { - ModuleName = "Conversations", - Prefix = oldConfig.CommandPrefixes.Conversations - }, - new ModulePrefix() - { - ModuleName = "ClashOfClans", - Prefix = oldConfig.CommandPrefixes.ClashOfClans - }, - new ModulePrefix() {ModuleName = "Help", Prefix = oldConfig.CommandPrefixes.Help}, - new ModulePrefix() {ModuleName = "Music", Prefix = oldConfig.CommandPrefixes.Music}, - new ModulePrefix() {ModuleName = "Trello", Prefix = oldConfig.CommandPrefixes.Trello}, - new ModulePrefix() {ModuleName = "Games", Prefix = oldConfig.CommandPrefixes.Games}, - new ModulePrefix() - { - ModuleName = "Gambling", - Prefix = oldConfig.CommandPrefixes.Gambling - }, - new ModulePrefix() - { - ModuleName = "Permissions", - Prefix = oldConfig.CommandPrefixes.Permissions - }, - new ModulePrefix() - { - ModuleName = "Programming", - Prefix = oldConfig.CommandPrefixes.Programming - }, - new ModulePrefix() {ModuleName = "Pokemon", Prefix = oldConfig.CommandPrefixes.Pokemon}, - new ModulePrefix() {ModuleName = "Utility", Prefix = oldConfig.CommandPrefixes.Utility} - }; - botConfig.ModulePrefixes = prefix; + ModuleName = "Administration", + Prefix = oldConfig.CommandPrefixes.Administration + }, + new ModulePrefix() + { + ModuleName = "Searches", + Prefix = oldConfig.CommandPrefixes.Searches + }, + new ModulePrefix() {ModuleName = "NSFW", Prefix = oldConfig.CommandPrefixes.NSFW}, + new ModulePrefix() + { + ModuleName = "Conversations", + Prefix = oldConfig.CommandPrefixes.Conversations + }, + new ModulePrefix() + { + ModuleName = "ClashOfClans", + Prefix = oldConfig.CommandPrefixes.ClashOfClans + }, + new ModulePrefix() {ModuleName = "Help", Prefix = oldConfig.CommandPrefixes.Help}, + new ModulePrefix() {ModuleName = "Music", Prefix = oldConfig.CommandPrefixes.Music}, + new ModulePrefix() {ModuleName = "Trello", Prefix = oldConfig.CommandPrefixes.Trello}, + new ModulePrefix() {ModuleName = "Games", Prefix = oldConfig.CommandPrefixes.Games}, + new ModulePrefix() + { + ModuleName = "Gambling", + Prefix = oldConfig.CommandPrefixes.Gambling + }, + new ModulePrefix() + { + ModuleName = "Permissions", + Prefix = oldConfig.CommandPrefixes.Permissions + }, + new ModulePrefix() + { + ModuleName = "Programming", + Prefix = oldConfig.CommandPrefixes.Programming + }, + new ModulePrefix() {ModuleName = "Pokemon", Prefix = oldConfig.CommandPrefixes.Pokemon}, + new ModulePrefix() {ModuleName = "Utility", Prefix = oldConfig.CommandPrefixes.Utility} + }); //Blacklist var blacklist = new HashSet(oldConfig.ServerBlacklist.Select(server => new BlacklistItem() { ItemId = server, Type = BlacklistItem.BlacklistType.Server })); @@ -311,6 +371,19 @@ namespace NadekoBot.Modules.Administration //Eightball botConfig.EightBallResponses = new HashSet(oldConfig._8BallResponses.Select(response => new EightBallResponse() { Text = response })); + //customreactions + uow.CustomReactions.AddRange(oldConfig.CustomReactions.SelectMany(cr => + { + return cr.Value.Select(res => new CustomReaction() + { + GuildId = 0, + IsRegex = false, + OwnerOnly = false, + Response = res, + Trigger = cr.Key, + }); + }).ToArray()); + try { File.Move(configPath, "./data/DELETE_ME_config.json"); } catch { } } } diff --git a/src/NadekoBot/Modules/Administration/Commands/Migration/0_9..cs b/src/NadekoBot/Modules/Administration/Commands/Migration/0_9..cs index 1be87724..7606cf82 100644 --- a/src/NadekoBot/Modules/Administration/Commands/Migration/0_9..cs +++ b/src/NadekoBot/Modules/Administration/Commands/Migration/0_9..cs @@ -167,7 +167,7 @@ namespace NadekoBot.Modules.Administration.Commands.Migration public bool VoicePlusTextEnabled { get; set; } public bool SendPrivateMessageOnMention { get; set; } public ulong? LogChannel { get; set; } = null; - public ulong? LogPresenceChannel = null; + public ulong? LogPresenceChannel { get; set; } = null; public HashSet LogserverIgnoreChannels { get; set; } public ConcurrentDictionary VoiceChannelLog { get; set; } public HashSet ListOfSelfAssignableRoles { get; set; } diff --git a/src/NadekoBot/Services/Database/Models/BotConfig.cs b/src/NadekoBot/Services/Database/Models/BotConfig.cs index 6108d16d..b3686b27 100644 --- a/src/NadekoBot/Services/Database/Models/BotConfig.cs +++ b/src/NadekoBot/Services/Database/Models/BotConfig.cs @@ -111,9 +111,6 @@ Nadeko Support Server: https://discord.gg/0ehQwTK2RBjAxzEY"; public string ModuleName { get; set; } public string Prefix { get; set; } - public int BotConfigId { get; set; } = 1; - public BotConfig BotConfig { get; set; } - public override int GetHashCode() { return ModuleName.GetHashCode();