private async Task ApplyPostMatchModifierAsync(SearchQueryResult result, string modifier) { int split_index = modifier.IndexOf(':'); string name = modifier.Substring(0, split_index).Trim(); string value = modifier.Substring(split_index + 1, modifier.Length - split_index - 1).Trim(); bool subtract = name.Length > 0 ? name[0] == '-' : false; if (name.StartsWith("-")) { name = name.Substring(1, name.Length - 1); } // Trim outer quotes from the value. if (value.Length > 0 && value.First() == '"' && value.Last() == '"') { value = value.Trim('"'); } switch (name) { case "groupby": case "group": // Applies grouping to the species based on the given attribute. switch (value.ToLower()) { case "z": case "zones": case "zone": await result.GroupByAsync(async (x) => { return((await BotUtils.GetZonesFromDb(x.Id)).Select(z => z.GetFullName()).ToArray()); }); break; case "g": case "genus": await result.GroupByAsync((x) => { return(Task.FromResult(new string[] { x.GenusName })); }); break; case "f": case "family": await result.GroupByAsync(async (x) => { Taxon taxon = (await BotUtils.GetFullTaxaFromDb(x)).Family; return(new string[] { taxon is null ? "N/A" : taxon.GetName() }); }); break;
public async Task Taxonomy(string genus, string species) { Species sp = await BotUtils.ReplyFindSpeciesAsync(Context, genus, species); if (sp is null) { return; } EmbedBuilder embed = new EmbedBuilder(); embed.WithTitle(string.Format("Taxonomy of {0}", sp.ShortName)); embed.WithThumbnailUrl(sp.Picture); TaxonSet set = await BotUtils.GetFullTaxaFromDb(sp); string unknown = "Unknown"; string genus_name = set.Genus is null ? unknown : set.Genus.GetName(); string family_name = set.Family is null ? unknown : set.Family.GetName(); string order_name = set.Order is null ? unknown : set.Order.GetName(); string class_name = set.Class is null ? unknown : set.Class.GetName(); string phylum_name = set.Phylum is null ? unknown : set.Phylum.GetName(); string kingdom_name = set.Kingdom is null ? unknown : set.Kingdom.GetName(); string domain_name = set.Domain is null ? unknown : set.Domain.GetName(); embed.AddField("Domain", domain_name, inline: true); embed.AddField("Kingdom", kingdom_name, inline: true); embed.AddField("Phylum", phylum_name, inline: true); embed.AddField("Class", class_name, inline: true); embed.AddField("Order", order_name, inline: true); embed.AddField("Family", family_name, inline: true); embed.AddField("Genus", genus_name, inline: true); embed.AddField("Species", StringUtils.ToTitleCase(sp.Name), inline: true); await ReplyAsync("", false, embed.Build()); }