Esempio n. 1
0
        /// <summary>
        /// Check the chatter list for any followers or subscribers
        /// </summary>
        /// <returns></returns>
        private async Task CheckChatterFollowersSubscribers()
        {
            try
            {
                // Wait until chatter lists are available
                while (!_twitchChatterListInstance.AreListsAvailable)
                {
                    Thread.Sleep(500);
                }

                IEnumerable <string> availableChatters = _twitchChatterListInstance.ChattersByName;
                if (availableChatters == null || availableChatters.Count() == 0)
                {
                    return;
                }

                _rankList = await _follower.GetRankList(_broadcasterId);

                if (_rankList == null)
                {
                    _rankList = await _follower.CreateDefaultRanks(_broadcasterId);
                }

                // Check for existing or new followers/subscribers
                for (int i = 0; i < availableChatters.Count(); i++)
                {
                    string chatter = availableChatters.ElementAt(i);

                    // skip bot and broadcaster
                    if (string.Equals(chatter, _botConfig.BotName, StringComparison.CurrentCultureIgnoreCase) ||
                        string.Equals(chatter, _botConfig.Broadcaster, StringComparison.CurrentCultureIgnoreCase))
                    {
                        continue;
                    }

                    // get chatter info
                    RootUserJSON rootUserJSON = await _twitchInfo.GetUsersByLoginName(chatter);

                    string userTwitchId = rootUserJSON.Users.FirstOrDefault()?.Id;

                    // skip chatter if Twitch ID is missing
                    if (string.IsNullOrEmpty(userTwitchId))
                    {
                        continue;
                    }

                    // check for follower and/or subscriber and add then to their respective lists
                    await CheckFollower(chatter, userTwitchId);
                    await CheckSubscriber(chatter, userTwitchId);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error inside FollowerSubscriberListener.CheckChatterFollowersSubscribers(): {ex.Message}");
                if (ex.InnerException != null)
                {
                    Console.WriteLine($"Inner Exception: {ex.InnerException.Message}");
                }
            }
        }
Esempio n. 2
0
        public async Task CmdPromoteStreamer(TwitchChatter chatter)
        {
            try
            {
                string streamerUsername = chatter.Message.Substring(chatter.Message.IndexOf("@") + 1).ToLower();

                RootUserJSON userInfo = await _twitchInfo.GetUsersByLoginName(streamerUsername);

                if (userInfo.Users.Count == 0)
                {
                    _irc.SendPublicChatMessage($"Cannot find the requested user @{chatter.Username}");
                    return;
                }

                string userId           = userInfo.Users.First().Id;
                string promotionMessage = $"Hey everyone! Check out {streamerUsername}'s channel at https://www.twitch.tv/"
                                          + $"{streamerUsername} and slam that follow button!";

                RootStreamJSON userStreamInfo = await _twitchInfo.GetUserStream(userId);

                if (userStreamInfo.Stream == null)
                {
                    ChannelJSON channelInfo = await _twitchInfo.GetUserChannelById(userId);

                    if (!string.IsNullOrEmpty(channelInfo.Game))
                    {
                        promotionMessage += $" They were last seen playing \"{channelInfo.Game}\"";
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(userStreamInfo.Stream.Game))
                    {
                        promotionMessage += $" Right now, they're playing \"{userStreamInfo.Stream.Game}\"";
                    }
                }

                _irc.SendPublicChatMessage(promotionMessage);
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "CmdMod", "CmdResetGotNextGame(TwitchChatter)", false, "!streamer");
            }
        }