public static async Task <Bot.PaginatedMessageBuilder> BuildRecentEventsEmbedAsync(long startTimestamp, long endTimestamp, TimeUnits timeUnit = 0) { // Get all species created within the given timespan. List <Species> new_species = new List <Species>(); TimeAmount time_amount = new TimeAmount(endTimestamp - startTimestamp, TimeUnits.Seconds); if (timeUnit != 0) { time_amount = time_amount.ConvertTo(timeUnit); } else { time_amount = time_amount.Reduce(); } using (SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM Species WHERE timestamp >= $start_ts AND timestamp < $end_ts")) { cmd.Parameters.AddWithValue("$start_ts", startTimestamp); cmd.Parameters.AddWithValue("$end_ts", endTimestamp); using (DataTable table = await Database.GetRowsAsync(cmd)) foreach (DataRow row in table.Rows) { new_species.Add(await SpeciesUtils.SpeciesFromDataRow(row)); } } new_species.Sort(); // Get all extinctions that occurred recently. List <Species> extinct_species = new List <Species>(); using (SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM Extinctions WHERE timestamp >= $start_ts AND timestamp < $end_ts")) { cmd.Parameters.AddWithValue("$start_ts", startTimestamp); cmd.Parameters.AddWithValue("$end_ts", endTimestamp); using (DataTable table = await Database.GetRowsAsync(cmd)) foreach (DataRow row in table.Rows) { extinct_species.Add(await BotUtils.GetSpeciesFromDb(row.Field <long>("species_id"))); } } extinct_species.Sort(); // Build embed. Bot.PaginatedMessageBuilder embed = new Bot.PaginatedMessageBuilder(); List <EmbedBuilder> pages = new List <EmbedBuilder>(); List <string> field_lines = new List <string>(); if (new_species.Count() > 0) { foreach (Species sp in new_species) { field_lines.Add(sp.FullName); } EmbedUtils.AddLongFieldToEmbedPages(pages, field_lines, fieldName: string.Format("New species ({0})", new_species.Count())); field_lines.Clear(); } if (extinct_species.Count() > 0) { foreach (Species sp in extinct_species) { field_lines.Add(sp.FullName); } EmbedUtils.AddLongFieldToEmbedPages(pages, field_lines, fieldName: string.Format("Extinctions ({0})", extinct_species.Count())); field_lines.Clear(); } embed.AddPages(pages); embed.SetTitle(string.Format("Recent events ({0})", time_amount.ToString())); embed.SetFooter(string.Empty); // remove page numbers added automatically embed.AddPageNumbers(); if (embed.FieldCount <= 0) { embed.SetDescription("No events"); } return(embed); }