예제 #1
0
        public Task AnswerQuizAsync([Remainder] string answer)
        {
            IUser user = this.Context.User;

            string response;

            lock (this.lockObject)
            {
                try
                {
                    AnswerToQuizResponseModel result = this.CommandsManager.AnswerToQuiz(user, answer);

                    if (!result.Success)
                    {
                        response = "Unfortunately you are not correct, that's not the answer to any of the active quizes.";
                    }
                    else
                    {
                        response = $"{user.Mention} bingo!" + Environment.NewLine +
                                   $"Question was `{result.QuizQuestion}`" + Environment.NewLine +
                                   $"And the answer is `{answer}`" + Environment.NewLine +
                                   $"Your reward of {result.Reward} {this.Settings.Ticker} was deposited to your account!" + Environment.NewLine +
                                   $"<@!{result.QuizCreatorDiscordUserId}>, your quiz was solved!";
                    }
                }
                catch (CommandExecutionException exception)
                {
                    response = "Error: " + exception.Message;
                }
            }

            return(this.ReplyAsync(response));
        }
예제 #2
0
        public void AnswerToQuiz_FailsIfHashNotCorrect()
        {
            this.testContext.CommandsManager.StartQuiz(this.caller, 2, Cryptography.Hash("1"), 2, string.Empty);

            AnswerToQuizResponseModel answer = this.testContext.CommandsManager.AnswerToQuiz(this.caller, "2");

            Assert.False(answer.Success);
        }
예제 #3
0
        public async Task AnswerQuizAsync([Remainder] string answer)
        {
            this.logger.Trace("({0}:'{1}')", nameof(answer), answer);

            IUser user = this.Context.User;

            string response;
            bool   deleteMessage = false;

            lock (this.lockObject)
            {
                try
                {
                    AnswerToQuizResponseModel result = this.CommandsManager.AnswerToQuiz(user, answer);

                    if (!result.Success)
                    {
                        response = "Unfortunately you are not correct, that's not the answer to any of the active quizes." +
                                   Environment.NewLine + Environment.NewLine +
                                   $"_`This and your message will be removed in {this.Settings.SelfDestructedMessagesDelaySeconds} seconds to avoid bloating the channel.`_";

                        this.MessagesHelper.SelfDestruct(this.Context.Message, this.Settings.SelfDestructedMessagesDelaySeconds);

                        deleteMessage = true;
                    }
                    else
                    {
                        response = $"{user.Mention} bingo!" + Environment.NewLine +
                                   $"Question was `{result.QuizQuestion}`" + Environment.NewLine +
                                   $"And the answer is `{answer}`" + Environment.NewLine +
                                   $"Your reward of {result.Reward} {this.Settings.Ticker} was deposited to your account!" + Environment.NewLine +
                                   $"<@!{result.QuizCreatorDiscordUserId}>, your quiz was solved!";
                    }
                }
                catch (CommandExecutionException exception)
                {
                    response = "Error: " + exception.Message;
                }
            }

            response = this.TrimMessage(response);

            if (deleteMessage)
            {
                await this.MessagesHelper.SendSelfDesctructedMessage(this.Context, response, false).ConfigureAwait(false);
            }
            else
            {
                await this.ReplyAsync(response).ConfigureAwait(false);
            }

            this.logger.Trace("(-)");
        }
예제 #4
0
        public void AnswerToQuiz_FailsIfTimeIsCorrectButExpired()
        {
            this.testContext.CommandsManager.StartQuiz(this.caller, 2, Cryptography.Hash("1"), 2, string.Empty);

            using (BotDbContext dbContext = this.testContext.CreateDbContext())
            {
                QuizModel quiz = dbContext.ActiveQuizes.First();
                quiz.CreationTime = DateTime.Now - TimeSpan.FromMinutes(20);
                dbContext.Update(quiz);
                dbContext.SaveChanges();
            }

            AnswerToQuizResponseModel answer = this.testContext.CommandsManager.AnswerToQuiz(this.caller, "1");

            Assert.False(answer.Success);
        }
예제 #5
0
        public void AnswerToQuiz_AnsweredCorrectly()
        {
            this.testContext.CommandsManager.StartQuiz(this.caller, 2, Cryptography.Hash("1"), 2, string.Empty);
            this.testContext.CommandsManager.StartQuiz(this.caller, 2, Cryptography.Hash("2"), 2, string.Empty);

            using (BotDbContext dbContext = this.testContext.CreateDbContext())
            {
                Assert.Equal(2, dbContext.ActiveQuizes.Count());
            }

            AnswerToQuizResponseModel answer = this.testContext.CommandsManager.AnswerToQuiz(this.caller, "1");

            Assert.True(answer.Success);

            using (BotDbContext dbContext = this.testContext.CreateDbContext())
            {
                Assert.Equal(1, dbContext.ActiveQuizes.Count());
            }
        }
예제 #6
0
        public void AnswerToQuiz_FailsIfAnswerTooLong()
        {
            AnswerToQuizResponseModel answer = this.testContext.CommandsManager.AnswerToQuiz(this.caller, RandomStringGenerator.RandomString(1025));

            Assert.False(answer.Success);
        }