Beispiel #1
0
        /// <summary>
        /// Generates and returns an embedded message containing information about a command
        /// </summary>
        private async Task HelpCommand(CommandInfo command)
        {
            EmbedBuilder builder = new EmbedBuilder();

            builder.Title       = $"Command: {command.FullCommandName()}";
            builder.Description = command.Summary;

            builder.AddField(field =>
            {
                field.Name     = "Usage:";
                field.Value    = command.Usage();
                field.IsInline = false;
            });


            // If the command has parameters, add a field for it
            if (command.Parameters.Count > 0)
            {
                builder.AddField(field =>
                {
                    field.Name = "Parameters";
                    List <string> parameters = new List <string>();
                    foreach (var parameter in command.Parameters)
                    {
                        parameters.Add(parameter.Name + (parameter.IsOptional ? " (Optional)" : "") + ": " +
                                       parameter.Summary);
                    }
                    field.Value = String.Join('\n', parameters);
                });
            }

            // If the command has remarks, add a field for it
            if (!String.IsNullOrEmpty(command.Remarks))
            {
                builder.AddField(field =>
                {
                    field.Name  = "Remarks:";
                    field.Value = command.Remarks;
                });
            }

            // If the command requires custom permissions, add a field for it
            RequireCustomPermissionAttribute[] requiredPermissions =
                command.Preconditions.OfType <RequireCustomPermissionAttribute>().ToArray();
            if (requiredPermissions.Length > 0)
            {
                builder.AddField(field =>
                {
                    field.Name  = "Required Permissions";
                    field.Value = String.Join('\n', requiredPermissions.Select(x => x.Permission));
                });
            }

            // Build the embed and send
            await ReplyAsync(embed : builder.Build());
        }
Beispiel #2
0
 public static string Usage(this CommandInfo commandInfo)
 {
     return(commandInfo.FullCommandName() + " " +
            string.Join(" ", commandInfo.Parameters.Select(
                            x => x.IsOptional ? $"[{x.Name}]" : $"<{x.Name}>")));
 }