當前位置: 首頁>>代碼示例>>C#>>正文


C# Bot.StopBot方法代碼示例

本文整理匯總了C#中SteamBot.Bot.StopBot方法的典型用法代碼示例。如果您正苦於以下問題:C# Bot.StopBot方法的具體用法?C# Bot.StopBot怎麽用?C# Bot.StopBot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SteamBot.Bot的用法示例。


在下文中一共展示了Bot.StopBot方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: BotMode

        // 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();
                    }
                }
            }
        }
開發者ID:einsteinsci,項目名稱:SteamBot,代碼行數:77,代碼來源:Program.cs


注:本文中的SteamBot.Bot.StopBot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。