Beispiel #1
0
            private void MigrateConfig0_9(IUnitOfWork uow, BotConfig botConfig)
            {
                Config0_9 oldConfig;
                const string configPath = "data/config.json";
                try
                {
                    oldConfig = JsonConvert.DeserializeObject<Config0_9>(File.ReadAllText(configPath));
                }
                catch (FileNotFoundException)
                {
                    _log.Warn("config.json not found");
                    return;
                }
                catch (Exception)
                {
                    _log.Error("Unknown error while deserializing file config.json, pls check its integrity, aborting migration");
                    throw new MigrationException();
                }

                //Basic
                botConfig.ForwardMessages = oldConfig.ForwardMessages;
                botConfig.ForwardToAllOwners = oldConfig.ForwardToAllOwners;
                botConfig.BufferSize = (ulong)oldConfig.BufferSize;
                botConfig.RemindMessageFormat = oldConfig.RemindMessageFormat;
                botConfig.CurrencySign = oldConfig.CurrencySign;
                botConfig.CurrencyName = oldConfig.CurrencyName;
                botConfig.DMHelpString = oldConfig.DMHelpString;
                botConfig.HelpString = oldConfig.HelpString;

                //messages
                botConfig.RotatingStatuses = oldConfig.IsRotatingStatus;
                var messages = new List<PlayingStatus>();

                oldConfig.RotatingStatuses.ForEach(i => messages.Add(new PlayingStatus { Status = i }));
                botConfig.RotatingStatusMessages = messages;

                //Prefix
                botConfig.ModulePrefixes.Clear();
                botConfig.ModulePrefixes.AddRange(new HashSet<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}
                });

                //Blacklist
                var blacklist = new HashSet<BlacklistItem>(oldConfig.ServerBlacklist.Select(server => new BlacklistItem() { ItemId = server, Type = BlacklistItem.BlacklistType.Server }));
                blacklist.AddRange(oldConfig.ChannelBlacklist.Select(channel => new BlacklistItem() { ItemId = channel, Type = BlacklistItem.BlacklistType.Channel }));
                blacklist.AddRange(oldConfig.UserBlacklist.Select(user => new BlacklistItem() { ItemId = user, Type = BlacklistItem.BlacklistType.User }));
                botConfig.Blacklist = blacklist;

                //Eightball
                botConfig.EightBallResponses = new HashSet<EightBallResponse>(oldConfig._8BallResponses.Select(response => new EightBallResponse() { Text = response }));

                //customreactions
                uow.CustomReactions.AddRange(oldConfig.CustomReactions.SelectMany(cr =>
                {
                    return cr.Value.Select(res => new CustomReaction()
                    {
                        GuildId = null,
                        IsRegex = false,
                        OwnerOnly = false,
                        Response = res,
                        Trigger = cr.Key.ToLowerInvariant(),
                    });
                }).ToArray());

                try { File.Move(configPath, "./data/DELETE_ME_config.json"); } catch { }
            }
        //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        //{
        //    optionsBuilder.UseSqlite("Filename=./data/NadekoBot.db");
        //}
        public void EnsureSeedData()
        {
            if (!BotConfig.Any())
            {
                var bc = new BotConfig();

                bc.ModulePrefixes.AddRange(new HashSet<ModulePrefix>()
                {
                    new ModulePrefix() { ModuleName = "Administration", Prefix = "." },
                    new ModulePrefix() { ModuleName = "Searches", Prefix = "~" },
                    new ModulePrefix() { ModuleName = "Translator", Prefix = "~" },
                    new ModulePrefix() { ModuleName = "NSFW", Prefix = "~" },
                    new ModulePrefix() { ModuleName = "ClashOfClans", Prefix = "," },
                    new ModulePrefix() { ModuleName = "Help", Prefix = "-" },
                    new ModulePrefix() { ModuleName = "Music", Prefix = "!!" },
                    new ModulePrefix() { ModuleName = "Trello", Prefix = "trello" },
                    new ModulePrefix() { ModuleName = "Games", Prefix = ">" },
                    new ModulePrefix() { ModuleName = "Gambling", Prefix = "$" },
                    new ModulePrefix() { ModuleName = "Permissions", Prefix = ";" },
                    new ModulePrefix() { ModuleName = "Pokemon", Prefix = ">" },
                    new ModulePrefix() { ModuleName = "Utility", Prefix = "." },
                    new ModulePrefix() { ModuleName = "CustomReactions", Prefix = "." }
                });
                bc.RaceAnimals.AddRange(new HashSet<RaceAnimal>
                {
                    new RaceAnimal { Icon = "🐼", Name = "Panda" },
                    new RaceAnimal { Icon = "🐻", Name = "Bear" },
                    new RaceAnimal { Icon = "🐧", Name = "Pengu" },
                    new RaceAnimal { Icon = "🐨", Name = "Koala" },
                    new RaceAnimal { Icon = "🐬", Name = "Dolphin" },
                    new RaceAnimal { Icon = "🐞", Name = "Ladybird" },
                    new RaceAnimal { Icon = "🦀", Name = "Crab" },
                    new RaceAnimal { Icon = "🦄", Name = "Unicorn" }
                });
                bc.EightBallResponses.AddRange(new HashSet<EightBallResponse>
                {
                    new EightBallResponse() { Text = "Most definitely yes" },
                    new EightBallResponse() { Text = "For sure" },
                    new EightBallResponse() { Text = "Totally!" },
                    new EightBallResponse() { Text = "Of course!" },
                    new EightBallResponse() { Text = "As I see it, yes" },
                    new EightBallResponse() { Text = "My sources say yes" },
                    new EightBallResponse() { Text = "Yes" },
                    new EightBallResponse() { Text = "Most likely" },
                    new EightBallResponse() { Text = "Perhaps" },
                    new EightBallResponse() { Text = "Maybe" },
                    new EightBallResponse() { Text = "Not sure" },
                    new EightBallResponse() { Text = "It is uncertain" },
                    new EightBallResponse() { Text = "Ask me again later" },
                    new EightBallResponse() { Text = "Don't count on it" },
                    new EightBallResponse() { Text = "Probably not" },
                    new EightBallResponse() { Text = "Very doubtful" },
                    new EightBallResponse() { Text = "Most likely no" },
                    new EightBallResponse() { Text = "Nope" },
                    new EightBallResponse() { Text = "No" },
                    new EightBallResponse() { Text = "My sources say no" },
                    new EightBallResponse() { Text = "Dont even think about it" },
                    new EightBallResponse() { Text = "Definitely no" },
                    new EightBallResponse() { Text = "NO - It may cause disease contraction" }
                });

                BotConfig.Add(bc);

                this.SaveChanges();
            }
        }