Exemplo 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}");
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tell the user how long they have been following the broadcaster
        /// </summary>
        /// <param name="chatter">User that sent the message</param>
        /// <returns></returns>
        private async Task <DateTime> FollowSinceAsync(TwitchChatter chatter)
        {
            try
            {
                if (chatter.Username == _botConfig.Broadcaster.ToLower())
                {
                    _irc.SendPublicChatMessage($"Please don't tell me you're really following yourself...are you {_botConfig.Broadcaster.ToLower()}? WutFace");
                    return(DateTime.Now);
                }

                chatter.CreatedAt = _twitchChatterListInstance.TwitchFollowers.FirstOrDefault(c => c.Username == chatter.Username).CreatedAt;

                if (chatter.CreatedAt == null)
                {
                    // get chatter info manually
                    RootUserJSON rootUserJSON = await _twitchInfo.GetUsersByLoginNameAsync(chatter.Username);

                    using (HttpResponseMessage message = await _twitchInfo.CheckFollowerStatusAsync(rootUserJSON.Users.First().Id))
                    {
                        string body = await message.Content.ReadAsStringAsync();

                        FollowerJSON response = JsonConvert.DeserializeObject <FollowerJSON>(body);

                        if (!string.IsNullOrEmpty(response.CreatedAt))
                        {
                            chatter.CreatedAt = Convert.ToDateTime(response.CreatedAt);
                        }
                    }
                }

                // mainly used if chatter was originally null
                if (chatter.CreatedAt != null)
                {
                    DateTime startedFollowing = Convert.ToDateTime(chatter.CreatedAt);
                    _irc.SendPublicChatMessage($"@{chatter.DisplayName} has been following since {startedFollowing.ToLongDateString()}");
                }
                else
                {
                    _irc.SendPublicChatMessage($"{chatter.DisplayName} is not following {_botConfig.Broadcaster.ToLower()}");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "FollowerFeature", "FollowSince(TwitchChatter)", false, "!followsince");
            }

            return(DateTime.Now);
        }
Exemplo n.º 3
0
        private async Task <DateTime> PromoteStreamerAsync(TwitchChatter chatter)
        {
            try
            {
                string streamerUsername = ParseChatterMessageUsername(chatter);

                RootUserJSON userInfo = await _twitchInfo.GetUsersByLoginNameAsync(streamerUsername);

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

                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.GetUserStreamAsync(userId);

                if (userStreamInfo.Stream == null)
                {
                    ChannelJSON channelInfo = await _twitchInfo.GetUserChannelByIdAsync(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, "Vip", "PromoteStreamer(TwitchChatter)", false, "!streamer");
            }

            return(DateTime.Now);
        }
Exemplo n.º 4
0
        private async Task SetBroadcasterIdsAsync()
        {
            try
            {
                RootUserJSON json = await _twitchInfo.GetUsersByLoginNameAsync(_botConfig.Broadcaster);

                if (json?.Users.Count == 0)
                {
                    Console.WriteLine("Error: Couldn't find Twitch login name from Twitch. If this persists, please contact my creator");
                    Console.WriteLine("Shutting down now...");
                    Thread.Sleep(3000);
                    Environment.Exit(0);
                }

                await _broadcasterInstance.FindBroadcaster(json.Users.First().Id, _botConfig.TwitchBotApiLink);

                // check if user exists, but changed their username
                if (_broadcasterInstance.TwitchId != null)
                {
                    if (_broadcasterInstance.Username.ToLower() != json.Users.First().Name)
                    {
                        _broadcasterInstance.Username = json.Users.First().Name;

                        await _broadcasterInstance.UpdateBroadcaster(_botConfig.TwitchBotApiLink);
                    }
                    else
                    {
                        return;
                    }
                }
                else // add new user
                {
                    _broadcasterInstance.Username = json.Users.First().Name;
                    _broadcasterInstance.TwitchId = json.Users.First().Id;

                    await _broadcasterInstance.AddBroadcaster(_botConfig.TwitchBotApiLink);
                }

                // check if user was inserted/updated correctly
                await _broadcasterInstance.FindBroadcaster(_broadcasterInstance.TwitchId, _botConfig.TwitchBotApiLink, _broadcasterInstance.Username);
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "TwitchBotApplication", "SetBroadcasterIds()", true);
            }
        }
Exemplo n.º 5
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");
            }
        }