Пример #1
0
        public BotInfo CreateBot(/*Ts3FullClientData bot*/)
        {
            bool removeBot = false;
            var  bot       = new Bot {
                Injector = CoreInjector.CloneRealm <BotInjector>()
            };

            if (!CoreInjector.TryInject(bot))
            {
                Log.Warn("Partial bot dependency loaded only");
            }

            lock (bot.SyncRoot)
            {
                if (bot.InitializeBot())
                {
                    lock (lockObj)
                    {
                        activeBots.Add(bot);
                        bot.Id    = activeBots.Count - 1;
                        removeBot = !isRunning;
                    }
                }

                if (removeBot)
                {
                    StopBot(bot);
                    return(null);
                }
            }
            return(bot.GetInfo());
        }
Пример #2
0
        public R <BotInfo, string> RunBot(ConfBot config, string name = null)
        {
            var bot = new Bot(config)
            {
                Injector = CoreInjector.CloneRealm <BotInjector>(), Name = name
            };

            if (!CoreInjector.TryInject(bot))
            {
                Log.Warn("Partial bot dependency loaded only");
            }

            lock (bot.SyncRoot)
            {
                var initializeResult = bot.InitializeBot();
                var removeBot        = false;
                if (initializeResult.Ok)
                {
                    lock (lockObj)
                    {
                        if (!InsertIntoFreeId(bot))
                        {
                            removeBot = true;
                        }
                    }
                }
                else
                {
                    return($"Bot failed to connect ({initializeResult.Error})");
                }

                if (removeBot)
                {
                    StopBot(bot);
                    return("BotManager is shutting down");
                }
            }
            return(bot.GetInfo());
        }