Beispiel #1
0
        private async void CheckViews(object state)
        {
            var          api      = new TwitchLib.TwitchAPI(clientId: ClientId);
            var          v5Stream = new TwitchLib.Streams.V5(api);
            StreamByUser myStream = null;

            try
            {
                myStream = await v5Stream.GetStreamByUserAsync(ChannelId);
            }
            catch (JsonReaderException ex)
            {
                Logger.LogError($"Unable to read stream from Twitch: {ex}");
                return;
            }

            if (_CurrentViewerCount != (myStream.Stream?.Viewers ?? 0))
            {
                _CurrentViewerCount = (myStream.Stream?.Viewers ?? 0);
                Updated?.Invoke(null, new ServiceUpdatedEventArgs
                {
                    ServiceName = Name,
                    NewViewers  = _CurrentViewerCount
                });
            }
        }
        public async Task OnGet()
        {
            var sw = Stopwatch.StartNew();

            Uptime = await TwitchProxy.Uptime();

            this.Logger.LogInformation($"Get uptime took {sw.ElapsedMilliseconds}ms");

            sw.Restart();
            var api      = new TwitchLib.TwitchAPI(clientId: "t7y5txan5q662t7zj7p3l4wlth8zhv");
            var v5Stream = new TwitchLib.Streams.V5(api);
            var myStream = await v5Stream.GetStreamByUserAsync("96909659");

            var createdAt = myStream.Stream?.CreatedAt;

            this.Logger.LogInformation($"Get uptime took {sw.ElapsedMilliseconds}ms");
        }
        private TwitchLib.Streams.V5 CreateTwitchStream(TwitchLib.TwitchAPI api)
        {
            TwitchLib.Streams.V5 v5Stream = null;

            try
            {
                v5Stream = new TwitchLib.Streams.V5(api);
                TwitchService.ErrorsReadingViewers = 0;
            }
            catch (Exception ex)
            {
                TwitchService.ErrorsReadingViewers++;
                Logger.LogError(ex, $"Error reading viewers.. {TwitchService.ErrorsReadingViewers} consecutive errors");
            }

            return(v5Stream);
        }
        private async void CheckViews(object state)
        {
            if (!(state is TwitchLib.Streams.V5))
            {
                return;
            }

            TwitchLib.Streams.V5 v5Stream = state as TwitchLib.Streams.V5;

            StreamByUser myStream = null;

            try
            {
                myStream = await v5Stream.GetStreamByUserAsync(ChannelId);
            }
            catch (JsonReaderException ex)
            {
                Logger.LogError($"Unable to read stream from Twitch: {ex}");
                return;
            }
            catch (Exception)
            {
                Logger.LogError($"Error while communicating with Twitch");
                return;
            }

            if (_CurrentViewerCount != (myStream.Stream?.Viewers ?? 0))
            {
                _CurrentViewerCount = (myStream.Stream?.Viewers ?? 0);
                Updated?.Invoke(null, new ServiceUpdatedEventArgs
                {
                    ServiceName = Name,
                    NewViewers  = _CurrentViewerCount
                });
            }
        }
Beispiel #5
0
        private async Task StartTwitchMonitoring()
        {
            var api = new TwitchLib.TwitchAPI(clientId: ClientId);

            Service = new FollowerService(api);
            Service.SetChannelByName(Channel);
            await Service.StartService();

            var v5 = new TwitchLib.Channels.V5(api);

            var follows = await v5.GetAllFollowersAsync(ChannelId);

            _CurrentFollowerCount           = follows.Count;
            Service.OnNewFollowersDetected += Service_OnNewFollowersDetected;

            var v5Stream = new TwitchLib.Streams.V5(api);
            var myStream = await v5Stream.GetStreamByUserAsync(ChannelId);

            _CurrentViewerCount = myStream.Stream?.Viewers ?? 0;

            Logger.LogInformation($"Now monitoring Twitch with {_CurrentFollowerCount} followers and {_CurrentViewerCount} Viewers");

            _Timer = new Timer(CheckViews, null, 0, 5000);
        }