Exemple #1
0
        private static async void StartBot(string[] args) // Startup Method.
        {
            // Print Application Information to Console.
            Console.Write($@"{DateTime.Now,-19} DiscordBot: [");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write(@"Version " + ProgramVersion.Major + @"." + ProgramVersion.Minor + @"." +
                          ProgramVersion.Build + @"." + ProgramVersion.Revision);
            Console.ResetColor();
            Console.WriteLine(@"]    ");

            // Print Developer Information to Console.
            Console.Write($@"{DateTime.Now,-19} DiscordBot: Developed by Melissa Brennan (");
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.Write(@"@MythicalCuddles");
            Console.ResetColor();
            Console.WriteLine(@")");

            // Print Additional Information to the Console.
            Console.WriteLine($@"{DateTime.Now,-19} DiscordBot: Web: www.mythicalcuddles.xyz");
            Console.WriteLine($@"{DateTime.Now,-19} DiscordBot: Copyright 2017 - 2019 Melissa Brennan | Licensed under the MIT License.");

            Methods.PrintConsoleSplitLine();

            // Run the Initializer for MelissaNET.
            MelissaNet.MelissaNet.Initialize();

            Methods.PrintConsoleSplitLine();

            // Check for Updates using MelissaNet.
            CheckForUpdates();

            // Check if application configurations exist.
            Configuration.EnsureExists();
            StringConfiguration.EnsureExists();

            // Verify Settings
            bool invalidToken = false, invalidDbSettings = false;

            if (!Configuration.Load().FirstTimeRun)
            {
                Methods.PrintConsoleSplitLine();

                invalidToken      = !Methods.VerifyBotToken().GetAwaiter().GetResult();
                invalidDbSettings = !DatabaseActivity.TestDatabaseSettings().GetAwaiter().GetResult().connectionValid;
            }

            Methods.PrintConsoleSplitLine();

            // Check & Run the configurator form if the configuration has not been setup or the -config arg has been passed.
            var configArg = args.Contains("-CONFIG");

            await new LogMessage(LogSeverity.Debug, "Configurator",
                                 "Checking if the Configurator needs to run...").PrintToConsole();
            await new LogMessage(LogSeverity.Debug, "Configurator",
                                 "configArg: " + configArg.ToYesNo()).PrintToConsole();
            await new LogMessage(LogSeverity.Debug, "Configurator",
                                 "FirstTimeRun: " + Configuration.Load().FirstTimeRun.ToYesNo()).PrintToConsole();
            await new LogMessage(LogSeverity.Debug, "Configurator",
                                 "invalidToken: " + invalidToken.ToYesNo()).PrintToConsole();
            await new LogMessage(LogSeverity.Debug, "Configurator",
                                 "invalidDbSettings: " + invalidDbSettings.ToYesNo()).PrintToConsole();
            FrmConfigure.CheckRunConfigurator(configArg || Configuration.Load().FirstTimeRun || invalidToken || invalidDbSettings);

            Methods.PrintConsoleSplitLine();

            // Check to see if the database and tables exist.
            DatabaseActivity.EnsureExists();

            // Start the bot.
            DiscordBot.RunBotAsync().GetAwaiter().GetResult();
        }
Exemple #2
0
        public static void StartBot()
        {
            Console.Write(@"DiscordBot: [");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write(@"Version " + ProgramVersion.Major + @"." + ProgramVersion.Minor + @"." + ProgramVersion.Build + @"." + ProgramVersion.Revision);
            Console.ResetColor();
            Console.WriteLine(@"]    ");

            Console.Write(@"Developed by Melissa Brennan (");
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.Write(@"@MythicalCuddles");
            Console.ResetColor();
            Console.WriteLine(@")");

            Console.WriteLine(@"Web: www.mythicalcuddles.xyz");

            Console.WriteLine(@"Copyright 2017 - 2019 Melissa Brennan | Licensed under the MIT License.");
            Console.WriteLine(@"-----------------------------------------------------------------");

            MelissaNet.MelissaNet.Initialize();

            /*    Update Checker via MythicalCore    */
            try
            {
                var updateCheck = Updater.CheckForUpdate("DiscordBot", ProgramVersion);
                if (updateCheck.Item1)
                {
                    Console.WriteLine(@"-----------------------------------------------------------------");
                    LogMessage lm = new LogMessage(LogSeverity.Info, "MythicalCore",
                                                   "A new update has been found. Would you like to download?");
                    lm.PrintToConsole();
                    Console.WriteLine(@"-----------------------------------------------------------------");

                    DialogResult result = MessageBox.Show("A new update is available. Would you like to update?",
                                                          "DiscordBot Update Available", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                    if (result == DialogResult.Yes)
                    {
                        System.Diagnostics.Process.Start(updateCheck.Item2);
                        Environment.Exit(0);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(@"-----------------------------------------------------------------");
                LogMessage lm = new LogMessage(LogSeverity.Error, "MythicalCore",
                                               "Unable to check for new updates.");
                lm.PrintToConsole();
                Console.WriteLine(@"-----------------------------------------------------------------");
            }
            /*    Update End    */

            Configuration.EnsureExists();
            StringConfiguration.EnsureExists();
            QuoteHandler.EnsureExists();
            VoteLinkHandler.EnsureExists();

            try
            {
                DatabaseActivity.CheckForDatabase();
            }
            catch (Exception e)
            {
                LogMessage lm = new LogMessage(LogSeverity.Critical, "MySQL Database", "Unable to connect to database. Is it currently running?", e);
                lm.PrintToConsole();
                Environment.Exit(0);
            }


            Console.WriteLine(@"-----------------------------------------------------------------");

            new DiscordBot().RunBotAsync().GetAwaiter().GetResult();
        }