Exemplo n.º 1
0
        public OutgoingWebookMessage MapToSlackMessage(string body)
        {
            this._body = body;
            var order = QueryHelpers.ParseQuery(this._body);

            var slackMessage = new OutgoingWebookMessage
            {
                Token       = order["token"],
                TeamId      = order["team_id"],
                TeamDomain  = order["team_domain"],
                ChannelId   = order["channel_id"],
                ChannelName = order["channel_name"],
                UserId      = order["user_id"],
                Username    = order["user_name"],
                Text        = order["text"],
                Timestamp   = order["timestamp"],
                TriggerWord = order["trigger_word"]
            };

            return(slackMessage);
        }
Exemplo n.º 2
0
        private async Task <APIGatewayProxyResponse> Delagator(OutgoingWebookMessage order)
        {
            var response = new APIGatewayProxyResponse
            {
                StatusCode = 200,
                Body       = "An error occured and I don't know what to do with myself"
            };

            var commands = order.Text.Split(' ');
            var command  = commands[1] ?? string.Empty;
            var card     = commands[2] ?? string.Empty;

            Team team = null;

            if (string.IsNullOrEmpty(command))
            {
                team = await Team.Load(this._context, order.TeamId, order.ChannelId);
            }

            // handle a create command first because logic is different
            if (command == "create")
            {
                if (team == null)
                {
                    team = new Team(order.TeamId, order.ChannelId);
                }
                else
                {
                    if (!team.IsGameInProgress())
                    {
                        team.CurrentGame = new Game();
                    }
                    else
                    {
                        response.Body = "Game already in progress!";
                    }
                }

                team.Save(this._context);
                response.Body = "Game created! Waiting for players to join...";
                return(response);
            }

            // apply general game checks
            if (team == null || !team.IsGameInProgress())
            {
                response.Body = "No game in progress. Create a game first.";
                return(response);
            }

            switch (command)
            {
            case "debug":
                response.Body = this.CreateDebugBody(order);
                break;

            case "join":
                var player = new Player
                {
                    Id   = order.UserId,
                    Name = order.Username
                };

                if (team.CurrentGame.AddPlayer(player))
                {
                    response.Body = $"{player.Name} joined the game! There are now {team.CurrentGame.Players.Count} / 4 players";
                }

                team.Save(this._context);
                break;

            case "start":
                team.CurrentGame.Start();

                // need to spawn responses to each player with their hands
                break;

            case "play":
                response.Body = team.CurrentGame.Play(card);

                // need to spawn reponse to affected players with their current hands
                // need to understand if something like d2 that multiple players will be messaged with their hands
                break;

            case "pass":
                team.CurrentGame.Pass();

                // need to spawn reponse to player with current hand
                break;
            }

            return(response);
        }