Ejemplo n.º 1
0
        public static IContainer NewBotDependencyContainer(BotConfiguration botConfiguration)
        {
            var repository = SetUpDatabase.SetUpRepository(botConfiguration.DatabaseConnectionString);

            var builder = new ContainerBuilder();

            builder.RegisterModule <DevChatterBotCoreModule>();
            builder.RegisterModule <DevChatterBotTwitchModule>();

            builder.Register(ctx => botConfiguration.CommandHandlerSettings).AsSelf().SingleInstance();
            builder.Register(ctx => botConfiguration.TwitchClientSettings).AsSelf().SingleInstance();

            builder.Register(ctx => repository)
            .As <IRepository>().SingleInstance();


            var simpleCommands = repository.List <SimpleCommand>();

            foreach (var command in simpleCommands)
            {
                builder.Register(ctx => command)
                .AsImplementedInterfaces()
                .SingleInstance();
            }

            var container = builder.Build();

            WireUpAliasNotifications(container);

            return(container);
        }
Ejemplo n.º 2
0
        public static BotMain NewBot(TwitchClientSettings twitchSettings, string connectionString)
        {
            var twitchApi        = new TwitchAPI(twitchSettings.TwitchClientId);
            var twitchChatClient = new TwitchChatClient(twitchSettings, twitchApi);
            var chatClients      = new List <IChatClient>
            {
                new ConsoleChatClient(),
                twitchChatClient,
            };
            var twitchFollowerService = new TwitchFollowerService(twitchApi, twitchSettings);

            IRepository repository = SetUpDatabase.SetUpRepository(connectionString);

            var chatUserCollection = new ChatUserCollection(repository);
            var currencyGenerator  = new CurrencyGenerator(chatClients, chatUserCollection);
            var currencyUpdate     = new CurrencyUpdate(1, currencyGenerator);

            var automatedActionSystem = new AutomatedActionSystem(new List <IIntervalAction> {
                currencyUpdate
            });
            var rockPaperScissorsGame = new RockPaperScissorsGame(currencyGenerator, automatedActionSystem);
            var wordList = new List <string> {
                "apple", "banana", "orange", "mango", "watermellon", "grapes", "pizza", "pasta", "pepperoni", "cheese", "mushroom", "csharp", "javascript", "cplusplus", "nullreferenceexception", "parameter", "argument"
            };
            var hangmanGame = new HangmanGame(currencyGenerator, automatedActionSystem, wordList);

            var simpleCommands = repository.List <SimpleCommand>();

            List <IBotCommand> allCommands = new List <IBotCommand>();

            allCommands.AddRange(simpleCommands);
            allCommands.Add(new GiveCommand(chatUserCollection));
            allCommands.Add(new HelpCommand(allCommands));
            allCommands.Add(new CommandsCommand(allCommands));
            allCommands.Add(new CoinsCommand(repository));
            allCommands.Add(new BonusCommand(currencyGenerator));
            allCommands.Add(new StreamsCommand(repository));
            allCommands.Add(new ShoutOutCommand(twitchFollowerService));
            allCommands.Add(new QuoteCommand(repository));
            allCommands.Add(new AddQuoteCommand(repository));
            allCommands.Add(new AddCommandCommand(repository, allCommands));
            allCommands.Add(new RemoveCommandCommand(repository, allCommands));
            allCommands.Add(new HangmanCommand(hangmanGame));
            allCommands.Add(new RockPaperScissorsCommand(rockPaperScissorsGame));

            var commandHandler    = new CommandHandler(chatClients, allCommands);
            var subscriberHandler = new SubscriberHandler(chatClients);

            var twitchSystem = new FollowableSystem(new[] { twitchChatClient }, twitchFollowerService);


            var botMain = new BotMain(chatClients, repository, commandHandler, subscriberHandler, twitchSystem, automatedActionSystem);

            return(botMain);
        }
Ejemplo n.º 3
0
        public static IContainer NewBotDepedencyContainer(BotConfiguration botConfiguration)
        {
            var repository = SetUpDatabase.SetUpRepository(botConfiguration.DatabaseConnectionString);

            var builder = new ContainerBuilder();

            builder.Register(ctx => botConfiguration.CommandHandlerSettings).AsSelf().SingleInstance();
            builder.Register(ctx => botConfiguration.TwitchClientSettings).AsSelf().SingleInstance();

            builder.RegisterType <TwitchFollowerService>().AsImplementedInterfaces().SingleInstance();
            builder.Register(ctx => new TwitchAPI(botConfiguration.TwitchClientSettings.TwitchClientId))
            .AsImplementedInterfaces();
            builder.RegisterType <TwitchChatClient>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <StreamingPlatform>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <TwitchStreamingInfoService>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <SystemClock>().AsImplementedInterfaces().SingleInstance();

            builder.RegisterType <ConsoleChatClient>().AsImplementedInterfaces().SingleInstance();

            builder.Register(ctx => repository).As <IRepository>().SingleInstance();

            builder.RegisterType <ChatUserCollection>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <CurrencyGenerator>().AsImplementedInterfaces().SingleInstance();
            builder.Register(ctx => new CurrencyUpdate(1, ctx.Resolve <ICurrencyGenerator>(), ctx.Resolve <IClock>()))
            .AsImplementedInterfaces()
            .SingleInstance();

            builder.RegisterType <AutomatedActionSystem>().AsImplementedInterfaces().SingleInstance();

            builder.RegisterType <RockPaperScissorsGame>().AsSelf().SingleInstance();
            builder.RegisterType <RockPaperScissorsCommand>().AsImplementedInterfaces().SingleInstance();

            builder.RegisterType <HangmanGame>().AsSelf().SingleInstance();
            builder.RegisterType <HardcodedWordListProvider>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <HangmanCommand>().AsImplementedInterfaces().SingleInstance();

            builder.RegisterType <UptimeCommand>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <GiveCommand>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <CoinsCommand>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <BonusCommand>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <StreamsCommand>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <ShoutOutCommand>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <QuoteCommand>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <AliasCommand>().AsImplementedInterfaces().SingleInstance();

            builder.Register(ctx => new HelpCommand(ctx.Resolve <IRepository>()))
            .OnActivated(e => e.Instance.AllCommands = e.Context.Resolve <CommandList>())
            .AsImplementedInterfaces();
            builder.Register(ctx => new CommandsCommand(ctx.Resolve <IRepository>()))
            .OnActivated(e => e.Instance.AllCommands = e.Context.Resolve <CommandList>())
            .AsImplementedInterfaces();

            var simpleCommands = repository.List <SimpleCommand>();

            foreach (var command in simpleCommands)
            {
                builder.Register(ctx => command).AsImplementedInterfaces().SingleInstance();
            }

            builder.Register(ctx => new CommandList(ctx.Resolve <IList <IBotCommand> >()))
            .AsSelf()
            .SingleInstance();

            builder.RegisterType <CommandUsageTracker>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <CommandHandler>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <SubscriberHandler>().AsSelf().SingleInstance();
            builder.RegisterType <FollowableSystem>().AsImplementedInterfaces().SingleInstance();

            builder.RegisterType <BotMain>().AsImplementedInterfaces().SingleInstance();

            var container = builder.Build();

            WireUpAliasNotifications(container);

            return(container);
        }