コード例 #1
0
        public async Task <ITaxon> ReplyNoSuchTaxonExistsAsync(string input, ITaxon suggestion, TaxonRankType rank = TaxonRankType.None)
        {
            string taxonName = rank == TaxonRankType.None ? "taxon" : rank.GetName();

            if (suggestion != null)
            {
                taxonName = suggestion.GetRank().GetName();
            }

            StringBuilder sb = new StringBuilder();

            if (string.IsNullOrWhiteSpace(input))
            {
                sb.Append($"No such {taxonName} exists.");
            }
            else
            {
                sb.Append($"No {taxonName} named \"{input}\" exists.");
            }

            if (suggestion != null)
            {
                string suggestionText = (suggestion is ISpecies species) ? species.GetFullName() : suggestion.GetName().ToTitle();

                sb.Append($" Did you mean **{suggestionText}**?");
            }

            IPaginatedMessage message = new PaginatedMessage(sb.ToString())
            {
                Restricted = true
            };

            if (suggestion != null)
            {
                bool confirmed = false;

                message.AddReaction(PaginatedMessageReactionType.Yes, async(args) => {
                    confirmed = true;

                    await Task.CompletedTask;
                });

                await ReplyAndWaitAsync(message);

                if (!confirmed)
                {
                    suggestion = null;
                }
            }
            else
            {
                await ReplyAsync(message);
            }

            return(suggestion);
        }
コード例 #2
0
        private async Task ReplyAddTaxonAsync(TaxonRankType rank, string taxonName, string description)
        {
            // Make sure that the taxon does not already exist before trying to add it.

            ITaxon taxon = (await Db.GetTaxaAsync(taxonName, rank)).FirstOrDefault();

            if (taxon.IsValid())
            {
                await ReplyWarningAsync($"The {rank.GetName()} **{taxon.GetName()}** already exists.");
            }
            else
            {
                taxon = new Common.Taxa.Taxon(rank, taxonName)
                {
                    Name        = taxonName,
                    Description = description
                };

                await Db.AddTaxonAsync(taxon);

                await ReplySuccessAsync($"Successfully created new {rank.GetName()}, **{taxon.GetName()}**.");
            }
        }
コード例 #3
0
        public async Task ReplyTaxonAsync(TaxonRankType rank)
        {
            // List all taxa of the given rank.

            IEnumerable <ITaxon> taxa  = (await Db.GetTaxaAsync(rank)).OrderBy(t => t.GetName());
            List <string>        lines = new List <string>();

            foreach (ITaxon taxon in taxa)
            {
                // Count the number of items under this taxon.

                int subtaxaCount = (await Db.GetSubtaxaAsync(taxon)).Count();

                if (subtaxaCount > 0)
                {
                    lines.Add($"{taxon.GetName().ToTitle()} ({subtaxaCount})");
                }
            }

            if (lines.Count() <= 0)
            {
                await ReplyInfoAsync($"No {rank.GetName(true)} have been added yet.");
            }
            else
            {
                string title = $"All {rank.GetName(true)} ({lines.Count()})";

                IEnumerable <Discord.Messaging.IEmbed> pages = EmbedUtilities.CreateEmbedPages(title.ToTitle(), lines, options: EmbedPaginationOptions.AddPageNumbers);

                foreach (Discord.Messaging.IEmbed page in pages)
                {
                    page.Footer += $" — Empty {rank.GetName(true)} are not listed.";
                }

                await ReplyAsync(new PaginatedMessage(pages));
            }
        }