Beispiel #1
0
 public BastardBot(ConversationState conversationState, UserState userState, T dialog, BastardDBContext bastardDB)
 {
     ConversationState = conversationState;
     UserState         = userState;
     Dialog            = dialog;
     _database         = bastardDB;
 }
Beispiel #2
0
 public FunctionAppBastardBrain(IConfiguration config)
 {
     _settings       = new SystemSettings(config);
     _context        = new BastardDBContext(config.GetConnectionString("DefaultConnection"));
     _qnAMakerClient = new QnAMakerClient(new ApiKeyServiceClientCredentials(_settings.QnASubscriptionKey))
     {
         Endpoint = _settings.QnAMakerHost
     };
 }
Beispiel #3
0
 public AddMoreInsultsForResponseDialog(BastardDBContext context) : base(nameof(AddMoreInsultsForResponseDialog))
 {
     AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
     {
         AskForNextInsult,
         AskIfMore,
         RepeatIfNeeded
     }));
     AddDialog(new TextPrompt(nameof(TextPrompt), InsultValidator));
     AddDialog(new ConfirmPrompt(nameof(ConfirmPrompt)));
     _context = context;
 }
Beispiel #4
0
        public static async Task <string> GetPhrase(string category, BastardDBContext context)
        {
            var cat = await context.ChatPhraseCategories.SingleOrDefaultAsync(p => p.Text == category);

            if (cat == null)
            {
                throw new ArgumentOutOfRangeException(nameof(category));
            }

            int          phrasesWithCat = context.ChatPhrases.Where(p => p.Category == cat).Count();
            int          toSkip         = rand.Next(0, phrasesWithCat);
            DialogPhrase randomPhrase   = null;

            if (phrasesWithCat == 0)
            {
                NoPhraseByCategory(category);
            }
            else if (phrasesWithCat == 1)
            {
                randomPhrase = await context.ChatPhrases.Where(p => p.Category == cat)
                               .SingleOrDefaultAsync();
            }
            else
            {
                randomPhrase = await context.ChatPhrases.Where(p => p.Category == cat)
                               .Skip(toSkip)
                               .Take(1)
                               .FirstAsync();
            }


            if (randomPhrase == null)
            {
                NoPhraseByCategory(category);
            }

            return(randomPhrase.Text);
        }