Beispiel #1
0
        private static Embed GetHelp(IGuild guild, Permissions permissions, int startIndex, out int page)
        {
            // Get all help commands
            IEnumerable <HelpCommand> helpCommands = CommandsService.GetGroupedHelpCommands()
                                                     .Where(x => x.Permission <= permissions);

            int numberOfPages = 0;
            int pagesForGroup = 0;

            foreach (IGrouping <CommandCategory, HelpCommand> group in helpCommands.GroupBy(x => x.CommandCategory))
            {
                pagesForGroup  = (int)Math.Ceiling((decimal)group.Count() / PageSize);
                numberOfPages += pagesForGroup;

                // Create spacer commands
                int spacerCommandsRequired = (PageSize * pagesForGroup) - group.Count();
                for (int i = 0; i < spacerCommandsRequired; i++)
                {
                    helpCommands = helpCommands.Append(new HelpCommand("Spacer", group.Key, string.Empty, Permissions.Everyone));
                }
            }

            helpCommands = helpCommands.OrderBy(x => x.CommandCategory)
                           .ThenBy(x => x.CommandName)
                           .AsEnumerable();

            // page is 0-indexed
            page = startIndex + 1;

            // If page is greater than last page, wrap to start
            if (page > numberOfPages)
            {
                page       = 1;
                startIndex = 0;
            }

            // Moving to last page
            if (startIndex == -1)
            {
                page = numberOfPages;

                helpCommands = helpCommands.TakeLast(PageSize);

                startIndex = 0;
            }

            // Restrict to page size
            helpCommands = helpCommands.Skip(startIndex * PageSize).Take(PageSize);

            // Start Embed
            EmbedBuilder  embed   = new EmbedBuilder();
            StringBuilder builder = new StringBuilder();

            // Category name
            embed.Title = helpCommands.FirstOrDefault().CommandCategory.ToDisplayString() + " Commands";

            // Iterate commands
            foreach (HelpCommand category in helpCommands)
            {
                if (category.CommandName.ToLower() == "spacer")
                {
                    continue;
                }

                builder.Append("**" + category.CommandName + "**");
                builder.Append(" - ");

                if (category.CommandCount > 1)
                {
                    builder.Append("*+" + category.CommandCount + "* - ");
                }

                builder.Append(category.Help);
                builder.AppendLine();

                if (category.CommandShortcuts.Count > 0)
                {
                    builder.Append("Shortcut: ");
                    foreach (string shortcutString in category.CommandShortcuts)
                    {
                        builder.Append(shortcutString + ", ");
                    }

                    builder.Remove(builder.Length - 2, 2);

                    builder.AppendLine();
                }

                builder.AppendLine();
            }

            builder.AppendLine();

            string prefix = CommandsService.GetPrefix(guild);

            embed.WithThumbnailUrl("https://cdn.discordapp.com/attachments/825936704023691284/828491389838426121/think3.png")
            .WithDescription(builder.ToString())
            .WithAuthor(string.Format("Page {0} of {1}", page, numberOfPages))
            .WithFooter("To get more information on a command, look it up directly, like \"" + prefix + "help time\" or \"" + prefix + "et ?\"");

            // Return page to 0-index
            page -= 1;

            return(embed.Build());
        }