Esempio 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));
        }
Esempio n. 2
0
        private async Task <DialogTurnResult> PromptReplyToInsult(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            NewInsultQnA newInsultQnA = (NewInsultQnA)stepContext.Options;

            // First time around. Ask for response
            bool addInsult = (bool)stepContext.Result;

            if (addInsult)
            {
                var reply = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_NEW_INSULT_REPLY, _brain.GetBastardDBContext());

                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions()
                {
                    Prompt = MessageFactory.Text(string.Format(reply, newInsultQnA.Insults.Last())),
                    RetryPrompt = MessageFactory.Text("Seriously, what should I say?")
                }));
            }
            else
            {
                // User doesn't want to add it. Abort. Next prompt will have this text

                var reply = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_ENDING_DISAPPOINT, _brain.GetBastardDBContext());

                return(await stepContext.EndDialogAsync(reply, cancellationToken));
            }
        }
Esempio n. 3
0
        private async Task <DialogTurnResult> ConfirmNewInsultQnA(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            NewInsultQnA newInsultQnA = (NewInsultQnA)stepContext.Values[BotConstants.STEP_VALUES_NEW_INSULT_KEY];

            // Confirm it's saved
            var reply = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_INSULT_ADDED, _brain.GetBastardDBContext());

            await stepContext.Context.SendActivityAsync(
                MessageFactory.Text(string.Format(reply, newInsultQnA.InsultResponse)),
                cancellationToken
                );

            // New new insult QnA to SQL
            await _brain.AddNewInsultQnA(newInsultQnA);

            // Done
            var text = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_ALL_DONE, _brain.GetBastardDBContext());

            await stepContext.Context.SendActivityAsync(
                MessageFactory.Text(text),
                cancellationToken
                );

            // For next main diag loop, preface with this...
            return(await stepContext.EndDialogAsync("Hit me again", cancellationToken));
        }
        public void ShouldFindTwoWordPhrase()
        {
            var wordsList       = new[] { "some", "random", "word" };
            var hashes          = new[] { "90c234e95bce297cb5c382b9091c5a29" };
            var anagram         = "medo somran";
            var phraseGenerator = new PhraseGenerator(anagram, wordsList);
            var finder          = new SecretPhrasesFinder(phraseGenerator, hashes);
            var results         = finder.FindSecretPhrases();

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual($"some random {hashes[0]}", results[0]);
        }
        public void ShouldFindOneWordPhrase()
        {
            var wordsList       = new[] { "some", "random", "word" };
            var hashes          = new[] { "7ddf32e17a6ac5ce04a8ecbf782ca509" };
            var anagram         = "domran";
            var phraseGenerator = new PhraseGenerator(anagram, wordsList);
            var finder          = new SecretPhrasesFinder(phraseGenerator, hashes);
            var results         = finder.FindSecretPhrases();

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual($"random {hashes[0]}", results[0]);
        }
Esempio n. 6
0
        /// <summary>
        /// Generates and returns a password as a protected string.
        /// </summary>
        /// <param name="prf">Password profile.</param>
        /// <param name="crsRandomSource">Cryptographic random source.</param>
        /// <returns>The generated password.</returns>
        public override ProtectedString Generate(PwProfile prf, CryptoRandomStream crsRandomSource)
        {
            UserConfig              config           = UserConfig.Deserialize(prf.CustomAlgorithmOptions);
            SystemConfig            sysConfig        = new SystemConfig();
            RandomUtil              random           = new RandomUtil(crsRandomSource);
            IRepositoryFactory      factory          = new FileRepositoryFactory(config, sysConfig);
            IPhraseRepository       repo             = factory.Make(random);
            ISpecialCharsRepository specialCharsRepo = factory.MakeSpecialChars(random);

            IPhraseGenerator generator = new PhraseGenerator(config, repo, specialCharsRepo);

            return(generator.Generate());
        }
Esempio n. 7
0
        private async Task <DialogTurnResult> NewInsult(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            NewInsultQnA newInsultQnA = (NewInsultQnA)stepContext.Options;

            // Save new QnA to session
            stepContext.Values.Add(BotConstants.STEP_VALUES_NEW_INSULT_KEY, newInsultQnA);

            var askToHelp = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_NEW_INSULT_START, _brain.GetBastardDBContext());

            return(await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions
            {
                Prompt = MessageFactory.Text(string.Format(askToHelp, newInsultQnA.Insults.First())),
                RetryPrompt = MessageFactory.Text("Need some actual text here")
            }, cancellationToken));
        }
Esempio n. 8
0
        public void ShouldReturnJustValidPhrases()
        {
            var anagram              = "some random word";
            var wordsList            = new[] { "some", "random", "word", "none", "ran" };
            var allCombinationsCount = 6;
            var phraseGenerator      = new PhraseGenerator(anagram, wordsList);

            var allPhrases = phraseGenerator.GetUniquePhrases(0, phraseGenerator.WordsInListCount - 1).ToArray();

            foreach (var phrase in allPhrases)
            {
                Console.WriteLine(phrase);
            }

            Assert.AreEqual(allCombinationsCount, allPhrases.Length);
        }
Esempio n. 9
0
        public void ShouldReturnAllPhrasesWhenAllWordsSameLenght()
        {
            var anagram              = "abcd acbd adbc";
            var wordsList            = new[] { "abcd", "acbd", "adbc", "bcad", "badc", "cadb", "cbda", "dabc", "dbac", "dcab" };
            var phraseGenerator      = new PhraseGenerator(anagram, wordsList);
            var allCombinationsCount = 10 * 9 * 8;

            var allPhrases = phraseGenerator.GetUniquePhrases(0, phraseGenerator.WordsInListCount - 1).ToArray();

            foreach (var phrase in allPhrases)
            {
                Console.WriteLine(phrase);
            }

            Assert.AreEqual(allCombinationsCount, allPhrases.Length);
        }
        public void ShouldFindThreeWordPhrase()
        {
            var wordsList       = new[] { "yups", "tortola", "untwist", "yuan", "tuna", "tutor", "tosup", "yawls", "stout", "printout" };
            var hashes          = new[] { "e4820b45d2277f3844eac66c903e84be" };
            var anagram         = "poultry outwits ants";
            var phraseGenerator = new PhraseGenerator(anagram, wordsList);
            var finder          = new SecretPhrasesFinder(phraseGenerator, hashes);
            var results         = finder.FindSecretPhrases();

            foreach (var result in results)
            {
                Console.WriteLine(result);
            }

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual($"printout stout yawls {hashes[0]}", results[0]);
        }
Esempio n. 11
0
        private async Task <DialogTurnResult> AskForNextInsult(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            NewInsultQnA newInsultQnA = (NewInsultQnA)stepContext.Options;


            // Save new QnA to session
            stepContext.Values.Add(BotConstants.STEP_VALUES_NEW_INSULT_KEY, newInsultQnA);


            var reply = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_NEXT_INSULT_PROMPT, _context);

            return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions()
            {
                Prompt = MessageFactory.Text(string.Format(reply, newInsultQnA.InsultResponse)),
                RetryPrompt = MessageFactory.Text("Seriously, what should I say?")
            }));
        }
Esempio n. 12
0
        private async Task <DialogTurnResult> AddInsultResponse(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            NewInsultQnA newInsultQnA = (NewInsultQnA)stepContext.Values[BotConstants.STEP_VALUES_NEW_INSULT_KEY];

            string insultReply = (string)stepContext.Result;

            newInsultQnA.InsultResponse = insultReply;

            // Send adaptive card with new QnA
            await CommonDialogMessages.SendConfirmQnACard(stepContext, cancellationToken, newInsultQnA);

            var text = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_MORE_INSULTS_QUESTION, _brain.GetBastardDBContext());

            return(await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions()
            {
                Prompt = MessageFactory.Text(text),
                RetryPrompt = MessageFactory.Text($"Seriously, what other insults should I reply '{newInsultQnA.InsultResponse}' to?")
            }));
        }
Esempio n. 13
0
        private async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Hard-coded responses
            bool abortDialogue = await HandleHardCodedResponses(stepContext, cancellationToken);

            if (abortDialogue)
            {
                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }

            // Call LUIS and gather any potential booking details. (Note the TurnContext has the response to the prompt.)
            var luisResult = await _luisRecognizer.RecognizeAsync <BastardTalk>(stepContext.Context, cancellationToken);

            switch (luisResult.TopIntent().intent)
            {
            case BastardTalk.Intent.InsultMe:

                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text("Oh, an insult! Here's one someone taught me..."),
                    cancellationToken);

                await GenerateInsultFromQnA(stepContext, cancellationToken);

                return(await GetQnAResponseFromInput(stepContext, cancellationToken));

            case BastardTalk.Intent.ComplementInsult:
                var likedResponse = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_INSULT_LIKED, _brain.GetBastardDBContext());

                return(await stepContext.NextAsync(likedResponse, cancellationToken));

            case BastardTalk.Intent.DismissInsult:
                var dislikedResponse = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_INSULT_LIKED, _brain.GetBastardDBContext());

                return(await stepContext.NextAsync(dislikedResponse, cancellationToken));

            default:
                // Handle with QnA
                return(await GetQnAResponseFromInput(stepContext, cancellationToken));
            }

            // Should never arrive here
            throw new Exception("wtf");
        }
Esempio n. 14
0
        private async Task <DialogTurnResult> AskIfMore(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            string newInsult = (string)stepContext.Result;

            NewInsultQnA newInsultQnA = (NewInsultQnA)stepContext.Values[BotConstants.STEP_VALUES_NEW_INSULT_KEY];

            newInsultQnA.Insults.Add(newInsult);

            // Send adaptive card with new QnA
            await CommonDialogMessages.SendConfirmQnACard(stepContext, cancellationToken, newInsultQnA);


            var reply = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_MORE_INSULTS_QUESTION, _context);

            return(await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions
            {
                Prompt = MessageFactory.Text(reply),
                RetryPrompt = MessageFactory.Text("Soooo...more?")
            }, cancellationToken));
        }
Esempio n. 15
0
 void Awake()
 {
     textMan   = GetComponent <TextManager>();
     phraseGen = GetComponent <PhraseGenerator>();
 }
Esempio n. 16
0
        public void TestGenerate()
        {
            var generator = new PhraseGenerator(this.config, this.repo, this.specialCharsRepo);

            Assert.AreEqual("foo foo foo foo foo foo", generator.Generate().ReadString(), "Assert that the generated password matches expectations.");
        }
Esempio n. 17
0
        public void TestInterface()
        {
            var generator = new PhraseGenerator(this.config, this.repo, this.specialCharsRepo);

            Assert.IsInstanceOf(typeof(IPhraseGenerator), generator, "Assert that the generator implements the expected interface.");
        }
 public void SetUp()
 {
     phraseGenerator = new PhraseGenerator();
 }