Ejemplo n.º 1
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);
        }
        public static IHostBuilder RegisterApplicationServices(this IHostBuilder hostBuilder)
        {
            return(hostBuilder.ConfigureServices((context, services) =>
            {
                var connectionString = context.Configuration["ConnectionStrings:AntiHarassmentDatabase"];
                var twitchUsername = context.Configuration["Twitch:Username"];
                var twitchBotOAuth = context.Configuration["Twitch:OAuthToken"];
                var clientId = context.Configuration["Twitch:ClientId"];
                var secret = context.Configuration["Twitch:Secret"];
                var fileStoragePath = context.Configuration["ApplicationSettings:FileStoragePath"];

                var discordToken = context.Configuration["Discord:AuthToken"];
                var discordServerId = ulong.Parse(context.Configuration["Discord:PrometheusServerId"]);
                var discordChannelId = ulong.Parse(context.Configuration["Discord:StatusChannelId"]);

                var timeoutChatLogInMinutes = TimeSpan.FromMinutes(int.Parse(context.Configuration["SuspensionLogSettings:TimeoutChatLogInMinutes"]));
                var banChatLogInMinutes = TimeSpan.FromMinutes(int.Parse(context.Configuration["SuspensionLogSettings:BanChatLogInMinutes"]));
                var minimumDurationForTimeouts = int.Parse(context.Configuration["SuspensionLogSettings:MinimumDurationForTimeoutsInSeconds"]);

                var chatClientSettings = new TwitchClientSettings(twitchUsername, twitchBotOAuth, clientId, secret);
                var suspensionLogSettings = new SuspensionLogSettings(timeoutChatLogInMinutes, banChatLogInMinutes, minimumDurationForTimeouts);

                services.AddSingleton(chatClientSettings);
                services.AddSingleton <IChatClient, TwitchChatClient>();
                services.AddSingleton <IPubSubClient, TwitchPubSubClient>();
                services.AddSingleton <IRuleCheckService, RuleCheckService>();

                services.AddSingleton <IChatlistenerService, ChatlistenerService>();
                services.AddSingleton <IUserNotificationService, UserNotificationService>();
                services.AddSingleton <ISystemBanService, SystemBanService>();
                services.AddSingleton <IChannelRepository, ChannelRepository>(x => new ChannelRepository(connectionString, x.GetRequiredService <ILogger <ChannelRepository> >()));
                services.AddSingleton <ISuspensionRepository, SuspensionRepository>(x => new SuspensionRepository(connectionString, x.GetRequiredService <ILogger <SuspensionRepository> >()));
                services.AddSingleton <IChatRepository, ChatRepository>(x => new ChatRepository(connectionString, x.GetRequiredService <ILogger <ChatRepository> >()));
                services.AddSingleton <ITagRepository, TagRepository>(x => new TagRepository(connectionString, x.GetRequiredService <ILogger <TagRepository> >()));
                services.AddSingleton <IUserRepository, UserRepository>(x => new UserRepository(connectionString, x.GetRequiredService <ILogger <UserRepository> >()));
                services.AddSingleton <IChatterRepository, ChatterRepository>(x => new ChatterRepository(connectionString, x.GetRequiredService <ILogger <ChatterRepository> >()));
                services.AddSingleton <IDeletedMessagesRepository, DeletedMessagesRepository>(x => new DeletedMessagesRepository(connectionString, x.GetRequiredService <ILogger <DeletedMessagesRepository> >()));
                services.AddSingleton <IDataAnalyser, DataAnalyser>(x => new DataAnalyser(fileStoragePath, x.GetRequiredService <ITagRepository>(), x.GetRequiredService <ISuspensionRepository>(), x.GetRequiredService <IDatetimeProvider>(), x.GetRequiredService <ILogger <DataAnalyser> >()));

                services.AddSingleton <IDiscordMessageClient, DiscordMessageClient>();
                services.AddSingleton <IDiscordClientSettings>(new DiscordClientSettings(discordToken, discordServerId, discordChannelId));
                services.AddSingleton <IDiscordNotificationService, DiscordNotificationService>();

                services.AddSingleton <IDatetimeProvider, DatetimeProvider>();

                services.AddSingleton <ISuspensionLogSettings>(suspensionLogSettings);
                services.AddSingleton <ICompositeChatClient, CompositeChatClient>();
                services.AddSingleton <IChatlogService, ChatlogService>();
                services.AddSingleton <ISuspensionLogService, SuspensionLogService>();
                services.AddSingleton <IChannelMonitoringService, ChannelMonitoringService>();
            }));
        }
        public TwitchFollowerService(ITwitchAPI twitchApi, TwitchClientSettings settings)
        {
            _twitchApi = twitchApi;

            _settings = settings;

            _followerService = new FollowerService(twitchApi);

            _followerService.SetChannelByChannelId(settings.TwitchChannelId);

            _followerService.StartService().Wait();

            _followerService.OnNewFollowersDetected += FollowerServiceOnOnNewFollowersDetected;
        }
        public TwitchFollowerService(ITwitchAPI twitchApi, TwitchClientSettings settings)
        {
            _twitchApi = twitchApi;

            _settings = settings;

            _followerService = new FollowerService(twitchApi);

            _followerService.SetChannelsById(new List <string> {
                settings.TwitchChannelId
            });

            _followerService.Start();

            _followerService.OnNewFollowersDetected += FollowerServiceOnOnNewFollowersDetected;
        }
Ejemplo n.º 5
0
        public static BotMain NewBot(TwitchClientSettings clientSettings, EfGenericRepo efGenericRepo)
        {
            var chatClients = new List <IChatClient>
            {
                new ConsoleChatClient(),
                new TwitchChatClient(clientSettings),
            };


            var commandMessages   = efGenericRepo.List(DataItemPolicy <SimpleResponseMessage> .ActiveOnly());
            var commandHandler    = new CommandHandler(chatClients, commandMessages);
            var subscriberHandler = new SubscriberHandler(chatClients);
            var followerHandler   = new FollowerHandler(chatClients);
            var botMain           = new BotMain(chatClients, efGenericRepo, commandHandler, subscriberHandler, followerHandler);

            return(botMain);
        }
Ejemplo n.º 6
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Initializing the Bot...");
            TwitchClientSettings clientSettings = SetUpConfig.InitializeConfiguration();

            DbContextOptions <AppDataContext> options = new DbContextOptionsBuilder <AppDataContext>()
                                                        .UseInMemoryDatabase("fake-data-db")
                                                        .Options;

            var efGenericRepo = new EfGenericRepo(new AppDataContext(options));

            new FakeData(efGenericRepo).Initialize();

            Console.WriteLine("To exit, press [Ctrl]+c");

            BotMain botMain = SetUpBot.NewBot(clientSettings, efGenericRepo);

            botMain.Run();
        }
Ejemplo n.º 7
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .UseWindowsService()
        .ConfigureServices((hostContext, services) =>
        {
            var config         = hostContext.Configuration;
            var botName        = config.GetValue <string>("ChatbotClient:BotUserName");
            var botOAuthToken  = config.GetValue <string>("ChatbotClient:BotOAuthToken");
            var clientSettings = new TwitchClientSettings(botName, botOAuthToken);

            services.AddSingleton <UserJobController, UserJobController>();
            services.AddSingleton <IUserRepository>(new UserRepository(config.GetValue <string>("StreamHealthApiAddress")));
            services.AddSingleton <IDateTimeProvider, DateTimeProvider>();
            services.AddSingleton <IStreamHealthLogger, StreamHealthFileLogger>();
            services.AddSingleton(clientSettings);
            services.AddSingleton <ITwitchIntegration, TwitchChatClient>();
            services.AddSingleton <HealthCheckerMain, HealthCheckerMain>();
            services.AddHostedService <Worker>();
        });
        public static IServiceCollection AddTwitchLibConnection(this IServiceCollection services,
                                                                TwitchClientSettings twitchClientSettings)
        {
            services.AddSingleton <SubscriberHandler>();

            services.AddSingleton <IFollowableSystem, FollowableSystem>();

            services.AddSingleton <IFollowerService, TwitchFollowerService>();

            var api = new TwitchAPI();

            api.Settings.ClientId    = twitchClientSettings.TwitchClientId;
            api.Settings.AccessToken = twitchClientSettings.TwitchChannelOAuth;
            services.AddSingleton <ITwitchAPI>(api);

            services.AddSingleton <IChatClient, TwitchChatClient>();

            services.AddSingleton <IStreamingInfoService, TwitchStreamingInfoService>();

            return(services);
        }
Ejemplo n.º 9
0
        private static async Task InitializeBot()
        {
            Console.WriteLine("Initializing LipheBot...");

            TwitchClientSettings settings = new TwitchClientSettings(
                $"{Configuration["TwitchChatClient:twitchUsername"]}",
                $"{Configuration["TwitchChatClient:twitchOAuth"]}",
                $"{Configuration["TwitchChatClient:twitchChannel"]}");
            List <IChatClient> chatClients = new List <IChatClient>

            {
                new ConsoleChatClient(),
                new TwitchChatClient(settings),
            };

            _lipheBot = new BotMain(chatClients);

            await _lipheBot.Run();

            Console.WriteLine("Bot initialized");
        }
Ejemplo n.º 10
0
 public TwitchModule(TwitchClientSettings twitchClientSettings)
 {
     _twitchClientSettings = twitchClientSettings;
 }