Beispiel #1
0
        /// <summary>Downloads recent followers from Twitch, starts service, fires OnServiceStarted event.</summary>
        public async void StartService()
        {
            TwitchAPIClasses.FollowersResponse response = await TwitchApi.GetTwitchFollowers(Channel, QueryCount);

            ActiveCache = response.Followers;
            _followerServiceTimer.Start();
            OnServiceStarted?.Invoke(this,
                                     new OnServiceStartedArgs {
                Channel = Channel, CheckIntervalSeconds = CheckIntervalSeconds, QueryCount = QueryCount
            });
        }
Beispiel #2
0
        private async void _followerServiceTimerElapsed(object sender, ElapsedEventArgs e)
        {
            TwitchAPIClasses.FollowersResponse response = await TwitchApi.GetTwitchFollowers(Channel, QueryCount);

            List <TwitchAPIClasses.Follower> mostRecentFollowers = response.Followers;
            List <TwitchAPIClasses.Follower> newFollowers        = new List <TwitchAPIClasses.Follower>();

            if (ActiveCache == null)
            {
                ActiveCache  = mostRecentFollowers;
                newFollowers = ActiveCache;
            }
            else
            {
                if (ActiveCache[0].User.Name != mostRecentFollowers[0].User.Name)
                {
                    for (int i = 0; i < mostRecentFollowers.Count; i++)
                    {
                        if (mostRecentFollowers[i].User.Name != ActiveCache[0].User.Name)
                        {
                            newFollowers.Add(mostRecentFollowers[i]);
                        }
                        else
                        {
                            break;
                        }
                    }
                    ActiveCache = mostRecentFollowers;
                }
            }
            if (newFollowers.Count > 0)
            {
                OnNewFollowersDetected?.Invoke(this,
                                               new OnNewFollowersDetectedArgs {
                    Channel = Channel, CheckIntervalSeconds = CheckIntervalSeconds, QueryCount = QueryCount, NewFollowers = newFollowers
                });
            }
        }