Ejemplo n.º 1
0
        public void PostOnEvent(WorldCupMatch match, WorldCupTeam team, WorldCupTeamEvent e)
        {
            var message = "";

            switch (e.Type)
            {
            case "red-card":
                message = string.Format(EVENT_RED_CARD, e.Player, team.Country, GetCountryCode(team.Country), e.Time);
                break;

            case "yellow-card":
                message = string.Format(EVENT_YELLOW_CARD, e.Player, team.Country, GetCountryCode(team.Country), e.Time);
                break;

            case "goal-penalty":
                message = string.Format(EVENT_PENALTY, team.Country, GetCountryCode(team.Country), e.Player, e.Time);
                break;

            case "goal":
                message = string.Format(EVENT_GOAL, e.Player, team.Country, GetCountryCode(team.Country), e.Time);
                break;

            default:
                return;
            }

            var slackMessage = new SlackMessage
            {
                Channel   = _channel,
                Text      = message,
                IconEmoji = Emoji.Ghost,
                Username  = "******"
            };

            _logger.Info(message);
            _api.SendMessage(_channel, message, Emoji.Ghost, "Apollo WorldCup", _logger);

            if (e.Type == "goal")
            {
                PostMatchStateChange(match);
            }
        }
Ejemplo n.º 2
0
        public void PostMatchStateChange(WorldCupMatch matchState)
        {
            var date    = DateTime.Parse(matchState.DateTime);
            var message = "";

            switch (matchState.Status)
            {
            case "future":
                var stageName = "";

                switch (matchState.StageName)
                {
                case "Round of 16":
                    stageName = "1/8";
                    break;

                case "Quarter-finals":
                    stageName = "1/4";
                    break;

                case "Semi-finals":
                    stageName = "1/2";
                    break;

                case "Play-off for third place":
                    stageName = "Petite finale";
                    break;

                case "Final":
                    stageName = "Finale";
                    break;
                }

                if (matchState.HomeTeam.Code != "TBD" && matchState.AwayTeam.Code != "TBD")
                {
                    message = string.Format(
                        MATCH_FUTURE,
                        stageName,
                        matchState.HomeTeam.Country,
                        GetCountryCode(matchState.HomeTeam.Country),
                        GetCountryCode(matchState.AwayTeam.Country),
                        matchState.AwayTeam.Country,
                        date.ToString(Constants.DATETIME_FORMAT)
                        );
                }
                else if (matchState.HomeTeam.Code != "TBD")
                {
                    message = string.Format(
                        MATCH_FUTURE_TBD_1,
                        stageName,
                        matchState.HomeTeam.Country,
                        GetCountryCode(matchState.HomeTeam.Country),
                        date.ToString(Constants.DATETIME_FORMAT)
                        );
                }
                else if (matchState.AwayTeam.Code != "TBD")
                {
                    message = string.Format(
                        MATCH_FUTURE_TBD_2,
                        stageName,
                        GetCountryCode(matchState.AwayTeam.Country),
                        matchState.AwayTeam.Country,
                        date.ToString(Constants.DATETIME_FORMAT)
                        );
                }
                else
                {
                    message = string.Format(
                        MATCH_FUTURE_TBD_3,
                        stageName,
                        date.ToString(Constants.DATETIME_FORMAT)
                        );
                }
                break;

            case "in progress":
                if (matchState.Time == "half-time")
                {
                    message = string.Format(
                        MATCH_PAUSE,
                        matchState.HomeTeam.Country,
                        GetCountryCode(matchState.HomeTeam.Country),
                        matchState.HomeTeam.Goals,
                        matchState.AwayTeam.Goals,
                        GetCountryCode(matchState.AwayTeam.Country),
                        matchState.AwayTeam.Country
                        );
                }
                else
                {
                    message = string.Format(
                        MATCH_START,
                        matchState.HomeTeam.Country,
                        GetCountryCode(matchState.HomeTeam.Country),
                        matchState.HomeTeam.Goals,
                        matchState.AwayTeam.Goals,
                        GetCountryCode(matchState.AwayTeam.Country),
                        matchState.AwayTeam.Country,
                        matchState.Time
                        );
                }
                break;

            case "completed":
                if (matchState.Winner == "Draw")
                {
                    message = string.Format(
                        MATCH_END_DRAW,
                        matchState.HomeTeam.Country,
                        GetCountryCode(matchState.HomeTeam.Country),
                        GetCountryCode(matchState.AwayTeam.Country),
                        matchState.AwayTeam.Country,
                        matchState.AwayTeam.Goals,
                        matchState.AwayTeam.Goals
                        );
                }
                else
                {
                    var looser      = matchState.Winner == matchState.HomeTeam.Country ? matchState.AwayTeam.Country : matchState.HomeTeam.Country;
                    var scoreWinner = matchState.Winner == matchState.HomeTeam.Country ? matchState.HomeTeam.Goals : matchState.AwayTeam.Goals;
                    var scoreLooser = matchState.Winner == matchState.HomeTeam.Country ? matchState.AwayTeam.Goals : matchState.HomeTeam.Goals;

                    message = string.Format(
                        MATCH_END_VICTORY,
                        matchState.Winner,
                        GetCountryCode(matchState.Winner),
                        looser,
                        GetCountryCode(looser),
                        scoreWinner,
                        scoreLooser
                        );
                }
                break;

            default:
                message = string.Format(
                    MATCH_OTHER,
                    matchState.HomeTeam.Country,
                    GetCountryCode(matchState.HomeTeam.Country),
                    GetCountryCode(matchState.AwayTeam.Country),
                    matchState.AwayTeam.Country,
                    matchState.Status
                    );
                break;
            }

            _logger.Info(message);
            _api.SendMessage(_channel, message, Emoji.Ghost, "Apollo WorldCup", _logger);
        }
Ejemplo n.º 3
0
        public void PostMatchStateChange(WorldCupMatch matchState)
        {
            var date    = DateTime.Parse(matchState.DateTime);
            var message = "";

            switch (matchState.Status)
            {
            case "future":
                message = string.Format(
                    MATCH_FUTURE,
                    matchState.HomeTeam.Country,
                    GetCountryCode(matchState.HomeTeam.Country),
                    GetCountryCode(matchState.AwayTeam.Country),
                    matchState.AwayTeam.Country,
                    date.ToLocalTime().ToShortTimeString()
                    );
                break;

            case "in progress":
                if (matchState.Time == "half-time")
                {
                    message = string.Format(
                        MATCH_PAUSE,
                        matchState.HomeTeam.Country,
                        GetCountryCode(matchState.HomeTeam.Country),
                        matchState.HomeTeam.Goals,
                        matchState.AwayTeam.Goals,
                        GetCountryCode(matchState.AwayTeam.Country),
                        matchState.AwayTeam.Country
                        );
                }
                else
                {
                    message = string.Format(
                        MATCH_START,
                        matchState.HomeTeam.Country,
                        GetCountryCode(matchState.HomeTeam.Country),
                        matchState.HomeTeam.Goals,
                        matchState.AwayTeam.Goals,
                        GetCountryCode(matchState.AwayTeam.Country),
                        matchState.AwayTeam.Country,
                        matchState.Time
                        );
                }
                break;

            case "completed":
                if (matchState.Winner == "Draw")
                {
                    message = string.Format(
                        MATCH_END_DRAW,
                        matchState.HomeTeam.Country,
                        GetCountryCode(matchState.HomeTeam.Country),
                        GetCountryCode(matchState.AwayTeam.Country),
                        matchState.AwayTeam.Country,
                        matchState.AwayTeam.Goals,
                        matchState.AwayTeam.Goals
                        );
                }
                else
                {
                    var looser      = matchState.Winner == matchState.HomeTeam.Country ? matchState.AwayTeam.Country : matchState.HomeTeam.Country;
                    var scoreWinner = matchState.Winner == matchState.HomeTeam.Country ? matchState.HomeTeam.Goals : matchState.AwayTeam.Goals;
                    var scoreLooser = matchState.Winner == matchState.HomeTeam.Country ? matchState.AwayTeam.Goals : matchState.HomeTeam.Goals;

                    message = string.Format(
                        MATCH_END_VICTORY,
                        matchState.Winner,
                        GetCountryCode(matchState.Winner),
                        looser,
                        GetCountryCode(looser),
                        scoreWinner,
                        scoreLooser
                        );
                }
                break;

            default:
                return;
            }

            Console.WriteLine(message);

            _api.SendMessage("#sport", message, Emoji.Ghost, "Apollo WorldCup");
        }