public static async Task <IPaginatedMessage> BuildRecentEventsMessageAsync(this OfcModuleBase moduleBase, DateTimeOffset start, DateTimeOffset end)
        {
            IEnumerable <ISpecies> newSpecies     = (await moduleBase.Db.GetSpeciesAsync(start, end)).OrderBy(species => moduleBase.TaxonFormatter.GetString(species, false));
            IEnumerable <ISpecies> extinctSpecies = (await moduleBase.Db.GetExtinctSpeciesAsync(start, end)).OrderBy(species => moduleBase.TaxonFormatter.GetString(species, false));

            List <IEmbed> pages = new List <IEmbed>();

            if (newSpecies.Count() > 0)
            {
                EmbedUtilities.AppendEmbedPages(pages, EmbedUtilities.CreateEmbedPages($"New species ({newSpecies.Count()})", newSpecies.Select(species => moduleBase.TaxonFormatter.GetString(species))));
            }

            if (extinctSpecies.Count() > 0)
            {
                EmbedUtilities.AppendEmbedPages(pages, EmbedUtilities.CreateEmbedPages($"Extinctions ({extinctSpecies.Count()})", extinctSpecies.Select(species => moduleBase.TaxonFormatter.GetString(species, false))));
            }

            EmbedUtilities.AddPageNumbers(pages);

            if (pages.Count() <= 0)
            {
                pages.Add(new Embed()
                {
                    Description = "No events"
                });
            }

            foreach (IEmbed page in pages)
            {
                page.Title = $"Recent events ({DateUtilities.GetTimeSpanString(end - start)})";
            }

            IPaginatedMessage message = new PaginatedMessage(pages);

            return(message);
        }
示例#2
0
 public static void AddPageNumbers(this IPaginatedMessage message)
 {
     EmbedUtilities.AddPageNumbers(message.Select(page => page.Embed).Where(embed => embed != null));
 }