Example #1
0
        private async Task <TwitchChatter> GetTwitchFollowerInfo(string chatter, string userTwitchId)
        {
            TwitchChatter follower = null;

            try
            {
                using (HttpResponseMessage message = await _twitchInfo.CheckFollowerStatus(userTwitchId))
                {
                    // check if chatter is a follower
                    if (!message.IsSuccessStatusCode)
                    {
                        // check if user was a follower but isn't anymore
                        if (_twitchChatterListInstance.TwitchFollowers.Any(c => c.Username == chatter))
                        {
                            _twitchChatterListInstance.TwitchFollowers.RemoveAll(c => c.Username == chatter);
                            _twitchChatterListInstance.TwitchRegularFollowers.RemoveAll(c => c.Username == chatter);
                        }

                        return(null);
                    }

                    string body = await message.Content.ReadAsStringAsync();

                    FollowerJSON response         = JsonConvert.DeserializeObject <FollowerJSON>(body);
                    DateTime     startedFollowing = Convert.ToDateTime(response.CreatedAt);

                    follower = new TwitchChatter {
                        Username = chatter, CreatedAt = startedFollowing, TwitchId = userTwitchId
                    };

                    if (!_twitchChatterListInstance.TwitchFollowers.Any(c => c.Username == chatter))
                    {
                        _twitchChatterListInstance.TwitchFollowers.Add(follower);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error inside FollowerSubscriberListener.GetTwitchFollowerInfo(string, string): {ex.Message}");
                if (ex.InnerException != null)
                {
                    Console.WriteLine($"Inner Exception: {ex.InnerException.Message}");
                }
            }

            return(follower);
        }