示例#1
0
        public async Task GetZoneType(string arg0)
        {
            if (!string.IsNullOrEmpty(arg0))
            {
                // If the given argument is a zone type, display information for that type.
                // If the given argument is a zone name, display information for the type corresponding to that zone.

                IZoneType type = await Db.GetZoneTypeAsync(arg0);

                if (!type.IsValid())
                {
                    // If no zone type exists with this name, attempt to get the type of the zone with this name.

                    IZone zone = await Db.GetZoneAsync(arg0);

                    if (zone != null)
                    {
                        type = await Db.GetZoneTypeAsync(zone.TypeId);
                    }
                }

                if (type.IsValid())
                {
                    // We got a valid zone type, so show information about the zone type.

                    IEnumerable <IZone> zones = await Db.GetZonesAsync(type);

                    string embedTitle       = string.Format("{0} {1} Zones ({2})", type.Icon, type.Name, zones.Count()).ToTitle();
                    string embedDescription = type.Description + "\n\n";

                    IEnumerable <IEmbed> pages = await BotUtils.ZonesToEmbedPagesAsync(embedTitle.Length + embedDescription.Length, zones, Db, showIcon : false);

                    foreach (IEmbed page in pages)
                    {
                        page.Description = embedDescription + page.Description;
                    }

                    IPaginatedMessage message = new PaginatedMessage(pages);

                    message.SetTitle(embedTitle);
                    message.SetColor(type.Color);

                    await ReplyAsync(message);
                }
                else
                {
                    await ReplyErrorAsync("No such zone type exists.");
                }
            }
            else
            {
                await GetZoneTypes();
            }
        }
示例#2
0
        // Private members

        private async Task ShowZonesAsync(IEnumerable <IZone> zones, IZoneType type)
        {
            if (zones.Count() > 0)
            {
                // We need to make sure that even if the "short" description is actually long, we can show n zones per page.

                string embedTitle       = string.Format("{0} zones ({1})", type.IsValid() ? type.Name : "All", zones.Count()).ToTitle();
                string embedDescription = string.Format("For detailed zone information, use `{0}zone <zone>` (e.g. `{0}zone {1}`).\n\n",
                                                        Config.Prefix,
                                                        zones.First().GetShortName().Contains(" ") ? string.Format("\"{0}\"", zones.First().GetShortName().ToLowerInvariant()) : zones.First().GetShortName().ToLowerInvariant());

                // Build paginated message.

                IEnumerable <IEmbed> pages = await BotUtils.ZonesToEmbedPagesAsync(embedTitle.Length + embedDescription.Length, zones, Db);

                foreach (IEmbed page in pages)
                {
                    page.Description = embedDescription + page.Description;
                }

                IPaginatedMessage message = new PaginatedMessage(pages);

                message.SetTitle(embedTitle);

                if (type.IsValid())
                {
                    message.SetColor(type.Color);
                }

                await ReplyAsync(message);
            }
            else
            {
                await ReplyInfoAsync("No zones have been added yet.");
            }
        }
示例#3
0
        public async Task <IPaginatedMessage> BuildSpeciesMessageAsync(ISpecies species)
        {
            if (!species.IsValid())
            {
                return(null);
            }

            Discord.Messaging.Embed embed = new Discord.Messaging.Embed {
                Title = species.GetFullName()
            };

            if (species.CommonNames.Count() > 0)
            {
                embed.Title += string.Format(" ({0})", string.Join(", ", species.CommonNames.Select(name => name.ToTitle())));
            }

            if (Config.GenerationsEnabled)
            {
                // Add a field for the generation.

                IGeneration gen = await Db.GetGenerationByDateAsync(species.CreationDate);

                embed.AddField("Gen", gen is null ? "???" : gen.Number.ToString(), inline: true);
            }

            // Add a field for the species owner.

            embed.AddField("Owner", await GetCreatorAsync(species.Creator), inline: true);

            // Add a field for the species' zones.

            IEnumerable <ISpeciesZoneInfo> speciesZoneList = (await Db.GetZonesAsync(species))
                                                             .Where(info => !info.Zone.Flags.HasFlag(ZoneFlags.Retired));

            string zonesFieldValue = speciesZoneList.ToString(ZoneListToStringOptions.Default, DiscordUtilities.MaxFieldLength);

            embed.AddField("Zone(s)", string.IsNullOrEmpty(zonesFieldValue) ? "None" : zonesFieldValue, inline: true);

            // Add the species' description.

            StringBuilder descriptionBuilder = new StringBuilder();

            if (species.IsExtinct())
            {
                embed.Title = "[EXTINCT] " + embed.Title;

                if (!string.IsNullOrEmpty(species.Status.Reason))
                {
                    descriptionBuilder.AppendLine(string.Format("**Extinct ({0}):** _{1}_\n", await BotUtils.TimestampToDateStringAsync(DateUtilities.GetTimestampFromDate((DateTimeOffset)species.Status.Date), BotContext), species.Status.Reason));
                }
            }

            descriptionBuilder.Append(species.GetDescriptionOrDefault());

            embed.Description = descriptionBuilder.ToString();

            // Add the species' picture.

            embed.ThumbnailUrl = species.GetPictureUrl();

            if (!string.IsNullOrEmpty(Config.WikiUrlFormat))
            {
                // Discord automatically encodes certain characters in URIs, which doesn't allow us to update the config via Discord when we have "{0}" in the URL.
                // Replace this with the proper string before attempting to call string.Format.

                string format = Config.WikiUrlFormat.Replace("%7B0%7D", "{0}");

                embed.Url = string.Format(format, Uri.EscapeUriString(WikiUtilities.GetWikiPageTitle(species)));
            }

            // Create embed pages.

            IEnumerable <Discord.Messaging.IEmbed> embedPages = EmbedUtilities.CreateEmbedPages(embed, EmbedPaginationOptions.AddPageNumbers | EmbedPaginationOptions.CopyFields);
            IPaginatedMessage paginatedMessage = new PaginatedMessage(embedPages);

            if (speciesZoneList.Count() > 0)
            {
                paginatedMessage.SetColor((await Db.GetZoneTypeAsync(speciesZoneList.GroupBy(x => x.Zone.TypeId).OrderBy(x => x.Count()).Last().Key)).Color);
            }

            if (species.IsExtinct())
            {
                paginatedMessage.SetColor(Color.Red);
            }

            return(paginatedMessage);
        }