示例#1
0
        public async Task CmdSetGenericIgn(string message)
        {
            try
            {
                string gameIgn = message.Substring(message.IndexOf(" ") + 1);

                // Get current game name
                ChannelJSON json = await _twitchInfo.GetBroadcasterChannelById();

                string gameTitle = json.Game;

                InGameUsername ign = await _ign.GetInGameUsername(_broadcasterInstance.DatabaseId);

                if (ign == null)
                {
                    await _ign.CreateInGameUsername(null, _broadcasterInstance.DatabaseId, gameIgn);

                    _irc.SendPublicChatMessage($"Yay! You've set your generic IGN to \"{gameIgn}\"");
                }
                else
                {
                    ign.Message = gameIgn;
                    await _ign.UpdateInGameUsername(ign.Id, _broadcasterInstance.DatabaseId, ign);

                    _irc.SendPublicChatMessage($"Yay! You've updated your generic IGN to \"{gameIgn}\"");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "CmdBrdCstr", "CmdSetGenericIgn(string)", false, "!setgenericign");
            }
        }
示例#2
0
        private async Task <bool> IsMultiplayerGameAsync(string username)
        {
            // Get current game name
            ChannelJSON json = await _twitchInfo.GetBroadcasterChannelByIdAsync();

            string gameTitle = json.Game;

            // Grab game id in order to find party member
            TwitchGameCategory game = await _gameDirectory.GetGameIdAsync(gameTitle);

            if (string.IsNullOrEmpty(gameTitle))
            {
                _irc.SendPublicChatMessage("I cannot see the name of the game. It's currently set to either NULL or EMPTY. "
                                           + "Please have the chat verify that the game has been set for this stream. "
                                           + $"If the error persists, please have @{_botConfig.Broadcaster.ToLower()} retype the game in their Twitch Live Dashboard. "
                                           + "If this error shows up again and your chat can see the game set for the stream, please contact my master with !support in this chat");
                return(false);
            }
            else if (game == null || game.Id == 0)
            {
                _irc.SendPublicChatMessage($"I cannot find the game, \"{gameTitle.TrimEnd()}\", in the database. "
                                           + $"Have my master resolve this issue by typing !support in this chat @{username}");
                return(false);
            }

            if (!game.Multiplayer)
            {
                _irc.SendPublicChatMessage("This game is set to single-player only. "
                                           + $"Contact my master with !support in this chat if this isn't correct @{username}");
                return(false);
            }

            return(true);
        }
示例#3
0
        public async Task CmdRefreshBossFight()
        {
            try
            {
                // Check if any fighters are queued or fighting
                if (_bossFightSettingsInstance.Fighters.Count > 0)
                {
                    _irc.SendPublicChatMessage($"A boss fight is either queued or in progress @{_botConfig.Broadcaster}");
                    return;
                }

                // Get current game name
                ChannelJSON json = await _twitchInfo.GetBroadcasterChannelById();

                string gameTitle = json.Game;

                // Grab game id in order to find party member
                GameList game = await _gameDirectory.GetGameId(gameTitle);

                // During refresh, make sure no fighters can join
                _bossFightSettingsInstance.RefreshBossFight = true;
                await _bossFightSettingsInstance.LoadSettings(_broadcasterId, game?.Id, _botConfig.TwitchBotApiLink);

                _bossFightSettingsInstance.RefreshBossFight = false;

                _irc.SendPublicChatMessage($"Boss fight settings refreshed @{_botConfig.Broadcaster}");
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "CmdBrdCstr", "CmdRefreshBossFight()", false, "!refreshbossfight");
            }
        }
示例#4
0
        private async Task <DateTime> SetGenericIgnAsync(TwitchChatter chatter)
        {
            try
            {
                string message = chatter.Message;
                string gameIgn = message.Substring(message.IndexOf(" ") + 1);

                // Get current game name
                ChannelJSON json = await _twitchInfo.GetBroadcasterChannelByIdAsync();

                string gameTitle = json.Game;

                InGameUsername ign = await _ign.GetInGameUsernameAsync(_broadcasterInstance.DatabaseId);

                if (ign == null)
                {
                    await _ign.CreateInGameUsernameAsync(null, _broadcasterInstance.DatabaseId, gameIgn);

                    _irc.SendPublicChatMessage($"Yay! You've set your generic IGN to \"{gameIgn}\" @{chatter.DisplayName}");
                }
                else
                {
                    ign.Message = gameIgn;
                    await _ign.UpdateInGameUsernameAsync(ign.Id, _broadcasterInstance.DatabaseId, ign);

                    _irc.SendPublicChatMessage($"Yay! You've updated your generic IGN to \"{gameIgn}\" @{chatter.DisplayName}");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "InGameNameFeature", "SetGenericIgn(TwitchChatter)", false, "!setgenericign", chatter.Message);
            }

            return(DateTime.Now);
        }
示例#5
0
        /// <summary>
        /// Removes first party memeber in queue of party up requests
        /// </summary>
        public async Task CmdPopPartyUpRequest()
        {
            try
            {
                // get current game info
                ChannelJSON json = await _twitchInfo.GetBroadcasterChannelById();

                string             gameTitle = json.Game;
                TwitchGameCategory game      = await _gameDirectory.GetGameId(gameTitle);

                if (string.IsNullOrEmpty(gameTitle))
                {
                    _irc.SendPublicChatMessage("I cannot see the name of the game. It's currently set to either NULL or EMPTY. "
                                               + "Please have the chat verify that the game has been set for this stream. "
                                               + $"If the error persists, please have @{_botConfig.Broadcaster.ToLower()} retype the game in their Twitch Live Dashboard. "
                                               + "If this error shows up again and your chat can see the game set for the stream, please contact my master with !support in this chat");
                }
                else if (game?.Id > 0)
                {
                    _irc.SendPublicChatMessage(await _partyUp.PopRequestedPartyMember(game.Id, _broadcasterId));
                }
                else
                {
                    _irc.SendPublicChatMessage("This game is not part of the \"Party Up\" system");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "CmdMod", "CmdPopPartyUpRequest()", false, "!poppartyuprequest");
            }
        }
示例#6
0
        /// <summary>
        /// Display the broadcaster's subscriber link (if they're an Affiliate/Partner)
        /// </summary>
        /// <returns></returns>
        private async Task <DateTime> SubscribeAsync()
        {
            try
            {
                // Get broadcaster type and check if they can have subscribers
                ChannelJSON json = await _twitchInfo.GetBroadcasterChannelByIdAsync();

                string broadcasterType = json.BroadcasterType;

                if (broadcasterType == "partner" || broadcasterType == "affiliate")
                {
                    _irc.SendPublicChatMessage("Subscribe here! https://www.twitch.tv/subs/" + _botConfig.Broadcaster);
                }
                else
                {
                    _irc.SendPublicChatMessage($"{_botConfig.Broadcaster} is not a Twitch Affiliate/Partner. "
                                               + "Please stick around and make their dream not a meme BlessRNG");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "Gen", "Subscribe()", false, "!sub");
            }

            return(DateTime.Now);
        }
示例#7
0
        /// <summary>
        /// Check what party members are available (if game is part of the party up system)
        /// </summary>
        private async Task <DateTime> PartyUpListAsync()
        {
            try
            {
                // get current game info
                ChannelJSON json = await _twitchInfo.GetBroadcasterChannelByIdAsync();

                string             gameTitle = json.Game;
                TwitchGameCategory game      = await _gameDirectory.GetGameIdAsync(gameTitle);

                if (string.IsNullOrEmpty(gameTitle))
                {
                    _irc.SendPublicChatMessage("I cannot see the name of the game. It's currently set to either NULL or EMPTY. "
                                               + "Please have the chat verify that the game has been set for this stream. "
                                               + $"If the error persists, please have @{_botConfig.Broadcaster.ToLower()} retype the game in their Twitch Live Dashboard. "
                                               + "If this error shows up again and your chat can see the game set for the stream, please contact my master with !support in this chat");
                    return(DateTime.Now);
                }
                else if (game == null || game.Id == 0)
                {
                    _irc.SendPublicChatMessage("This game is currently not a part of the \"Party Up\" system");
                }
                else
                {
                    _irc.SendPublicChatMessage(await _partyUp.GetPartyListAsync(game.Id, _broadcasterInstance.DatabaseId));
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "PartyUpFeature", "PartyUpList()", false, "!partyuplist");
            }

            return(DateTime.Now);
        }
示例#8
0
        public async Task CmdDeleteIgn()
        {
            try
            {
                // Get current game name
                ChannelJSON json = await _twitchInfo.GetBroadcasterChannelById();

                string gameTitle = json.Game;

                TwitchGameCategory game = await _gameDirectory.GetGameId(gameTitle);

                InGameUsername ign = await _ign.GetInGameUsername(_broadcasterInstance.DatabaseId, game);

                if (ign != null && ign.GameId != null)
                {
                    await _ign.DeleteInGameUsername(ign.Id, _broadcasterInstance.DatabaseId);

                    _irc.SendPublicChatMessage($"Successfully deleted IGN set for the category \"{game.Title}\"");
                }
                else
                {
                    _irc.SendPublicChatMessage($"Wasn't able to find an IGN to delete for the category \"{game.Title}\"");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "CmdBrdCstr", "CmdDeleteIgn()", false, "!deleteign");
            }
        }
示例#9
0
        private async void Run()
        {
            await LoadReminderContextAsync(); // initial load

            DateTime midnightNextDay = DateTime.Today.AddDays(1);

            while (true)
            {
                ChannelJSON channelJSON = await _twitchInfo.GetBroadcasterChannelByIdAsync();

                string gameTitle = channelJSON.Game;

                TwitchGameCategory game = await _gameDirectory.GetGameIdAsync(gameTitle);

                if (game == null || game.Id == 0)
                {
                    _gameId = null;
                }
                else
                {
                    _gameId = game.Id;
                }

                // remove pending reminders
                _delayedMessagesInstance.DelayedMessages.RemoveAll(r => r.ReminderId > 0);

                foreach (RemindUser reminder in _reminders.OrderBy(m => m.RemindEveryMin))
                {
                    if (IsEveryMinReminder(reminder))
                    {
                        continue;
                    }
                    else if (IsCountdownEvent(reminder))
                    {
                        continue;
                    }
                    else
                    {
                        AddDayOfReminder(reminder);
                    }
                }

                if (_refreshReminders)
                {
                    _irc.SendPublicChatMessage("Reminders refreshed!");
                }

                // reset refresh
                midnightNextDay   = DateTime.Today.AddDays(1);
                _refreshReminders = false;

                // wait until midnight to check reminders
                // unless a manual refresh was called
                while (DateTime.Now < midnightNextDay && !_refreshReminders)
                {
                    Thread.Sleep(1000); // 1 second
                }
            }
        }
示例#10
0
        public async Task LoadChannelInfoAsync()
        {
            ChannelJSON channelJSON = await _twitchInfo.GetBroadcasterChannelByIdAsync();

            if (channelJSON != null)
            {
                CurrentCategory = channelJSON.Game;
                CurrentTitle    = channelJSON.Status;
            }
        }
示例#11
0
        /// <summary>
        /// Removes first party memeber in queue of party up requests
        /// </summary>
        public async Task CmdPopPartyUpRequest()
        {
            try
            {
                // get current game info
                ChannelJSON json = await _twitchInfo.GetBroadcasterChannelById();

                string   gameTitle = json.Game;
                GameList game      = await _gameDirectory.GetGameId(gameTitle);

                _irc.SendPublicChatMessage(await _partyUp.PopRequestedPartyMember(game.Id, _broadcasterId));
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "CmdMod", "CmdPopPartyUpRequest()", false, "!poppartyuprequest");
            }
        }
示例#12
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);
        }
示例#13
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");
            }
        }
示例#14
0
        private async Task <DateTime> SetGameIgnAsync(TwitchChatter chatter)
        {
            try
            {
                string message = chatter.Message;
                string gameIgn = message.Substring(message.IndexOf(" ") + 1);

                // Get current game name
                ChannelJSON json = await _twitchInfo.GetBroadcasterChannelByIdAsync();

                string gameTitle = json.Game;

                TwitchGameCategory game = await _gameDirectory.GetGameIdAsync(gameTitle);

                InGameUsername ign = await _ign.GetInGameUsernameAsync(_broadcasterInstance.DatabaseId, game);

                if (game == null)
                {
                    _irc.SendPublicChatMessage("The game isn't in the database. "
                                               + $"Please set this as part of the general game IDs or IGNs using !setgenericign or !setgenericid @{chatter.DisplayName}");
                    return(DateTime.Now);
                }

                if (ign == null || (ign != null && ign.GameId == null))
                {
                    await _ign.CreateInGameUsernameAsync(game.Id, _broadcasterInstance.DatabaseId, gameIgn);

                    _irc.SendPublicChatMessage($"Yay! You've set your IGN for {gameTitle} to \"{gameIgn}\" @{chatter.DisplayName}");
                }
                else
                {
                    ign.Message = gameIgn;
                    await _ign.UpdateInGameUsernameAsync(ign.Id, _broadcasterInstance.DatabaseId, ign);

                    _irc.SendPublicChatMessage($"Yay! You've updated your IGN for {gameTitle} to \"{gameIgn}\" @{chatter.DisplayName}");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "InGameNameFeature", "SetGameIgn(TwitchChatter)", false, "!setgameign", chatter.Message);
            }

            return(DateTime.Now);
        }
示例#15
0
        private async Task <DateTime> DeleteIgnAsync(TwitchChatter chatter)
        {
            try
            {
                // Get current game name
                ChannelJSON json = await _twitchInfo.GetBroadcasterChannelByIdAsync();

                string gameTitle = json.Game;

                TwitchGameCategory game = await _gameDirectory.GetGameIdAsync(gameTitle);

                InGameUsername ign = await _ign.GetInGameUsernameAsync(_broadcasterInstance.DatabaseId, game);

                if (game == null)
                {
                    _irc.SendPublicChatMessage($"The game isn't in the database @{chatter.DisplayName}");
                    return(DateTime.Now);
                }

                if (ign != null && ign.GameId != null)
                {
                    await _ign.DeleteInGameUsernameAsync(ign.Id, _broadcasterInstance.DatabaseId);

                    _irc.SendPublicChatMessage($"Successfully deleted IGN set for the category, \"{game.Title}\" @{chatter.DisplayName}");
                }
                else
                {
                    _irc.SendPublicChatMessage($"Wasn't able to find an IGN to delete for the category, \"{game.Title}\" @{chatter.DisplayName}");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "InGameNameFeature", "DeleteIgn(TwitchChatter)", false, "!deleteign", chatter.Message);
            }

            return(DateTime.Now);
        }
示例#16
0
        private async Task <DateTime> InGameUsernameAsync(TwitchChatter chatter)
        {
            try
            {
                // Get current game name
                ChannelJSON json = await _twitchInfo.GetBroadcasterChannelByIdAsync();

                string gameTitle = json.Game;

                TwitchGameCategory game = await _gameDirectory.GetGameIdAsync(gameTitle);

                InGameUsername ign = null;

                if (chatter.Message.StartsWith("!all"))
                {
                    ign = await _ign.GetInGameUsernameAsync(_broadcasterInstance.DatabaseId); // return generic IGN
                }
                else
                {
                    ign = await _ign.GetInGameUsernameAsync(_broadcasterInstance.DatabaseId, game); // return specified IGN (if available)
                }
                if (ign != null && !string.IsNullOrEmpty(ign.Message))
                {
                    _irc.SendPublicChatMessage($"{ign.Message} @{chatter.DisplayName}");
                }
                else
                {
                    _irc.SendPublicChatMessage($"I cannot find your in-game username @{chatter.DisplayName}");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "InGameNameFeature", "InGameUsername(TwitchChatter)", false, "!ign");
            }

            return(DateTime.Now);
        }
示例#17
0
        /// <summary>
        /// Removes first party memeber in queue of party up requests
        /// </summary>
        public async Task CmdPopPartyUpRequest()
        {
            try
            {
                // get current game info
                ChannelJSON json = await _twitchInfo.GetBroadcasterChannelById();

                string             gameTitle = json.Game;
                TwitchGameCategory game      = await _gameDirectory.GetGameId(gameTitle);

                if (game?.Id > 0)
                {
                    _irc.SendPublicChatMessage(await _partyUp.PopRequestedPartyMember(game.Id, _broadcasterId));
                }
                else
                {
                    _irc.SendPublicChatMessage("This game is not part of the \"Party Up\" system");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "CmdMod", "CmdPopPartyUpRequest()", false, "!poppartyuprequest");
            }
        }
示例#18
0
        /// <summary>
        /// Check broadcaster's info via API for newest followers or subscribers
        /// </summary>
        /// <returns></returns>
        private async Task CheckNewFollowersSubscribers()
        {
            try
            {
                // Get broadcaster type and check if they can have subscribers
                ChannelJSON channelJson = await _twitchInfo.GetBroadcasterChannelById();

                string broadcasterType = channelJson.BroadcasterType;

                if (broadcasterType.Equals("partner") || broadcasterType.Equals("affiliate"))
                {
                    // Check for new subscribers
                    RootSubscriptionJSON rootSubscriptionJson = await _twitchInfo.GetSubscribersByChannel();

                    IEnumerable <string> freshSubscribers = rootSubscriptionJson.Subscriptions
                                                            ?.Where(u => Convert.ToDateTime(u.CreatedAt).ToLocalTime() > DateTime.Now.AddSeconds(-60))
                                                            .Select(u => u.User.Name);

                    if (freshSubscribers?.Count() > 0)
                    {
                        string subscriberUsername     = "";
                        string subscriberRoleplayName = "";

                        if (freshSubscribers.Count() == 1)
                        {
                            subscriberUsername     = $"@{freshSubscribers.First()}";
                            subscriberRoleplayName = "a NaCl agent";
                        }
                        else if (freshSubscribers.Count() > 1)
                        {
                            subscriberRoleplayName = "NaCl agents";

                            foreach (string subscriber in freshSubscribers)
                            {
                                subscriberUsername += $"{subscriber}, ";
                            }

                            subscriberUsername = subscriberUsername.ReplaceLastOccurrence(", ", "");    // replace trailing ","
                            subscriberUsername = subscriberUsername.ReplaceLastOccurrence(", ", " & "); // replacing joining ","
                        }

                        string welcomeMessage = $"Thank you so much {subscriberUsername} on becoming {subscriberRoleplayName}! "
                                                + $"That dedication will give @{_botConfig.Broadcaster} the edge they need to lead the charge "
                                                + "into the seven salty seas of Twitch! SwiftRage";

                        _irc.SendPublicChatMessage(welcomeMessage);
                    }
                }

                // Check for new followers
                RootFollowerJSON rootFollowerJson = await _twitchInfo.GetFollowersByChannel();

                IEnumerable <string> freshFollowers = rootFollowerJson.Followers
                                                      ?.Where(u => Convert.ToDateTime(u.CreatedAt).ToLocalTime() > DateTime.Now.AddSeconds(-60))
                                                      .Select(u => u.User.Name);

                if (freshFollowers?.Count() > 0)
                {
                    string followerUsername = "";

                    if (freshFollowers.Count() == 1)
                    {
                        followerUsername = $"@{freshFollowers.First()}";
                    }
                    else if (freshFollowers.Count() > 1)
                    {
                        foreach (string follower in freshFollowers)
                        {
                            followerUsername += $"{follower}, ";
                        }

                        followerUsername = followerUsername.ReplaceLastOccurrence(", ", "");    // replace trailing ","
                        followerUsername = followerUsername.ReplaceLastOccurrence(", ", " & "); // replacing joining ","
                    }

                    _irc.SendPublicChatMessage($"Welcome {followerUsername} to the Salt Army! "
                                               + $"With @{_botConfig.Broadcaster} we will pillage the seven salty seas of Twitch together!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error inside FollowerSubscriberListener.CheckNewFollowersSubscribers(): " + ex.Message);
                if (ex.InnerException != null)
                {
                    Console.WriteLine($"Inner Exception: {ex.InnerException.Message}");
                }
            }
        }
示例#19
0
        /// <summary>
        /// Request party member if game and character exists in party up system
        /// </summary>
        /// <param name="chatter">User that sent the message</param>
        private async Task <DateTime> PartyUpAsync(TwitchChatter chatter)
        {
            try
            {
                int inputIndex = chatter.Message.IndexOf(" ") + 1;

                // check if user entered something
                if (chatter.Message.Length < inputIndex)
                {
                    _irc.SendPublicChatMessage($"Please enter a party member @{chatter.DisplayName}");
                    return(DateTime.Now);
                }

                // get current game info
                ChannelJSON json = await _twitchInfo.GetBroadcasterChannelByIdAsync();

                string             gameTitle       = json.Game;
                string             partyMemberName = chatter.Message.Substring(inputIndex);
                TwitchGameCategory game            = await _gameDirectory.GetGameIdAsync(gameTitle);

                // attempt to add requested party member into the queue
                if (string.IsNullOrEmpty(gameTitle))
                {
                    _irc.SendPublicChatMessage("I cannot see the name of the game. It's currently set to either NULL or EMPTY. "
                                               + "Please have the chat verify that the game has been set for this stream. "
                                               + $"If the error persists, please have @{_botConfig.Broadcaster.ToLower()} retype the game in their Twitch Live Dashboard. "
                                               + "If this error shows up again and your chat can see the game set for the stream, please contact my master with !support in this chat");
                    return(DateTime.Now);
                }
                else if (game == null || game.Id == 0)
                {
                    _irc.SendPublicChatMessage("This game is not part of the \"Party Up\" system");
                    return(DateTime.Now);
                }

                PartyUp partyMember = await _partyUp.GetPartyMemberAsync(partyMemberName, game.Id, _broadcasterInstance.DatabaseId);

                if (partyMember == null)
                {
                    _irc.SendPublicChatMessage($"I couldn't find the requested party member \"{partyMemberName}\" @{chatter.DisplayName}. "
                                               + "Please check with the broadcaster for possible spelling errors");
                    return(DateTime.Now);
                }

                if (await _partyUp.HasUserAlreadyRequestedAsync(chatter.DisplayName, game.Id, _broadcasterInstance.DatabaseId))
                {
                    _irc.SendPublicChatMessage($"You have already requested a party member. "
                                               + $"Please wait until your request has been completed @{chatter.DisplayName}");
                    return(DateTime.Now);
                }

                await _partyUp.AddRequestedPartyMemberAsync(chatter.DisplayName, partyMember.Id);

                _irc.SendPublicChatMessage($"@{chatter.DisplayName}: {partyMemberName} has been added to the party queue");
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "PartyUpFeature", "PartyUp(TwitchChatter)", false, "!partyup", chatter.Message);
            }

            return(DateTime.Now);
        }
示例#20
0
        /// <summary>
        /// Load a custom command made by the broadcaster
        /// </summary>
        /// <param name="chatter"></param>
        private async void FindCustomCommand(TwitchChatter chatter)
        {
            try
            {
                /* Display the sound commands to the chatter in alphabetical order */
                if (chatter.Message == "!sound")
                {
                    string orderedCommands = "";
                    foreach (string soundCommand in _customCommandInstance.GetSoundCommands().Select(c => c.Name))
                    {
                        orderedCommands += $"{soundCommand}, ";
                    }

                    string message = $"These are the available sound commands: {orderedCommands.ReplaceLastOccurrence(", ", "")}";
                    if (string.IsNullOrEmpty(orderedCommands))
                    {
                        message = $"There are no sound commands at this time @{chatter.Username}";
                    }

                    _irc.SendPublicChatMessage(message);
                    return;
                }

                /* Else use the custom command from the database */
                // Get current game name
                ChannelJSON json = await _twitchInfo.GetBroadcasterChannelByIdAsync();

                string gameTitle = json.Game;

                // Grab game id in order to find party member
                TwitchGameCategory game = await _gameDirectory.GetGameIdAsync(gameTitle);

                CustomCommand customCommand = _customCommandInstance.FindCustomCommand(chatter.Message.ToLower(), game?.Id);

                if (customCommand == null || _cooldownUsersInstance.IsCommandOnCooldown(customCommand.Name, chatter, _irc, customCommand.IsGlobalCooldown))
                {
                    return;
                }

                int balance = await _bank.CheckBalanceAsync(chatter.Username, _broadcasterInstance.DatabaseId);

                if (balance == -1)
                {
                    _irc.SendPublicChatMessage($"You are not currently banking with us at the moment. "
                                               + $"Please talk to a moderator about acquiring {_botConfig.CurrencyType} @{chatter.DisplayName}");

                    return;
                }
                else if (balance < customCommand.CurrencyCost)
                {
                    _irc.SendPublicChatMessage($"I'm sorry! {customCommand.Name} costs {customCommand.CurrencyCost} "
                                               + $"{_botConfig.CurrencyType} @{chatter.DisplayName}");

                    return;
                }

                // Send either a sound command or a normal text command
                if (customCommand.IsSound)
                {
                    using (SoundPlayer player = new SoundPlayer(customCommand.Message))
                    {
                        player.Play();
                    }
                }
                else if (!customCommand.IsSound)
                {
                    _irc.SendPublicChatMessage(customCommand.Message);
                }

                // Check and add cooldown if necessary
                if (customCommand.CooldownSec > 0)
                {
                    _cooldownUsersInstance.AddCooldown(chatter, DateTime.Now.AddSeconds(customCommand.CooldownSec), customCommand.Name);
                }

                // Make the chatter pay the price if necessary
                if (customCommand.CurrencyCost > 0)
                {
                    balance -= customCommand.CurrencyCost;
                    await _bank.UpdateFundsAsync(chatter.Username, _broadcasterInstance.DatabaseId, balance);

                    _irc.SendPublicChatMessage($"@{chatter.DisplayName} spent {customCommand.CurrencyCost} " +
                                               $"{_botConfig.CurrencyType} for {customCommand.Name} and now has {balance} {_botConfig.CurrencyType}");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "TwitchBotApplication", "FindCustomCommand(TwitchChatter)", false, "N/A", chatter.Message);
            }
        }
        /// <summary>
        /// Check broadcaster's info via API for newest followers or subscribers
        /// </summary>
        /// <returns></returns>
        private async Task CheckNewFollowersSubscribersAsync()
        {
            try
            {
                // Get broadcaster type and check if they can have subscribers
                ChannelJSON channelJson = await _twitchInfo.GetBroadcasterChannelByIdAsync();

                string broadcasterType = channelJson.BroadcasterType;

                if (broadcasterType == "partner" || broadcasterType == "affiliate")
                {
                    /* Check for new subscribers */
                    RootSubscriptionJSON rootSubscriptionJson = await _twitchInfo.GetSubscribersByChannelAsync();

                    IEnumerable <string> freshSubscribers = rootSubscriptionJson.Subscriptions
                                                            ?.Where(u => Convert.ToDateTime(u.CreatedAt).ToLocalTime() > DateTime.Now.AddSeconds(-60))
                                                            .Select(u => u.User.Name);

                    if (freshSubscribers?.Count() > 0)
                    {
                        string subscriberUsername     = "";
                        string subscriberRoleplayName = "";

                        if (freshSubscribers.Count() == 1)
                        {
                            subscriberUsername     = $"@{freshSubscribers.First()}";
                            subscriberRoleplayName = "a NaCl agent";
                        }
                        else if (freshSubscribers.Count() > 1)
                        {
                            subscriberRoleplayName = "NaCl agents";

                            foreach (string subscriber in freshSubscribers)
                            {
                                subscriberUsername += $"{subscriber}, ";
                            }

                            subscriberUsername = subscriberUsername.ReplaceLastOccurrence(", ", "");    // replace trailing ","
                            subscriberUsername = subscriberUsername.ReplaceLastOccurrence(", ", " & "); // replace last ","
                        }

                        string welcomeMessage = $"Congrats {subscriberUsername} on becoming @{_botConfig.Broadcaster} 's {subscriberRoleplayName}!";

                        // Break up welcome message if it's too big
                        if (welcomeMessage.Count() > 500)
                        {
                            string[]      separators  = new string[] { ", ", " & " };
                            List <string> subscribers = subscriberUsername.Split(separators, StringSplitOptions.RemoveEmptyEntries).ToList();

                            while (subscribers.Count > 0)
                            {
                                int popCount = 14;

                                if (subscribers.Count < popCount)
                                {
                                    popCount = subscribers.Count;
                                }

                                subscriberUsername = string.Join(", ", subscribers.Take(popCount));
                                subscriberUsername = subscriberUsername.ReplaceLastOccurrence(", ", "");    // replace trailing ","
                                subscriberUsername = subscriberUsername.ReplaceLastOccurrence(", ", " & "); // replace last ","

                                subscribers.RemoveRange(0, popCount);

                                _irc.SendPublicChatMessage($"Congrats {subscriberUsername} on becoming @{_botConfig.Broadcaster} 's {subscriberRoleplayName}!");
                                await Task.Delay(750);
                            }
                        }
                        else
                        {
                            _irc.SendPublicChatMessage(welcomeMessage);
                        }
                    }
                }

                /* Check for new followers */
                RootFollowerJSON rootFollowerJson = await _twitchInfo.GetFollowersByChannelAsync();

                IEnumerable <string> freshFollowers = rootFollowerJson.Followers
                                                      ?.Where(u => Convert.ToDateTime(u.CreatedAt).ToLocalTime() > DateTime.Now.AddSeconds(-60))
                                                      .Select(u => u.User.Name);

                if (freshFollowers?.Count() > 0)
                {
                    string followerUsername = "";

                    if (freshFollowers.Count() == 1)
                    {
                        followerUsername = $"@{freshFollowers.First()}";
                    }
                    else if (freshFollowers.Count() > 1)
                    {
                        foreach (string follower in freshFollowers)
                        {
                            followerUsername += $"{follower}, ";
                        }

                        followerUsername = followerUsername.ReplaceLastOccurrence(", ", "");    // replace trailing ","
                        followerUsername = followerUsername.ReplaceLastOccurrence(", ", " & "); // replacing joining ","
                    }

                    _irc.SendPublicChatMessage($"Welcome {followerUsername} to the Salt Army! "
                                               + $"With @{_botConfig.Broadcaster} we will pillage the seven salty seas of Twitch together!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error inside FollowerSubscriberListener.CheckNewFollowersSubscribers(): " + ex.Message);
                if (ex.InnerException != null)
                {
                    Console.WriteLine($"Inner Exception: {ex.InnerException.Message}");
                }
            }
        }