public async Task ListSpecies() { // Get all species. List <Species> species = new List <Species>(); using (SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM Species;")) using (DataTable table = await Database.GetRowsAsync(cmd)) foreach (DataRow row in table.Rows) { species.Add(await SpeciesUtils.SpeciesFromDataRow(row)); } // If there are no species, state so. if (species.Count <= 0) { await BotUtils.ReplyAsync_Info(Context, "No species have been added yet."); return; } // Create embed pages. species.Sort((lhs, rhs) => lhs.ShortName.CompareTo(rhs.ShortName)); List <EmbedBuilder> pages = EmbedUtils.SpeciesListToEmbedPages(species, fieldName: string.Format("All species ({0}):", species.Count())); // Send the result. Bot.PaginatedMessage reply = new Bot.PaginatedMessage(); foreach (EmbedBuilder page in pages) { reply.Pages.Add(page.Build()); } await Bot.DiscordUtils.SendMessageAsync(Context, reply); }
public async Task TrophyList() { int total_trophies = (await Global.TrophyRegistry.GetTrophiesAsync()).Count; int trophies_per_page = 8; int total_pages = (int)Math.Ceiling((float)total_trophies / trophies_per_page); int current_page = 0; int current_page_trophy_count = 0; Bot.PaginatedMessage message = new Bot.PaginatedMessage(); EmbedBuilder embed = null; IReadOnlyCollection <Trophy> trophy_list = await Global.TrophyRegistry.GetTrophiesAsync(); foreach (Trophy trophy in trophy_list) { if (current_page_trophy_count == 0) { ++current_page; embed = new EmbedBuilder(); embed.WithTitle(string.Format("All Trophies ({0})", (await Global.TrophyRegistry.GetTrophiesAsync()).Count)); embed.WithDescription(string.Format("For more details about a trophy, use `?trophy <name>` (e.g. `{0}trophy \"{1}\"`).", OurFoodChainBot.Instance.Config.Prefix, trophy_list.First().GetName())); embed.WithFooter(string.Format("Page {0} of {1}", current_page, total_pages)); embed.WithColor(new Color(255, 204, 77)); } double completion_rate = await Global.TrophyRegistry.GetCompletionRateAsync(trophy); string description = (trophy.Flags.HasFlag(TrophyFlags.Hidden) && completion_rate <= 0.0) ? string.Format("_{0}_", OurFoodChain.Trophies.Trophy.HIDDEN_TROPHY_DESCRIPTION) : trophy.GetDescription(); // If this was a first-time trophy, show who unlocked it. if (trophy.Flags.HasFlag(TrophyFlags.OneTime) && completion_rate > 0.0) { TrophyUser[] user_ids = await Global.TrophyRegistry.GetUsersUnlockedAsync(trophy); if (user_ids.Count() > 0 && !(Context.Guild is null)) { IGuildUser user = await Context.Guild.GetUserAsync(user_ids.First().UserId); if (!(user is null)) { description += string.Format(" (unlocked by {0})", user.Mention); } } } embed.AddField(string.Format("{0} **{1}** ({2:0.#}%)", trophy.GetIcon(), trophy.name, completion_rate), description); ++current_page_trophy_count; if (current_page_trophy_count >= trophies_per_page) { message.Pages.Add(embed.Build()); current_page_trophy_count = 0; } } // Add the last embed to the message. if (!(embed is null)) { message.Pages.Add(embed.Build()); } await Bot.DiscordUtils.SendMessageAsync(Context, message); }
public async Task ListSpecies(string taxonName) { // Get the taxon. Taxon taxon = await BotUtils.GetTaxonFromDb(taxonName); if (taxon is null) { await BotUtils.ReplyAsync_Error(Context, "No such taxon exists."); return; } // Get all species under that taxon. List <Species> species = new List <Species>(); species.AddRange(await BotUtils.GetSpeciesInTaxonFromDb(taxon)); species.Sort((lhs, rhs) => lhs.FullName.CompareTo(rhs.FullName)); // We might get a lot of species, which may not fit in one embed. // We'll need to use a paginated embed to reliably display the full list. // Create embed pages. List <EmbedBuilder> pages = EmbedUtils.SpeciesListToEmbedPages(species, fieldName: string.Format("Species in this {0} ({1}):", taxon.GetTypeName(), species.Count())); if (pages.Count <= 0) { pages.Add(new EmbedBuilder()); } // Add description to the first page. StringBuilder description_builder = new StringBuilder(); description_builder.AppendLine(taxon.GetDescriptionOrDefault()); if (species.Count() <= 0) { description_builder.AppendLine(); description_builder.AppendLine(string.Format("This {0} contains no species.", Taxon.GetRankName(taxon.type))); } // Add title to all pages. foreach (EmbedBuilder page in pages) { page.WithTitle(string.IsNullOrEmpty(taxon.CommonName) ? taxon.GetName() : string.Format("{0} ({1})", taxon.GetName(), taxon.GetCommonName())); page.WithDescription(description_builder.ToString()); page.WithThumbnailUrl(taxon.pics); } // Send the result. Bot.PaginatedMessage reply = new Bot.PaginatedMessage(); foreach (EmbedBuilder page in pages) { reply.Pages.Add(page.Build()); } await Bot.DiscordUtils.SendMessageAsync(Context, reply); }
public async Task Map() { // Get map images from the database. Gallery gallery = await GalleryUtils.GetGalleryAsync(MAP_GALLERY_NAME); Picture primary = null; Picture labeled = null; if (!(gallery is null)) { primary = await BotUtils.GetPicFromDb(gallery, "primary"); labeled = await BotUtils.GetPicFromDb(gallery, "labeled"); } // If no primary image has been provided, display an error message. if (primary is null) { await BotUtils.ReplyAsync_Error(Context, string.Format("No map images have been set. Use the \"{0}setmap\" command to set map images.", OurFoodChainBot.Instance.Config.Prefix)); return; } // Build the embed. string worldName = OurFoodChainBot.Instance.Config.WorldName; string title = string.IsNullOrEmpty(worldName) ? "" : string.Format("Map of {0}", StringUtils.ToTitleCase(worldName)); string footer = (labeled is null) ? "" : "Click the Z reaction to toggle zone labels."; Bot.PaginatedMessage paginatedMessage = new Bot.PaginatedMessage(); // Add the first page (primary image without zone labels). paginatedMessage.Pages.Add(new EmbedBuilder { Title = title, ImageUrl = primary.url, Footer = new EmbedFooterBuilder { Text = footer } }.Build()); // A second page (with zone labels) is only included in the case an image has been provided. if (!(labeled is null)) { paginatedMessage.Pages.Add(new EmbedBuilder { Title = title, ImageUrl = labeled.url, Footer = new EmbedFooterBuilder { Text = footer } }.Build()); } // Send the embed. paginatedMessage.PrevEmoji = string.Empty; paginatedMessage.NextEmoji = string.Empty; if (paginatedMessage.Pages.Count > 1) { paginatedMessage.ToggleEmoji = "🇿"; } await Bot.DiscordUtils.SendMessageAsync(Context, paginatedMessage); }