Example #1
0
        private GameDetail GetTodaysGame()
        {
            var req = new RestRequest("/api/v1/schedule");

            req.AddParameter("teamId", _config.Team);
            var res    = _restClient.Execute(req);
            var resObj = JObject.Parse(res.Content);
            var dates  = (JArray)resObj["dates"];

            if (dates.Count == 0)
            {
                return(null);
            }

            var gameDates = (JArray)dates[0]["games"];

            if (gameDates.Count == 0)
            {
                return(null);
            }

            // There should only ever be 1
            var gameDate     = DateTime.Parse(gameDates[0]["gameDate"].ToString());
            var gameLiveLink = gameDates[0]["link"].ToString();

            var result = new GameDetail()
            {
                LiveFeedLink = gameLiveLink, StartTimeUTC = gameDate
            };

            return(result);
        }
Example #2
0
        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);
        }
Example #3
0
        private JObject GetLiveGameData(GameDetail game)
        {
            var req     = new RestRequest(game.LiveFeedLink);
            var res     = _restClient.Execute(req);
            var gameObj = JObject.Parse(res.Content);

            return(gameObj);
        }
Example #4
0
        private bool IsGameFinal(GameDetail game)
        {
            var stateString = GetAbstractGameState(game);

            if (stateString != "Final")
            {
                return(false);
            }

            return(true);
        }
Example #5
0
        private bool IsGameInProgress(GameDetail game)
        {
            var stateString = GetAbstractGameState(game);

            if (stateString != "Live")
            {
                return(false);
            }

            return(true);
        }
Example #6
0
        private void AwaitIntermission(GameDetail game, JObject gameObj)
        {
            if (!GameIsInIntermission(gameObj))
            {
                return;
            }

            // Send Period LineScore here
            SendLineScoreForPeriod(gameObj);

            while (GameIsInIntermission(gameObj))
            {
                Thread.Sleep(5000); // check every 5 seconds to see if intermission is over
                gameObj = GetLiveGameData(game);
            }
        }
Example #7
0
        private void RunGame(GameDetail game)
        {
            var gameLive   = true;
            var lastGoalId = -1;

            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)
                    {
                        //we have a new goal, check if its the team we care about
                        var goal = GetGoalFromIndex(gameObj, currGoalIndx);

                        if (goal.ScoringTeamId == _config.Team)
                        {
                            // if we want to post the goal, delay first to let the data populate
                            Thread.Sleep(_config.Delay * 1000);
                            gameObj = GetLiveGameData(game);
                            var 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)
                            {
                                //output to bot
                                AnnounceGoal(goalDetails);
                            }
                        }
                        lastGoalId = currGoalId;
                    }
                }

                AwaitIntermission(game, gameObj);

                gameLive = IsGameInProgress(gameObj);
                Thread.Sleep(1000);
            }

            var gameData = GetLiveGameData(game);

            SendLineScoreForPeriod(gameData);
            SendGameSummary(gameData);
        }
Example #8
0
        private void AwaitGameStart(GameDetail game)
        {
            // calculate time to game and sleep, or if its after the scheduled time, just wait 5 seconds or something
            var gametime    = game.StartTimeUTC;
            var spanTilGame = gametime.Subtract(DateTime.UtcNow);

            if (spanTilGame.Ticks > 0) // check to make sure there is still time before the scheduled puck drop
            {
                Console.WriteLine("Sleeping until " + _config.TeamFriendlyName + " game in " + spanTilGame.ToString());
                Thread.Sleep(spanTilGame);
                Console.WriteLine("Waking up! Is it gametime?");
            }
            else //otherwise just wait 5 seconds and check again
            {
                Thread.Sleep(5000);
            }
        }
Example #9
0
        private void AwaitIntermission(GameDetail game, JObject gameObj)
        {
            if (!GameIsInIntermission(gameObj))
            {
                return;
            }

            Locator.Instance.Fetch <ILogger>().LogLine(String.Format("Goal Horn: Intermission detected in game for {0}", _config.TeamFriendlyName));

            // Send Period LineScore here
            SendLineScoreForPeriod(gameObj);

            while (GameIsInIntermission(gameObj))
            {
                Locator.Instance.Fetch <ILogger>().LogLine(String.Format("Goal Horn: Checking if intermission is over for {0}", _config.TeamFriendlyName));
                Thread.Sleep(30000); // check every 30 seconds to see if intermission is over
                gameObj = GetLiveGameData(game);
            }
        }
Example #10
0
        private GameDetail GetTodaysGame()
        {
            Locator.Instance.Fetch <ILogger>().LogLine(String.Format("Goal Horn: Fetching today's game schedule for {0}", _config.TeamFriendlyName));
            var req = new RestRequest("/api/v1/schedule");

            req.AddParameter("teamId", _config.Team);
            var res    = _restClient.Execute(req);
            var resObj = JObject.Parse(res.Content);
            var dates  = (JArray)resObj["dates"];

            if (dates.Count == 0)
            {
                Locator.Instance.Fetch <ILogger>().LogLine(String.Format("Goal Horn: No dates found today for {0}", _config.TeamFriendlyName));
                return(null);
            }

            var gameDates = (JArray)dates[0]["games"];

            if (gameDates.Count == 0)
            {
                Locator.Instance.Fetch <ILogger>().LogLine(String.Format("Goal Horn: No games found today for {0}", _config.TeamFriendlyName));
                return(null);
            }

            // There should only ever be 1
            Locator.Instance.Fetch <ILogger>().LogLine(String.Format("Goal Horn: Found a game today for {0}", _config.TeamFriendlyName));
            var gameDate     = DateTime.Parse(gameDates[0]["gameDate"].ToString());
            var gameLiveLink = gameDates[0]["link"].ToString();

            var result = new GameDetail()
            {
                LiveFeedLink = gameLiveLink, StartTimeUTC = gameDate
            };

            return(result);
        }
Example #11
0
        private string GetAbstractGameState(GameDetail game)
        {
            var gameObj = GetLiveGameData(game);

            return(GetAbstractGameState(gameObj));
        }