コード例 #1
0
ファイル: GoalHorn.cs プロジェクト: joefroh/JetsDiscordBot
        private void RunGame(GameDetail game)
        {
            var gameLive   = true;
            var lastGoalId = -1;

            Locator.Instance.Fetch <ILogger>().LogLine(String.Format("Goal Horn: Enterting GameLive loop for {0}", _config.TeamFriendlyName));
            while (gameLive)
            {
                var gameObj  = GetLiveGameData(game);
                var currGoal = GetLatestGoal(gameObj);
                if (currGoal != null)
                {
                    var currGoalId   = int.Parse(currGoal["about"]["eventId"].ToString());
                    var currGoalIndx = int.Parse(currGoal["about"]["eventIdx"].ToString());

                    if (currGoalId > lastGoalId)
                    {
                        Locator.Instance.Fetch <ILogger>().LogLine(String.Format("Goal Horn: Detected goal in tracked game for {0}", _config.TeamFriendlyName));

                        //we have a new goal
                        var        goal        = GetGoalFromIndex(gameObj, currGoalIndx);
                        GoalDetail goalDetails = null;


                        // if we want to post the goal, delay first to let the data populate
                        Thread.Sleep(_config.Delay * 1000);
                        gameObj     = GetLiveGameData(game);
                        goalDetails = GetGoalFromID(gameObj, currGoalId); // Fixes bug where if 2 goals are scored in a short period, we can announce the wrong goal.


                        if (goalDetails != null)
                        {
                            Locator.Instance.Fetch <ILogger>().LogLine(String.Format("Goal Horn: Announcing goal in tracked game for {0}", _config.TeamFriendlyName));
                            if (goal.ScoringTeamId == _config.Team)
                            {
                                //output to bot
                                AnnouncePriorityGoal(goalDetails);
                            }
                            else
                            {
                                AnnounceGoal(goalDetails);
                            }
                        }
                        Locator.Instance.Fetch <ILogger>().LogLine(String.Format("Goal Horn: Updating goal index to {1} for {0}", _config.TeamFriendlyName, currGoalId));
                        lastGoalId = currGoalId;
                    }
                }

                AwaitIntermission(game, gameObj);

                gameLive = IsGameInProgress(gameObj);
                Thread.Sleep(2000); // This used to be 1 second, but that seemed really fast.
            }

            Locator.Instance.Fetch <ILogger>().LogLine(String.Format("Goal Horn: Exited game loop, running end game commands for {0}", _config.TeamFriendlyName));
            var gameData = GetLiveGameData(game);

            SendLineScoreForPeriod(gameData);
            SendGameSummary(gameData);
        }
コード例 #2
0
ファイル: GoalHorn.cs プロジェクト: joefroh/JetsDiscordBot
        private void AnnounceGoal(GoalDetail goal)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine(String.Format("{1} Goal", goal.ScoringTeam));
            builder.AppendLine(goal.Description);

            _channel.SendMessageAsync(builder.ToString());
        }
コード例 #3
0
ファイル: GoalHorn.cs プロジェクト: joefroh/JetsDiscordBot
        private void AnnouncePriorityGoal(GoalDetail goal)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine(String.Format("{0} {1} GOOOAAALLL!!! {2}", _config.PreText, _config.TeamFriendlyName.ToUpper(), _config.PostText));
            builder.AppendLine(goal.Description);

            _channel.SendMessageAsync(builder.ToString());
        }
コード例 #4
0
ファイル: GoalHorn.cs プロジェクト: joefroh/JetsDiscordBot
        private GoalDetail GetGoalFromIndex(JObject gameObj, int index)
        {
            var allPlays = (JArray)gameObj["liveData"]["plays"]["allPlays"];
            var goalData = allPlays[index];

            var description = goalData["result"]["description"].ToString();
            var playIndex   = index;
            var teamName    = goalData["team"]["name"].ToString();
            var teamId      = int.Parse(goalData["team"]["id"].ToString());

            var goalDetail = new GoalDetail()
            {
                Description = description, PlayIndex = playIndex, ScoringTeam = teamName, ScoringTeamId = teamId
            };

            return(goalDetail);
        }