Beispiel #1
0
        private async void _followerServiceTimerElapsed(object sender, ElapsedEventArgs e)
        {
            Models.API.Follow.FollowersResponse response;
            try
            {
                response = await TwitchApi.Follows.GetFollowersAsync(Channel, QueryCount);
            }
            catch (WebException)
            {
                //Logging.Log("Twitch API is unavailable. Skipping FollowerService iteration...");
                return;
            }
            List <Models.API.Follow.Follower> mostRecentFollowers = response.Followers;
            List <Models.API.Follow.Follower> newFollowers        = new List <Models.API.Follow.Follower>();

            foreach (Models.API.Follow.Follower recentFollower in mostRecentFollowers)
            {
                bool found = false;
                foreach (Models.API.Follow.Follower cachedFollower in ActiveCache)
                {
                    if (recentFollower.User.Name.ToLower() == cachedFollower.User.Name.ToLower())
                    {
                        found = true;
                    }
                }
                if (!found)
                {
                    newFollowers.Add(recentFollower);
                }
            }

            // Check for new followers
            if (newFollowers.Count > 0)
            {
                // add new followers to active cache
                ActiveCache.AddRange(newFollowers);

                // prune cache so we don't use too much space unnecessarily
                if (ActiveCache.Count > CacheSize)
                {
                    ActiveCache = ActiveCache.GetRange(ActiveCache.Count - (CacheSize + 1), CacheSize);
                }

                // Invoke new followers event
                OnNewFollowersDetected?.Invoke(this,
                                               new OnNewFollowersDetectedArgs
                {
                    Channel = Channel,
                    CheckIntervalSeconds = CheckIntervalSeconds,
                    QueryCount           = QueryCount,
                    NewFollowers         = newFollowers
                });
            }
        }
Beispiel #2
0
        private async void _followerServiceTimerElapsed(object sender, ElapsedEventArgs e)
        {
            FollowersResponse response = await TwitchApi.GetTwitchFollowers(Channel, QueryCount);

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

            if (ActiveCache == null)
            {
                ActiveCache  = mostRecentFollowers;
                newFollowers = ActiveCache;
            }
            else
            {
                foreach (Follower recentFollower in mostRecentFollowers)
                {
                    bool found = false;
                    foreach (Follower cachedFollower in ActiveCache)
                    {
                        if (recentFollower.User.Name.ToLower() == cachedFollower.User.Name.ToLower())
                        {
                            found = true;
                        }
                    }
                    if (!found)
                    {
                        newFollowers.Add(recentFollower);
                    }
                }

                // Check for new followers
                if (newFollowers.Count > 0)
                {
                    // add new followers to active cache
                    ActiveCache.AddRange(newFollowers);

                    // prune cache so we don't use too much space unnecessarily
                    if (ActiveCache.Count > CacheSize)
                    {
                        ActiveCache = ActiveCache.GetRange(ActiveCache.Count - (CacheSize + 1), CacheSize);
                    }

                    // Invoke new followers event
                    OnNewFollowersDetected?.Invoke(this,
                                                   new OnNewFollowersDetectedArgs {
                        Channel = Channel, CheckIntervalSeconds = CheckIntervalSeconds, QueryCount = QueryCount, NewFollowers = newFollowers
                    });
                }
            }
        }
Beispiel #3
0
        private async void _followerServiceTimerElapsed(object sender, ElapsedEventArgs e)
        {
            List <string> mostRecentFollowers = new List <string>();

            try
            {
                if (ChannelIdentifier == Enums.ChannelIdentifierType.Username)
                {
                    var followers = await TwitchAPI.Follows.v3.GetFollowers(ChannelData, QueryCount);

                    foreach (var follower in followers.Followers)
                    {
                        mostRecentFollowers.Add(follower.User.Name);
                    }
                }
                else
                {
                    var followers = await TwitchAPI.Channels.v5.GetChannelFollowers(ChannelData, QueryCount);

                    foreach (var follower in followers.Follows)
                    {
                        mostRecentFollowers.Add(follower.User.Name);
                    }
                }
            }
            catch (WebException)
            {
                return;
            }
            List <string> newFollowers = new List <string>();

            foreach (var recentFollower in mostRecentFollowers)
            {
                bool found = false;
                foreach (var cachedFollower in ActiveCache)
                {
                    if (recentFollower == cachedFollower)
                    {
                        found = true;
                    }
                }
                if (!found)
                {
                    newFollowers.Add(recentFollower);
                }
            }

            // Check for new followers
            if (newFollowers.Count > 0)
            {
                // add new followers to active cache
                ActiveCache.AddRange(newFollowers);

                // prune cache so we don't use too much space unnecessarily
                if (ActiveCache.Count > CacheSize)
                {
                    ActiveCache = ActiveCache.GetRange(ActiveCache.Count - (CacheSize + 1), CacheSize);
                }

                // Invoke new followers event
                OnNewFollowersDetected?.Invoke(this,
                                               new OnNewFollowersDetectedArgs
                {
                    ChannelIdentifier    = ChannelIdentifier,
                    ChannelData          = ChannelData,
                    CheckIntervalSeconds = CheckIntervalSeconds,
                    QueryCount           = QueryCount,
                    NewFollowers         = newFollowers
                });
            }
        }