Ejemplo n.º 1
0
        private static void AddOldBotSettingsToNewDB(TRBotDataMigrationTool.Settings oldBotSettings)
        {
            /* Client Settings */
            Console.WriteLine("Beginning import of various bot settings...");

            AddSettingIntHelper(SettingsConstants.CLIENT_SERVICE_TYPE, (long)oldBotSettings.ClientSettings.ClientType);

            /* Message Settings */
            //The original periodic message time is in minutes, so convert it to milliseconds
            AddSettingIntHelper(SettingsConstants.PERIODIC_MSG_TIME, oldBotSettings.MsgSettings.MessageTime * 60L * 1000L);
            AddSettingIntHelper(SettingsConstants.MESSAGE_COOLDOWN, (long)oldBotSettings.MsgSettings.MessageCooldown);
            AddSettingStrHelper(SettingsConstants.CONNECT_MESSAGE, oldBotSettings.MsgSettings.ConnectMessage);
            AddSettingStrHelper(SettingsConstants.RECONNECTED_MESSAGE, oldBotSettings.MsgSettings.ReconnectedMsg);
            AddSettingStrHelper(SettingsConstants.PERIODIC_MESSAGE, oldBotSettings.MsgSettings.PeriodicMessage);
            AddSettingStrHelper(SettingsConstants.AUTOPROMOTE_MESSAGE, oldBotSettings.MsgSettings.AutoWhitelistMsg);
            AddSettingStrHelper(SettingsConstants.NEW_USER_MESSAGE, oldBotSettings.MsgSettings.NewUserMsg);
            AddSettingStrHelper(SettingsConstants.BEING_HOSTED_MESSAGE, oldBotSettings.MsgSettings.BeingHostedMsg);
            AddSettingStrHelper(SettingsConstants.NEW_SUBSCRIBER_MESSAGE, oldBotSettings.MsgSettings.NewSubscriberMsg);
            AddSettingStrHelper(SettingsConstants.RESUBSCRIBER_MESSAGE, oldBotSettings.MsgSettings.ReSubscriberMsg);

            /* Bingo Settings */
            AddSettingIntHelper(SettingsConstants.BINGO_ENABLED, (oldBotSettings.BingoSettings.UseBingo == true) ? 1L : 0L);
            AddSettingIntHelper(SettingsConstants.BINGO_PIPE_PATH_IS_RELATIVE, 0L);
            AddSettingStrHelper(SettingsConstants.BINGO_PIPE_PATH, oldBotSettings.BingoSettings.BingoPipeFilePath);

            /* Credits Settings */
            //The original credits time is in minutes, so convert it to milliseconds
            AddSettingIntHelper(SettingsConstants.CREDITS_GIVE_TIME, (long)oldBotSettings.CreditsTime * 60L * 1000L);
            AddSettingIntHelper(SettingsConstants.CREDITS_GIVE_AMOUNT, oldBotSettings.CreditsAmount);
            AddSettingIntHelper(SettingsConstants.BOT_MSG_CHAR_LIMIT, oldBotSettings.BotMessageCharLimit);
            AddSettingIntHelper(SettingsConstants.MAIN_THREAD_SLEEP, oldBotSettings.MainThreadSleep);

            /* Autopromote Settings */
            AddSettingIntHelper(SettingsConstants.AUTO_PROMOTE_ENABLED, (oldBotSettings.AutoWhitelistEnabled == true) ? 1L : 0L);
            AddSettingIntHelper(SettingsConstants.AUTO_PROMOTE_INPUT_REQ, oldBotSettings.AutoWhitelistInputCount);

            /* Chatbot Settings */
            AddSettingIntHelper(SettingsConstants.CHATBOT_ENABLED, (oldBotSettings.UseChatBot == true) ? 1L : 0L);
            AddSettingIntHelper(SettingsConstants.CHATBOT_SOCKET_PATH_IS_RELATIVE, 1L);
            AddSettingStrHelper(SettingsConstants.CHATBOT_SOCKET_PATH, oldBotSettings.ChatBotSocketFilename);

            Console.WriteLine("Finished importing all bot settings!");
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //Use invariant culture
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

            Console.WriteLine($"Welcome to the TRBot 1.8 to 2.0+ data migration tool! This is currently running TRBot version {Application.VERSION_NUMBER}.\n");
            Console.WriteLine();
            Console.WriteLine("Keep in mind that the 2.0+ releases have a vastly different data structure, so some data may not be able to be migrated.\nPress any key to continue.\n");
            Console.ReadKey();

            Console.WriteLine($"The first thing we are going to do is create a template database file for your new 2.0+ data. You can also provide an existing \"{DataConstants.DATABASE_FILE_NAME}\" data file in this application's \"{DataConstants.DATA_FOLDER_NAME}\" folder to migrate the data to. HOWEVER, keep in mind that doing so WILL OVERWRITE EXISTING DATA! Please be careful.\nPress any key to continue.\n");
            Console.ReadKey();

            Console.WriteLine("Initializing the template file now...");

            //Make template
            MakeTemplateDatabaseFile();

            Console.WriteLine("Template file created and/or validated!");
            Console.WriteLine(OldBotDataFileMessage);
            Console.WriteLine();

            bool fileExists  = false;
            bool skippedData = false;

            //Bot data
            do
            {
                string line = Console.ReadLine();

                //Skip if we hit the skip argument
                if (line == SKIP_ARG)
                {
                    skippedData = true;
                    break;
                }

                fileExists = File.Exists(line);
                if (fileExists == false)
                {
                    Console.WriteLine($"Sorry, I can't find the file specified.\n{OldBotDataFileMessage}");
                    Console.WriteLine();
                    continue;
                }

                string botDataStr = string.Empty;

                //Try to read the file and put it in the database
                try
                {
                    botDataStr = File.ReadAllText(line);
                    BotData botData = JsonConvert.DeserializeObject <BotData>(botDataStr);

                    //Convert all the bot data
                    AddOldBotDataToNewDB(botData);
                }
                catch (Exception e)
                {
                    fileExists = false;
                    Console.WriteLine($"Sorry, I was unable to read data from the given file for the following reason: {e.Message}\n{e.StackTrace}\n\n{OldBotDataFileMessage}");
                    continue;
                }
            }while (fileExists == false);

            //Reset flag
            fileExists = false;
            bool skippedSettings = false;

            Console.WriteLine(OldSettingsFileMessage);
            Console.WriteLine();

            //Bot settings
            do
            {
                string line = Console.ReadLine();

                //Skip if we hit the skip argument
                if (line == SKIP_ARG)
                {
                    skippedSettings = true;
                    break;
                }

                fileExists = File.Exists(line);
                if (fileExists == false)
                {
                    Console.WriteLine($"Sorry, I can't find the file specified.\n{OldSettingsFileMessage}");
                    Console.WriteLine();
                    continue;
                }

                string settingsDataStr = string.Empty;

                //Try to read the file and put it in the database
                try
                {
                    settingsDataStr = File.ReadAllText(line);
                    TRBotDataMigrationTool.Settings botSettings = JsonConvert.DeserializeObject <TRBotDataMigrationTool.Settings>(settingsDataStr);

                    //Convert all the settings data
                    AddOldBotSettingsToNewDB(botSettings);
                }
                catch (Exception e)
                {
                    fileExists = false;
                    Console.WriteLine($"Sorry, I was unable to read data from the given file for the following reason: {e.Message}\n{e.StackTrace}\n\n{OldSettingsFileMessage}");
                    continue;
                }
            }while (fileExists == false);

            if (skippedData == false || skippedSettings == false)
            {
                Console.WriteLine("All bot data and settings have been imported! Don't forget to double check the data and make sure it's fine!");
            }

            Console.WriteLine("\nPress any key to exit...\n");
            Console.ReadKey();
        }