Exemplo n.º 1
0
        private static Embed GetHelpEmbed(CommandService commandService)
        {
            var eb = new CustomEmbedBuilder();

            eb.WithTitle("Available Commands");

            var mainCommandsNames = new string[] { "flag", "stats" };
            var mainCommands      = commandService.Commands.Where(x => mainCommandsNames.Contains(x.Name));

            eb.Description += "\n**Main Commands**";

            foreach (var command in mainCommands)
            {
                eb.Description += $"\n`.{command.Name}";
                foreach (var parameter in command.Parameters)
                {
                    if (parameter.IsOptional)
                    {
                        eb.Description += $" [{parameter.Name}]";
                    }
                    else
                    {
                        eb.Description += $" <{parameter.Name}>";
                    }
                }
                eb.Description += "`";
                var requirePermission = command.Preconditions.OfType <RequireUserPermissionAttribute>().FirstOrDefault();
                if (requirePermission != null)
                {
                    eb.Description += " :star:";
                }
                eb.Description += $"\n➜ {command.Summary}";
                var requireContext = command.Preconditions.OfType <RequireContextAttribute>().FirstOrDefault();
                if (requireContext != null)
                {
                    switch (requireContext.Contexts)
                    {
                    case ContextType.DM:
                        eb.Description += " (DMs only)";
                        break;

                    case ContextType.Guild:
                        eb.Description += " (Guild only)";
                        break;
                    }
                }
            }

            eb.Description += "\n\n**Other Commands**";

            foreach (var module in commandService.Modules)
            {
                eb.Description += $"\n`.help {module.Name}`";
            }

            eb.WithFooter("Starred commands require the user to have certain permissions");

            return(eb.Build());
        }
Exemplo n.º 2
0
        private static Embed GetCategoryHelpEmbed(CommandService commandService, string category)
        {
            var module = commandService.Modules.FirstOrDefault(x => x.Name.ToLower() == category.ToLower());

            if (module == null)
            {
                return(null);
            }

            var eb = new CustomEmbedBuilder();

            eb.WithTitle("Available Commands");

            foreach (var command in module.Commands)
            {
                eb.Description += $"\n`.{command.Name}";
                foreach (var parameter in command.Parameters)
                {
                    if (parameter.IsOptional)
                    {
                        eb.Description += $" [{parameter.Name}]";
                    }
                    else
                    {
                        eb.Description += $" <{parameter.Name}>";
                    }
                }
                eb.Description += "`";
                var requirePermission = command.Preconditions.OfType <RequireUserPermissionAttribute>().FirstOrDefault();
                if (requirePermission != null)
                {
                    eb.Description += " :star:";
                }
                eb.Description += $"\n➜ {command.Summary}";
                var requireContext = command.Preconditions.OfType <RequireContextAttribute>().FirstOrDefault();
                if (requireContext != null)
                {
                    switch (requireContext.Contexts)
                    {
                    case ContextType.DM:
                        eb.Description += " (DMs only)";
                        break;

                    case ContextType.Guild:
                        eb.Description += " (Guild only)";
                        break;
                    }
                }
            }

            eb.WithFooter("Starred commands require the user to have certain permissions");

            return(eb.Build());
        }