Пример #1
0
        public async Task TopPlayersPositionAvailable(IDialogContext context, LuisResult result)
        {
            await context.PostAsync("Let me take a look...");

            DBConnector            _dbconnector        = new DBConnector();
            BingImageSearchService _imageSearchService = new BingImageSearchService();

            string message = "";

            if (result.Entities.Count > 0)
            {
                string position = result.Entities.Where(e => e.Type == "Position").FirstOrDefault().Entity.ToUpper();
                int    number   = 0;
                int.TryParse(result.Entities.Where(e => e.Type == "builtin.number").FirstOrDefault().Entity, out number);
                if (string.IsNullOrEmpty(position))
                {
                    message = "Didn't get the position...could you please try again?";
                    await PostMessage(context, message);
                }
                else
                {
                    List <Predictions> predictions = new List <Predictions>();
                    if (number > 0)
                    {
                        predictions = await _dbconnector.GetAvailableTopPlayersByPosition(position, number);

                        await context.PostAsync($"These are the top {number} {position}s available:");
                    }
                    else
                    {
                        predictions = await _dbconnector.GetAvailablePlayersByPosition(position);

                        message = $"These are all the {position}s available:\n";
                    }

                    List <Attachment> attachments = new List <Attachment>();
                    foreach (Predictions p in predictions)
                    {
                        string picture = await _imageSearchService.GetPlayerPhotoByName(p.Player);

                        Attachment attachment = CreateThumbnailCard(picture, p, false);
                        attachments.Add(attachment);
                    }
                    await ReplyWithCards(context, attachments);
                }
            }
            else
            {
                message = "Something went wrong...could you please try again?";
                await PostMessage(context, message);
            }
        }
Пример #2
0
        public async Task PlayerOverview(IDialogContext context, LuisResult result)
        {
            await context.PostAsync("Looking for him, give me a sec...");

            DBConnector            _dbconnector        = new DBConnector();
            BingImageSearchService _imageSearchService = new BingImageSearchService();
            BingNewsSearchService  _newsSearchService  = new BingNewsSearchService();

            string message = "";

            if (result.Entities.Count > 0)
            {
                string      playerName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(result.Entities.Where(e => e.Type == "Player").FirstOrDefault().Entity);
                Predictions playerInfo = await _dbconnector.GetPlayerInfoByName(playerName);

                if (string.IsNullOrEmpty(playerName) || playerInfo == null)
                {
                    message = "I'm afraid I don't know this player...could you please try again?";
                    await PostMessage(context, message);
                }
                else
                {
                    var picture = await _imageSearchService.GetPlayerPhotoByName(playerInfo.Player);

                    List <NewsValue> news = await _newsSearchService.GetPlayerNewsByName(playerInfo.Player);

                    Attachment        card         = CreateOverviewCard(picture, playerInfo);
                    List <Attachment> newsCarousel = CreateNewsCarousel(news);

                    await context.PostAsync("Got it!");
                    await ReplyWithCardAndNews(context, card, newsCarousel);
                }
            }
            else
            {
                message = "I'm afraid I don't know this player...could you please try again?";
                await PostMessage(context, message);
            }
        }