Esempio n. 1
0
        public TwitchPubSubService(
            TwitchAPI twitchApiClient,
            IOptions <TwitchConfig> config,
            ILoggerFactory loggerFactory)
        {
            _logger      = loggerFactory.CreateLogger <TwitchPubSubService>();
            _config      = config.Value;
            PubSubClient = new TwitchPubSub();
            var user = twitchApiClient.Helix.Users.GetUsersAsync(logins: new List <string> {
                "vic10usx"
            }).Result.Users.First();

            PubSubClient.OnPubSubServiceConnected += OnPubSubServiceConnected;
            PubSubClient.ListenToRewards(user.Id);
            // PubSubClient.ListenToChannelPoints(user.Id);
            PubSubClient.OnPubSubServiceClosed += (sender, args) =>
            {
                _logger.LogWarning("The service has closed it's connection... :(", args);
            };
            PubSubClient.OnPubSubServiceError += (sender, args) =>
            {
                _logger.LogError("The service encountered a critical error... :(", args);
            };
            PubSubClient.OnChannelSubscription += (sender, args) =>
            {
            };

            PubSubClient.Connect();
        }
 public TwitchClientServices(IOptions <TwitchConfig> settings,
                             IHttpClientFactory httpClientFactory,
                             ILoggerFactory loggerFactory)
 {
     _httpClientFactory = httpClientFactory;
     _logger            = loggerFactory.CreateLogger <TwitchClientServices>();
     _config            = settings.Value !;
 }
Esempio n. 3
0
        public TwitchBot(
            IOptions <TwitchConfig> config,
            IOptions <OBSConfig> obsConfig,
            ILogger <TwitchBot> logger,
            HubConnection hubConnection,
            HtmlSanitizer sanitizer,
            TwitchMemoryCache twitchMemoryCache,
            TwitchAPI twitchApi,
            IMapper mapper,
            OBSWebsocket obs,
            WLEDService wledService)
        {
            _config        = config.Value ?? throw new MissingConfigException();
            _hubConnection = hubConnection;
            _hubConnection.StartAsync();
            _logger      = logger;
            _sanitizer   = sanitizer;
            _mapper      = mapper;
            _cache       = twitchMemoryCache.Cache;
            _obs         = obs;
            _obsConfig   = obsConfig.Value;
            _wledService = wledService;

            var credentials = new ConnectionCredentials(
                _config.Chat.BotName,
                _config.Chat.PasswordGeneratorToken);

            var clientOptions = new ClientOptions
            {
                MessagesAllowedInPeriod = 750,
                ThrottlingPeriod        = TimeSpan.FromSeconds(30)
            };

            _twitchApiClient = twitchApi;

            var customClient = new WebSocketClient(clientOptions);

            _client = new TwitchClient(customClient);
            _client.Initialize(credentials, _config.Chat.Channel);

            _client.OnConnected           += ClientOnConnected;
            _client.OnJoinedChannel       += ClientOnJoinedChannel;
            _client.OnChatCommandReceived += ClientOnChatCommandReceived;
            _client.OnMessageReceived     += ClientOnMessageReceived;

            _client.Connect();

            SetupOBS();
        }