Beispiel #1
0
        // This mode is to run a single Bot until it's terminated.
        private static void BotMode(int botIndex)
        {
            if (!File.Exists("settings.json"))
            {
                Console.WriteLine("No settings.json file found.");
                return;
            }

            Configuration configObject;
            try
            {
                configObject = Configuration.LoadConfiguration("settings.json");
            }
            catch (Newtonsoft.Json.JsonReaderException)
            {
                // handle basic json formatting screwups
                Console.WriteLine("settings.json file is corrupt or improperly formatted.");
                return;
            }

            if (botIndex >= configObject.Bots.Length)
            {
                Console.WriteLine("Invalid bot index.");
                return;
            }

            Bot b = new Bot(configObject.Bots[botIndex], configObject.ApiKey, BotManager.UserHandlerCreator, true, true);
            Console.Title = "Bot Manager";
            b.StartBot();

            string AuthSet = "auth";
            string ExecCommand = "exec";

            // this loop is needed to keep the botmode console alive.
            // instead of just sleeping, this loop will handle console input
            while (true)
            {
                string inputText = Console.ReadLine();

                if (String.IsNullOrEmpty(inputText))
                    continue;

                // Small parse for console input
                var c = inputText.Trim();

                var cs = c.Split(' ');

                if (cs.Length > 1)
                {
                    if (cs[0].Equals(AuthSet, StringComparison.CurrentCultureIgnoreCase))
                    {
                        b.AuthCode = cs[1].Trim();
                    }
                    else if (cs[0].Equals(ExecCommand, StringComparison.CurrentCultureIgnoreCase))
                    {
                        b.HandleBotCommand(c.Remove(0, cs[0].Length + 1));
                    }
                }
            }
        }
            private void SpawnBotThread(Configuration.BotInfo botConfig)
            {
                // the bot object itself is threaded so we just build it and start it.
                Bot b = new Bot(botConfig,
                                config.ApiKey,
                                UserHandlerCreator,
                                true);

                TheBot = b;
                TheBot.StartBot();
            }
Beispiel #3
0
        // This mode is to run a single Bot until it's terminated.
        private static void BotMode(int botIndex)
        {
            if (!File.Exists("settings.json"))
            {
                Console.WriteLine("No settings.json file found.");
                return;
            }

            Configuration configObject;
            try
            {
                configObject = Configuration.LoadConfiguration("settings.json");
            }
            catch (Newtonsoft.Json.JsonReaderException)
            {
                // handle basic json formatting screwups
                Console.WriteLine("settings.json file is currupt or improperly formatted.");
                return;
            }

            if (configObject.Bots.Length > botIndex)
            {
                Bot b = new Bot(configObject.Bots[botIndex], configObject.ApiKey, BotManager.UserHandlerCreator, true, true);
                Console.Title = configObject.Bots[botIndex].DisplayName;
                b.StartBot(); // never returns from this.
            }

            // this loop is needed to keep the botmode console alive.
            // the sleep keeps the cpu usage low.
            while (true)
            {
                System.Threading.Thread.Sleep(1000);
            }
        }
Beispiel #4
0
        // This mode is to run a single Bot until it's terminated.
        private static void BotMode(int botIndex)
        {
            if (!Directory.Exists(BotManager.DATA_FOLDER))
            {
                Directory.CreateDirectory(BotManager.DATA_FOLDER);
            }

            if (!File.Exists(BotManager.DATA_FOLDER + "settings.json"))
            {
                Console.WriteLine("No settings.json file found.");
                if (!File.Exists(BotManager.DATA_FOLDER + "settings-template.json"))
                {
                    File.WriteAllText(BotManager.DATA_FOLDER + "settings-template.json", defSettingsStr);
                }

                return;
            }

            Configuration configObject;

            try
            {
                configObject = Configuration.LoadConfiguration("settings.json");
            }
            catch (Newtonsoft.Json.JsonReaderException)
            {
                // handle basic json formatting screwups
                Console.WriteLine("settings.json file is corrupt or improperly formatted.");
                return;
            }

            if (botIndex >= configObject.Bots.Length)
            {
                Console.WriteLine("Invalid bot index.");
                return;
            }

            Bot b = new Bot(configObject.Bots[botIndex], configObject.ApiKey,
                            (b2, sid) => BotManager.UserHandlerCreator(b2, sid, configObject), true, true);

            Console.Title = "Bot Manager";
            b.StartBot();

            string AuthSet     = "auth";
            string ExecCommand = "exec";
            string ExitCommand = "exit";

            // this loop is needed to keep the botmode console alive.
            // instead of just sleeping, this loop will handle console input
            while (true)
            {
                string inputText = Console.ReadLine();

                if (string.IsNullOrEmpty(inputText))
                {
                    continue;
                }

                // Small parse for console input
                var c = inputText.Trim();

                var cs = c.Split(' ');

                if (cs.Length > 1)
                {
                    if (cs[0].Equals(AuthSet, StringComparison.CurrentCultureIgnoreCase))
                    {
                        b.AuthCode = cs[1].Trim();
                    }
                    else if (cs[0].Equals(ExecCommand, StringComparison.CurrentCultureIgnoreCase))
                    {
                        b.HandleBotCommand(c.Remove(0, cs[0].Length + 1));
                    }
                    else if (cs[0].ToLower() == ExitCommand)
                    {
                        b.StopBot();
                    }
                }
            }
        }
Beispiel #5
0
        // This mode is to run a single Bot until it's terminated.
        private static void BotMode(int botIndex)
        {
            if (!File.Exists("settings.json"))
            {
                Console.WriteLine("No settings.json file found.");
                return;
            }

            Configuration configObject;
            try
            {
                configObject = Configuration.LoadConfiguration("settings.json");
            }
            catch (Newtonsoft.Json.JsonReaderException)
            {
                // handle basic json formatting screwups
                Console.WriteLine("settings.json file is currupt or improperly formatted.");
                return;
            }

            if (configObject.Bots.Length > botIndex)
            {
                Bot b = new Bot(configObject.Bots[botIndex], configObject.ApiKey, BotManager.UserHandlerCreator, true);
                Console.Title = configObject.Bots[botIndex].DisplayName;
                b.StartBot(); // never returns from this.
            }

            while (true)
            {
                // we need this in here so we can keep
                // the console alive so we can read the
                // steamguard code if need be.
            }
        }