Example #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                EmptyForm();

                var b = Bot.FromConfig();

                if (b != null)
                {
                    bot = b;
                    Log("[L] Bot loaded from config.");
                }
                else
                {
                    bot = new Bot();
                    l_botConfigNotFound.Visible = true;
                }

                PopulateForm();

                if (bot.CredentialsNotEmpty)
                    StartBot();
                else
                    Log("[x] Bot credentials not valid for automatic start.");

                t_updateRoomTranscript.Tick += t_updateRoomTranscript_Tick;
                t_updateRoomTranscript.Start();
                t_logUpdate.Tick += t_logUpdate_Tick;
                t_logUpdate.Start();
                t_statusStrips.Tick += t_statusStrips_Tick;
                t_statusStrips.Start();
            }
            catch (Exception ex) { Log("[X] Unacceptable!!!\n" + ex); }
        }
Example #2
0
        public static Bot FromConfig()
        {
            var serializedBotConfigPath = Path.Combine(Program.rootdir, serializedBotFileName);
            if (Helper.CreateDirectoryIfItDoesntExist(Program.rootdir) ||
                !File.Exists(serializedBotConfigPath))
            {
                Log("[x] Bot config not found. Bot not loaded. Either find the config or create a new bot.");
                return null;
            }

            Bot bot = null;

            try
            {
                bot = new Bot() { config = JsonConvert.DeserializeObject<BotConfigurationClass>(File.ReadAllText(serializedBotConfigPath)) };
            }
            catch (JsonException jex)
            {
                string error = "[X] Bot.FromBotDir: Failed to deserialize bot config file at \"" + serializedBotConfigPath + "\": \n" + jex;
                Log(error);
                throw new Exception(error);
            }

            return bot;
        }