Ejemplo n.º 1
0
        private async Task <DialogTurnResult> ShowQnAInsultAndGetAnother(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            string qnaInsultResult = (string)stepContext.Result;
            string msg             = qnaInsultResult;

            // Get state from options and save last insult
            var state = (MainDiagState)stepContext.Values[BotConstants.STEP_VALUES_MAIN_STATE_KEY];

            // 1st time around, this won't be set
            if (state == null)
            {
                state = new MainDiagState();
                stepContext.Values[BotConstants.STEP_VALUES_MAIN_STATE_KEY] = state;
            }

            if (!string.IsNullOrEmpty(state.LastInsult) && state.LastInsult == qnaInsultResult)
            {
                state.LastInsult = qnaInsultResult;
                var asISaid = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_AS_I_SAID_BEFORE, _brain.GetBastardDBContext());

                msg = $"{asISaid}, {qnaInsultResult}. Try another one. {GetRandomTrainedInsult()}";
            }
            // Remember last insult
            state.LastInsult = qnaInsultResult;

            // Ask for another insult, giving response to last insult supplied
            return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions()
            {
                Prompt = MessageFactory.Text(msg)
            }, cancellationToken));
        }
Ejemplo n.º 2
0
        private async Task <DialogTurnResult> CheckAccepted(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            MainDiagState state = (MainDiagState)stepContext.Values[BotConstants.STEP_VALUES_MAIN_STATE_KEY];

            if (state == null || !state.AcceptedConditions)
            {
                var response = (FoundChoice)stepContext.Result;
                if (response.Value == BotConstants.CHOICE_SAUL_GOODMAN)
                {
                    // Let battle commence!
                    await stepContext.Context.SendActivityAsync(MessageFactory.Text("Awesome. My job is to be a bastard & insult whoever wants to chat to me."), cancellationToken);

                    await stepContext.Context.SendActivityAsync(MessageFactory.Text("Insult me and I'll reply. If it's a new insult, you can teach me it if you want. Round 1: here goes!"), cancellationToken);

                    var startingInsult = await GetRandomTrainedInsult();

                    // Goad them to continue
                    var intro2 = new List <string>()
                    {
                        "Your turn.",
                        "Bring it.",
                        "Bring it on.",
                        "Fight me, bitch.",
                        "Now fight me.",
                        "That's right."
                    };
                    int toSkip2        = randomSelecta.Next(0, intro2.Count);
                    var randomFollowup = intro2.Skip(toSkip2).Take(1).First();

                    return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
                    {
                        Prompt = MessageFactory.Text($"'{startingInsult}'. {randomFollowup}"),
                        RetryPrompt = MessageFactory.Text("Seriously, bring it")
                    }));
                }
                else
                {
                    await stepContext.Context.SendActivityAsync(MessageFactory.Text("Probably for the best. Top of the day to you!"), cancellationToken);

                    return(await stepContext.EndDialogAsync(null, cancellationToken));
                }
            }
            else
            {
                // Not first time around. Skip disclaimer steps
                return(await stepContext.NextAsync(new Choice(BotConstants.CHOICE_SAUL_GOODMAN), cancellationToken));
            }
        }
Ejemplo n.º 3
0
        private async Task <DialogTurnResult> ShowConditions(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Get state from options and save. If null, save anyway so dictionary calls won't have to check if key exists.
            MainDiagState state = (MainDiagState)stepContext.Options;

            stepContext.Values.Add(BotConstants.STEP_VALUES_MAIN_STATE_KEY, state);

            if (state == null || !state.AcceptedConditions)
            {
                // Send adaptive card with disclaimer
                var adaptiveCard           = CardGenerator.GetDisclaimerCard();
                var adaptiveCardAttachment = new Attachment()
                {
                    ContentType = "application/vnd.microsoft.card.adaptive",
                    Content     = adaptiveCard,
                };
                var promptMessageSummary = MessageFactory.Attachment(adaptiveCardAttachment, "Hi! I'm BastardBot. Before we begin...");
                await stepContext.Context.SendActivityAsync(promptMessageSummary, cancellationToken);

                // Check S'all Good, Man
                string msg           = $"All good?";
                var    promptMessage = MessageFactory.Text(msg, msg, InputHints.ExpectingInput);
                return(await stepContext.PromptAsync(nameof(ChoicePrompt), new PromptOptions
                {
                    Prompt = promptMessage,
                    Choices = new List <Choice>
                    {
                        new Choice {
                            Value = BotConstants.CHOICE_SAUL_GOODMAN
                        },
                        new Choice {
                            Value = "I'm not Sure"
                        }
                    }
                }, cancellationToken));
            }
            else
            {
                // Not first time around. Skip disclaimer steps
                return(await stepContext.NextAsync(new Choice(BotConstants.CHOICE_SAUL_GOODMAN), cancellationToken));
            }
        }