Example #1
0
        private static void StartUpNonInteractive()
        {
            //Check if settingsfile exists, if not unattend mode doesn't make sense
            if (!System.IO.File.Exists(mySettingsFilePath))
            {
                Console.WriteLine("Error. settings.json file not found. Unattend mode doesn't work");
                Console.WriteLine("Location where it is expected: " + mySettingsFilePath);
                Environment.Exit(100);
            }

            //Try to load the Bot-Settings from the file. On error, exit the application and write out the exception message
            try
            {
                ConfigurationSettings = mySettings.ConfigurationSettings.LoadConfigurationSettings(mySettingsFilePath);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while loading settings.json file. Consider reacreating it.");
                Console.WriteLine("Location where it is expected: " + mySettingsFilePath);
                Console.WriteLine(ex.Message);
                Environment.Exit(101);
            }

            //Try to initialize the bot object. On error, write the error to the console and exit.
            try
            {
                bot            = new Telegram.Bot.TelegramBotClient(ConfigurationSettings.TelegramBot.BotId);
                bot.OnMessage += ReceiveMessageNonInteractive;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while initializing bot.");
                Console.WriteLine(ex.Message);
                Environment.Exit(102);
            }

            IShouldRun = true;
            PrintReceiveScreenNonInteractive();
        }
Example #2
0
        private static void StartUpInteractive()
        {
            WriteMessageSlowly("Try to read config from json file");
            Console.WriteLine("");

            if (System.IO.File.Exists(mySettingsFilePath))
            {
                try
                {
                    ConfigurationSettings = mySettings.ConfigurationSettings.LoadConfigurationSettings(mySettingsFilePath);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: " + ex.Message);
                    Console.WriteLine("Will now exit");
                    Console.ReadLine();
                    Environment.Exit(1);
                    throw ex;
                }
            }
            else
            {
                SetupDialog(true);
            }

            try
            {
                bot            = new Telegram.Bot.TelegramBotClient(ConfigurationSettings.TelegramBot.BotId);
                bot.OnMessage += ReceiveMessageInteractive;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                Console.WriteLine("Will now exit");
                Console.ReadLine();
                Environment.Exit(2);
            }
        }
Example #3
0
        private static void SetupDialog(bool permanent)
        {
            Console.Clear();
            string setupMessage = "" +
                                  "**********************************************************************************" + CVars.newLine +
                                  "***********************************    Setup    **********************************" + CVars.newLine +
                                  "**********************************************************************************" + CVars.newLine +
                                  "*                                                                                *" + CVars.newLine;

            Console.Write(setupMessage);
            Console.Write("* Please enter the Token-ID: ");
            string NewBotToken = Console.ReadLine();

            Console.WriteLine("*                                                                                *");
            Console.Write("* Please enter your first administrative ChatId: ");
            string NewFirstAdminChatId = Console.ReadLine();

            Console.WriteLine("*                                                                                *");
            Console.WriteLine("* OK, next we'll setup your cachet instance.                                     *");
            Console.Write("* Enter your Cachet's dns name (no http or https url): ");
            string NewCachetHost = Console.ReadLine();

            Console.WriteLine("*                                                                                *");
            Console.Write("* Your auth-token for Cachet: ");
            string NewCachetToken = Console.ReadLine();

            Console.WriteLine("*                                                                                *");
            Console.Write("* Does your Cachetserver is reachable over https? <Y/n> ");
            ConsoleKeyInfo answer = Console.ReadKey(false);

            while (!(answer.Key == ConsoleKey.Y || answer.Key == ConsoleKey.Enter || answer.Key == ConsoleKey.N))
            {
                Console.Write(CVars.newLine + "* Does your Cachetserver is reachable over https? <Y/n> ");
                answer = Console.ReadKey(false);
            }
            bool useHTTPs = true;

            if (answer.Key == System.ConsoleKey.Y || answer.Key == System.ConsoleKey.Enter)
            {
                useHTTPs = true;
            }
            else
            {
                useHTTPs = false;
            }

            Console.WriteLine("*                                                                                *");
            Console.WriteLine("* Congratulation. Setup completed.                                               *");


            mySettings.BotSettings    NewBotSettings    = new mySettings.BotSettings(NewBotToken, new string[] { NewFirstAdminChatId });
            mySettings.CachetSettings NewCachetSettings = new mySettings.CachetSettings(NewCachetHost, NewCachetToken, useHTTPs);
            ConfigurationSettings = new mySettings.ConfigurationSettings(NewBotSettings, NewCachetSettings);

            if (permanent)
            {
                ConfigurationSettings.SaveSettingsToFile(mySettingsFilePath);
                Console.WriteLine("*                                                                                *");
                Console.WriteLine("* File settings.json saved.                                                      *");
            }
            else
            {
                Console.WriteLine("*                                                                                *");
                Console.WriteLine("* Settings saved.                                                                *");
            }
        }