Ejemplo n.º 1
0
        private async Task <bool> TryShowRandomFaceAsync(IDialogContext context)
        {
            var recentPeople = context.ConversationData.GetValueOrDefault(Constants.RECENT_PEOPLE_KEY, new List <string> {
            });

            if (recentPeople.Count == _people.Count)
            {
                return(false);
            }

            Person randomPerson;

            do
            {
                randomPerson = _people.GetRandomPerson();
            } while (recentPeople.Contains(randomPerson.Name));

            context.ConversationData.SetValue(Constants.LAST_PERSON_KEY, randomPerson);
            recentPeople.Add(randomPerson.Name);
            context.ConversationData.SetValue(Constants.RECENT_PEOPLE_KEY, recentPeople);

            var subtitle = (ConfigurationManager.AppSettings["DebugMode"] == "true")
                                ? $"(Debug) {randomPerson.Name} {recentPeople.Count}/{_people.Count}"
                                : $"{recentPeople.Count}/{_people.Count}";

            var card = new HeroCard("Who is this?", subtitle: subtitle, images: new List <CardImage>()
            {
                new CardImage(randomPerson.PhotoUrl)
            });

            var message = context.MakeMessage();

            message.Attachments.Add(card.ToAttachment());

            await context.PostAsync(message);

            return(true);
        }