Esempio n. 1
0
        public async Task BrowseMenuTest(CommandContext ctx)
        {
            int upgradesPerPage = Math.Min(BotInfoHandler.gameHandler.pool.upgrades.Count(), 7);
            int totalPages      = BotInfoHandler.gameHandler.pool.upgrades.Count() / upgradesPerPage;

            if (BotInfoHandler.gameHandler.pool.upgrades.Count() % upgradesPerPage != 0)
            {
                totalPages++;
            }

            //DiscordMessage menuMessage = await ctx.RespondAsync(embed: new DiscordEmbedBuilder { Color = DiscordColor.Azure }).ConfigureAwait(false);
            //await this.UpdateBrowseMenuAsync(ctx, menuMessage, upgradesPerPage, page, totalPages);

            var interactivity = ctx.Client.GetInteractivity();

            List <DSharpPlus.Interactivity.Page> allMenuPages = new List <DSharpPlus.Interactivity.Page>();

            DSharpPlus.Interactivity.PaginationEmojis paginationEmojis = new DSharpPlus.Interactivity.PaginationEmojis
            {
                SkipLeft  = DiscordEmoji.FromName(ctx.Client, ":rewind:"),
                Left      = DiscordEmoji.FromName(ctx.Client, ":arrow_left:"),
                Stop      = DiscordEmoji.FromName(ctx.Client, ":no_entry_sign:"),
                Right     = DiscordEmoji.FromName(ctx.Client, ":arrow_right:"),
                SkipRight = DiscordEmoji.FromName(ctx.Client, ":fast_forward:")
            };

            for (int page = 1; page <= totalPages; page++)
            {
                string description = $"Page {page}/{totalPages}\n";

                Rarity lastRarity = Rarity.NO_RARITY;
                string pageInfo   = string.Empty;
                for (int i = upgradesPerPage * (page - 1); i < upgradesPerPage * page && i < BotInfoHandler.gameHandler.pool.upgrades.Count(); i++)
                {
                    if (lastRarity != BotInfoHandler.gameHandler.pool.upgrades[i].rarity)
                    {
                        if (lastRarity != Rarity.NO_RARITY)
                        {
                            description += $"\n**{lastRarity}**\n{pageInfo}";
                            //newMenuPage.AddField(lastRarity.ToString(), pageInfo);
                        }
                        pageInfo   = string.Empty;
                        lastRarity = BotInfoHandler.gameHandler.pool.upgrades[i].rarity;
                    }
                    pageInfo += $"{i + 1}) {BotInfoHandler.gameHandler.pool.upgrades[i]}\n";
                }
                description += $"\n**{lastRarity}**\n{pageInfo}";
                //newMenuPage.AddField(lastRarity.ToString(), pageInfo);

                DSharpPlus.Interactivity.Page menuPage = new DSharpPlus.Interactivity.Page(embed: new DiscordEmbedBuilder
                {
                    Title       = "List of Upgrades",
                    Description = description,
                    Color       = DiscordColor.Azure,
                    Footer      = new DiscordEmbedBuilder.EmbedFooter {
                        Text = $"Total Upgrades: {BotInfoHandler.gameHandler.pool.upgrades.Count()}"
                    }
                });

                allMenuPages.Add(menuPage);
            }

            await interactivity.SendPaginatedMessageAsync(ctx.Channel, ctx.User, allMenuPages, paginationEmojis, DSharpPlus.Interactivity.Enums.PaginationBehaviour.WrapAround, timeoutoverride : TimeSpan.FromMinutes(7));
        }
Esempio n. 2
0
        public async Task GetListOfRooms(CommandContext ctx)
        {
            List <ulong> roomsInThisServer = new List <ulong>();

            foreach (var room in BotHandler.openRooms)
            {
                if (room.Value.guild.Id == ctx.Guild.Id)
                {
                    roomsInThisServer.Add(room.Key);
                }
            }

            if (roomsInThisServer.Count() == 0)
            {
                await ctx.RespondAsync(new DiscordEmbedBuilder {
                    Title       = "There Are No Rooms In This Server",
                    Description = "You can create a room using \"room create\"",
                    Color       = DiscordColor.Azure
                }).ConfigureAwait(false);

                return;
            }

            var interactivity = ctx.Client.GetInteractivity();

            List <DSharpPlus.Interactivity.Page> allMenuPages = new List <DSharpPlus.Interactivity.Page>();

            DSharpPlus.Interactivity.PaginationEmojis paginationEmojis = new DSharpPlus.Interactivity.PaginationEmojis
            {
                SkipLeft  = DiscordEmoji.FromName(ctx.Client, ":rewind:"),
                Left      = DiscordEmoji.FromName(ctx.Client, ":arrow_left:"),
                Stop      = DiscordEmoji.FromName(ctx.Client, ":no_entry_sign:"),
                Right     = DiscordEmoji.FromName(ctx.Client, ":arrow_right:"),
                SkipRight = DiscordEmoji.FromName(ctx.Client, ":fast_forward:")
            };

            int roomsPerPage = Math.Min(10, roomsInThisServer.Count());
            int totalPages   = roomsInThisServer.Count() / roomsPerPage;

            if (roomsInThisServer.Count() % roomsPerPage != 0)
            {
                totalPages++;
            }

            for (int page = 1; page <= totalPages; page++)
            {
                string description = $"Page {page}/{totalPages}\n";

                for (int i = (page - 1) * roomsPerPage; i < page * roomsPerPage && i < roomsInThisServer.Count(); i++)
                {
                    description += $"\n{i + 1}) {BotHandler.openRooms[roomsInThisServer[i]].roomName} ({(await ctx.Client.GetUserAsync(roomsInThisServer[i])).Username})";
                }

                DSharpPlus.Interactivity.Page menuPage = new DSharpPlus.Interactivity.Page(embed: new DiscordEmbedBuilder
                {
                    Title       = "List of Rooms",
                    Description = description,
                    Color       = DiscordColor.Azure,
                    Footer      = new DiscordEmbedBuilder.EmbedFooter {
                        Text = $"Total Rooms: {roomsInThisServer.Count()}"
                    }
                });

                allMenuPages.Add(menuPage);
            }

            await interactivity.SendPaginatedMessageAsync(ctx.Channel, ctx.User, allMenuPages, paginationEmojis, DSharpPlus.Interactivity.Enums.PaginationBehaviour.WrapAround, timeoutoverride : TimeSpan.FromMinutes(3));
        }