예제 #1
0
        private static async Task HandleInfographicInvocation(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            Regex typeLookupRegex = new Regex($"^!\\w+ \"?([^\"]+)\"?$", RegexOptions.IgnoreCase);
            Match typeLookupMatch = typeLookupRegex.Match(turnContext.Activity.Text);
            var   searchTerm      = ((typeLookupMatch.Success && typeLookupMatch.Groups.Count >= 2) ? typeLookupMatch.Groups[1].Value : "").ToLowerInvariant();

            var raids = await PokeBattlerApi.GetRaids();

            var results = raids.Where(raid =>
                                      !string.IsNullOrEmpty(raid.Article?.InfographicURL) &&
                                      !searchTerm.Replace("-", " ").Split(" ").Except(raid.Pokemon.ToLowerInvariant().Replace("_", " ").Split(" ")).Any()
                                      );

            TextInfo ti = new CultureInfo("en-US", false).TextInfo;

            if (results.Any())
            {
                bool pluralize = results.Count() > 1;

                await turnContext.SendActivityAsync(MessageFactory.Text($"Here's {(pluralize ? "infographics" : " an infographic")} with details about {ti.ToTitleCase(searchTerm)}, courtesy of Pokebattler."));

                await turnContext.SendActivitiesAsync(
                    results
                    .Select(result =>
                            MessageFactory.Attachment(new Attachment("image/png", result.Article.InfographicURL)) as IActivity
                            )
                    .ToArray()
                    );
            }
            else
            {
                await turnContext.SendActivityAsync(MessageFactory.Text($"Sorry, but Pokebattler doesn't currently appear to have an infographic for {ti.ToTitleCase(searchTerm)}"), cancellationToken);
            }
        }
예제 #2
0
        private static async Task HandleRaidBossesInvocation(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            await turnContext.SendActivityAsync(MessageFactory.Text(Constants.RaidBossesMessage), cancellationToken);

            var tierFiveRaids = await PokeBattlerApi.GetRaids(tier : 5);

            if (tierFiveRaids.All(raid => !string.IsNullOrEmpty(raid.Article?.InfographicURL)))
            {
                bool pluralize = tierFiveRaids.Count() > 1;

                await turnContext.SendActivityAsync(MessageFactory.Text($"Here's {(pluralize ? "infographics" : " an infographic")} with details about the current tier-five raid {(pluralize ? "bosses" : "boss")}, courtesy of Pokebattler."));

                await turnContext.SendActivitiesAsync(
                    tierFiveRaids
                    .Select(raid =>
                            MessageFactory.Attachment(new Attachment("image/png", raid.Article.InfographicURL)) as IActivity
                            )
                    .ToArray()
                    );
            }
        }