コード例 #1
0
        public SlackResponseDoc MarkAnswerIncorrect(SlackRequestDoc requestDoc, string target)
        {
            string userId = SlackUtils.NormalizeId(target);

            try
            {
                _workflowService.OnIncorrectAnswerSelected(requestDoc.ChannelId, requestDoc.UserId, userId);
            }
            catch (GameNotStartedException e)
            {
                return(SlackResponseDoc.Failure(String.Format(GAME_NOT_STARTED_FORMAT, requestDoc.Command)));
            }
            catch (WorkflowException e)
            {
                return(SlackResponseDoc.Failure(e.Message));
            }

            SlackResponseDoc delayedResponseDoc = new SlackResponseDoc
            {
                ResponseType = SlackResponseType.IN_CHANNEL,
                Text         = String.Format("You couldn't be more wrong, <@{0}>", userId)
            };

            _delayedSlackService.sendResponse(requestDoc.ResponseUrl, delayedResponseDoc);

            return(new SlackResponseDoc
            {
                ResponseType = SlackResponseType.EPHEMERAL,
                Text = "Marked answer incorrect."
            });
        }
コード例 #2
0
        public SlackResponseDoc Stop(SlackRequestDoc requestDoc)
        {
            try
            {
                _workflowService.OnGameStopped(requestDoc.ChannelId, requestDoc.UserId);
            }
            catch (GameNotStartedException)
            {
                return(SlackResponseDoc.Failure(String.Format(GAME_NOT_STARTED_FORMAT, requestDoc.Command)));
            }
            catch (WorkflowException e)
            {
                return(SlackResponseDoc.Failure(e.Message));
            }

            return(new SlackResponseDoc
            {
                ResponseType = SlackResponseType.IN_CHANNEL,
                Text = String.Format(
                    "The game has been stopped but scores have not been cleared. If you'd like to start a new game, try `{0} start`.",
                    requestDoc.Command,
                    requestDoc.UserId
                    )
            });
        }
コード例 #3
0
        public SlackResponseDoc SubmitQuestion(SlackRequestDoc requestDoc, string question)
        {
            try
            {
                _workflowService.OnQuestionSubmitted(requestDoc.ChannelId, requestDoc.UserId, question);
            }
            catch (GameNotStartedException)
            {
                return(SlackResponseDoc.Failure(String.Format(GAME_NOT_STARTED_FORMAT, requestDoc.Command)));
            }
            catch (WorkflowException e)
            {
                return(SlackResponseDoc.Failure(e.Message));
            }

            SlackResponseDoc delayedResponseDoc = new SlackResponseDoc
            {
                ResponseType = SlackResponseType.IN_CHANNEL,
                Text         = String.Format("<@{0}> asked the following question:\n\n{1}", requestDoc.UserId, question)
            };

            _delayedSlackService.sendResponse(requestDoc.ResponseUrl, delayedResponseDoc);

            return(new SlackResponseDoc
            {
                ResponseType = SlackResponseType.EPHEMERAL,
                Text = "Question posted."
            });
        }
コード例 #4
0
        public SlackResponseDoc SubmitAnswer(SlackRequestDoc requestDoc, string answer)
        {
            try
            {
                _workflowService.OnAnswerSubmitted(
                    requestDoc.ChannelId,
                    requestDoc.UserId,
                    requestDoc.Username,
                    answer,
                    requestDoc.RequestTime
                    );
            }
            catch (GameNotStartedException)
            {
                return(SlackResponseDoc.Failure(String.Format(GAME_NOT_STARTED_FORMAT, requestDoc.Command)));
            }
            catch (WorkflowException e)
            {
                return(SlackResponseDoc.Failure(e.Message));
            }

            SlackUser user = new SlackUser(requestDoc.UserId, requestDoc.Username);

            _scoreService.CreateUserIfNotExists(requestDoc.ChannelId, user);

            SlackResponseDoc delayedResponseDoc = new SlackResponseDoc
            {
                ResponseType = SlackResponseType.IN_CHANNEL,
                Text         = String.Format("<@{0}> answers:", requestDoc.UserId),
                Attachments  = new List <SlackAttachment> {
                    new SlackAttachment(answer, false)
                }
            };

            _delayedSlackService.sendResponse(requestDoc.ResponseUrl, delayedResponseDoc);

            return(new SlackResponseDoc
            {
                ResponseType = SlackResponseType.EPHEMERAL,
                Text = "Answer submitted."
            });
        }
コード例 #5
0
        public SlackResponseDoc Pass(SlackRequestDoc requestDoc, string target)
        {
            string userId = SlackUtils.NormalizeId(target);

            try
            {
                bool userExists = _scoreService.DoesUserExist(requestDoc.ChannelId, userId);

                if (!userExists)
                {
                    SlackResponseDoc responseDoc = SlackResponseDoc.Failure("User " + target + " does not exist. Please choose a valid user.");
                    responseDoc.Attachments = new List <SlackAttachment> {
                        new SlackAttachment("Usage: `" + requestDoc.Command + " pass @jsmith`")
                    };
                    return(responseDoc);
                }

                _workflowService.OnTurnChanged(requestDoc.ChannelId, requestDoc.UserId, userId);
            }
            catch (GameNotStartedException)
            {
                return(SlackResponseDoc.Failure(String.Format(GAME_NOT_STARTED_FORMAT, requestDoc.Command)));
            }
            catch (WorkflowException e)
            {
                return(SlackResponseDoc.Failure(e.Message));
            }

            SlackResponseDoc delayedResponseDoc = new SlackResponseDoc
            {
                ResponseType = SlackResponseType.IN_CHANNEL,
                Text         = String.Format("<@{0}> has decided to pass his/her turn to <@{1}>.\n\nOK, <@{1}>, it's your turn to ask a question!", requestDoc.UserId, userId)
            };

            _delayedSlackService.sendResponse(requestDoc.ResponseUrl, delayedResponseDoc);

            return(new SlackResponseDoc
            {
                ResponseType = SlackResponseType.EPHEMERAL,
                Text = "Turn passed to <@" + userId + ">."
            });
        }
コード例 #6
0
        public SlackResponseDoc Start(SlackRequestDoc requestDoc, string topic)
        {
            string channelId = requestDoc.ChannelId;
            string userId    = requestDoc.UserId;

            try
            {
                _workflowService.OnGameStarted(channelId, userId, topic);
            }
            catch (GameNotStartedException)
            {
                return(SlackResponseDoc.Failure(String.Format(GAME_NOT_STARTED_FORMAT, requestDoc.Command)));
            }
            catch (WorkflowException e)
            {
                return(SlackResponseDoc.Failure(e.Message));
            }

            return(new SlackResponseDoc
            {
                ResponseType = SlackResponseType.IN_CHANNEL,
                Text = String.Format("OK, <@{0}>, please ask a question.", userId)
            });
        }
コード例 #7
0
        public SlackResponseDoc MarkAnswerCorrect(SlackRequestDoc requestDoc, string target, string answer)
        {
            string text;

            try
            {
                _workflowService.OnCorrectAnswerSelected(requestDoc.ChannelId, requestDoc.UserId);

                if (target.Equals(NO_CORRECT_ANSWER_TARGET, StringComparison.InvariantCultureIgnoreCase))
                {
                    //"Change" back to the original host to reset the workflow state
                    _workflowService.OnTurnChanged(requestDoc.ChannelId, requestDoc.UserId, requestDoc.UserId);

                    if (answer == null)
                    {
                        text = String.Format(
                            "It looks like no one was able to answer that one!\n\n{0}\n\nOK, <@{1}>, let's try another one!",
                            generateScoreText(requestDoc),
                            requestDoc.UserId
                            );
                    }
                    else
                    {
                        text = String.Format(
                            "It looks like no one was able to answer that one! The correct answer was {0}.\n\n{1}\n\nOK, <@{2}>, let's try another one!",
                            answer,
                            generateScoreText(requestDoc),
                            requestDoc.UserId
                            );
                    }
                }
                else
                {
                    string userId = SlackUtils.NormalizeId(target);

                    _scoreService.IncrementScore(requestDoc.ChannelId, userId);
                    _workflowService.OnTurnChanged(requestDoc.ChannelId, requestDoc.UserId, userId);

                    if (answer == null)
                    {
                        text = String.Format(
                            "<@{1}> is correct!\n\n{0}\n\nOK, <@{1}>, you're up!",
                            generateScoreText(requestDoc),
                            userId
                            );
                    }
                    else
                    {
                        text = String.Format(
                            "<@{2}> is correct with {0}!\n\n{1}\n\nOK, <@{2}>, you're up!",
                            answer,
                            generateScoreText(requestDoc),
                            userId
                            );
                    }
                }
            }
            catch (GameNotStartedException)
            {
                return(SlackResponseDoc.Failure(String.Format(GAME_NOT_STARTED_FORMAT, requestDoc.Command)));
            }
            catch (WorkflowException e)
            {
                return(SlackResponseDoc.Failure(e.Message));
            }
            catch (ScoreException)
            {
                SlackResponseDoc responseDoc = SlackResponseDoc.Failure("User " + target + " does not exist. Please choose a valid user.");
                responseDoc.Attachments = new List <SlackAttachment> {
                    new SlackAttachment("Usage: `" + requestDoc.Command + " correct @jsmith Blue skies`")
                };
                return(responseDoc);
            }

            SlackResponseDoc delayedResponseDoc = new SlackResponseDoc
            {
                ResponseType = SlackResponseType.IN_CHANNEL,
                Text         = text
            };

            _delayedSlackService.sendResponse(requestDoc.ResponseUrl, delayedResponseDoc);

            return(new SlackResponseDoc
            {
                ResponseType = SlackResponseType.EPHEMERAL,
                Text = "Score updated."
            });
        }