Ejemplo n.º 1
0
        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);
        }