コード例 #1
0
        public void Execute()
        {
            var logger = LogManager.GetLogger(nameof(SampleDataExecutable));

            logger.Info("Welcome to Bot!");
            logger.Info("Initializing...");

            var container = new TestContainerManager(
                configureSettings: s => s.ClientType = nameof(SampleDataExecutable)
                ).InitializeAndIsolateRepository();
            var factory            = container.GetInstance <ReceivedFactory>();
            var pipelineManager    = container.GetInstance <IPipelineManager>();
            var periodicTaskRunner = container.GetInstance <PeriodicTaskRunner>();

            logger.Info("Initialization complete.");
            logger.Info("Running...\r\n\r\n");

            var data = new List <IReceived <IUser, ITransmittable> > {
                factory.ModPublicReceivedMessage("!long"),
                factory.PublicReceivedMessage("hi"),
                factory.PublicReceivedMessage("banplox"),
                factory.PublicReceivedMessage("!time"),
                factory.ModPublicReceivedMessage("!sing"),
                factory.ModPublicReceivedMessage("!long"),
            };

            data.ForEach(x => {
                Task.Delay(100).Wait();
                pipelineManager.Enqueue(x);
            });
            periodicTaskRunner.Run();
        }
コード例 #2
0
        public void Execute()
        {
            var logger = LogManager.GetLogger(nameof(ContinuousExecutable));

            logger.Info("Welcome to Bot!");
            logger.Info("Initializing...");

            var container = new TestContainerManager(c => {
                if (_isDestinyGg)
                {
                    if (_canSend)
                    {
                        c.RegisterConditional(typeof(IClient), typeof(DestinyGgSendingClient), Lifestyle.Singleton, pc => !pc.Handled);
                    }
                }
                else
                {
                    c.RegisterConditional(typeof(IFactory <IEnumerable <ISendable <ITransmittable> >, IEnumerable <string> >), typeof(TwitchSerializer), Lifestyle.Singleton, pc => !pc.Handled);
                    if (_canSend)
                    {
                        c.RegisterConditional(typeof(IClient), typeof(TwitchSendingClient), Lifestyle.Singleton, pc => !pc.Handled);
                    }
                    else
                    {
                        c.RegisterConditional(typeof(IClient), typeof(TwitchLoggingClient), Lifestyle.Singleton, pc => !pc.Handled);
                    }
                }
            }, s => {
                s.SqlitePath = "Bot.sqlite";
                s.ClientType = _isDestinyGg ? "DestinyGg" : "Twitch";
            }).Container;

            var pipelineManager    = container.GetInstance <IPipelineManager>();
            var periodicTaskRunner = container.GetInstance <PeriodicTaskRunner>();
            var client             = container.GetInstance <IClient>();
            var twitterManager     = container.GetInstance <ITwitterManager>();

            logger.Info("Initialization complete.");
            logger.Info("Running...\r\n\r\n");

            client.TryConnect();
            periodicTaskRunner.Run();
            if (_runTwitter)
            {
                twitterManager.MonitorNewTweets(pipelineManager.Enqueue);
            }

            var r = container.GetInstance <ReceivedFactory>();

            while (true)
            {
                var line    = Console.ReadLine();
                var message = line.StartsWith("~")
          ? (IReceived <User, ITransmittable>)r.PublicReceivedMessage(line.Substring(1))
          : (IReceived <User, ITransmittable>)r.ModPublicReceivedMessage(line);

                pipelineManager.Enqueue(message);
            }
        }