public static CommandBuilder CreateCommandBuilder(CommandService service, ModuleBuilder module, TypeInfo typeInfo, MethodInfo methodInfo)
        {
            var builder    = new CommandBuilder(module, CreateCommandCallback(service, typeInfo, methodInfo));
            var attributes = methodInfo.GetCustomAttributes(false);

            for (var i = 0; i < attributes.Length; i++)
            {
                switch (attributes[i])
                {
                case NameAttribute nameAttribute:
                    builder.WithName(nameAttribute.Name);
                    break;

                case DescriptionAttribute descriptionAttribute:
                    builder.WithDescription(descriptionAttribute.Description);
                    break;

                case RemarksAttribute remarksAttribute:
                    builder.WithRemarks(remarksAttribute.Remarks);
                    break;

                case PriorityAttribute priorityAttribute:
                    builder.WithPriority(priorityAttribute.Priority);
                    break;

                case RunModeAttribute runModeAttribute:
                    builder.WithRunMode(runModeAttribute.RunMode);
                    break;

                case CooldownAttribute cooldownAttribute:
                    builder.AddCooldown(new Cooldown(cooldownAttribute.Amount, cooldownAttribute.Per, cooldownAttribute.BucketType));
                    break;

                case IgnoreExtraArgumentsAttribute ignoreExtraArgumentsAttribute:
                    builder.WithIgnoresExtraArguments(ignoreExtraArgumentsAttribute.IgnoreExtraArguments);
                    break;

                case CommandAttribute commandAttribute:
                    builder.AddAliases(commandAttribute.Aliases);
                    break;

                case CheckAttribute checkAttribute:
                    builder.AddCheck(checkAttribute);
                    break;

                case Attribute attribute:
                    builder.AddAttribute(attribute);
                    break;
                }
            }

            var parameters = methodInfo.GetParameters();

            for (var i = 0; i < parameters.Length; i++)
            {
                builder.Parameters.Add(CreateParameterBuilder(builder, parameters[i], i + 1 == parameters.Length));
            }

            return(builder);
        }
Exemple #2
0
        public static CommandBuilder BuildCommand(TypeInfo typeInfo, MethodInfo methodInfo)
        {
            var builder    = new CommandBuilder();
            var attributes = methodInfo.GetCustomAttributes(false);

            for (var i = 0; i < attributes.Length; i++)
            {
                switch (attributes[i])
                {
                case NameAttribute nameAttribute:
                    builder.WithName(nameAttribute.Name);
                    break;

                case DescriptionAttribute descriptionAttribute:
                    builder.WithDescription(descriptionAttribute.Description);
                    break;

                case RemarksAttribute remarksAttribute:
                    builder.WithRemarks(remarksAttribute.Remarks);
                    break;

                case PriorityAttribute priorityAttribute:
                    builder.WithPriority(priorityAttribute.Priority);
                    break;

                case RunModeAttribute runModeAttribute:
                    builder.WithRunMode(runModeAttribute.RunMode);
                    break;

                case IgnoreExtraArgumentsAttribute ignoreExtraArgumentsAttribute:
                    builder.WithIgnoreExtraArguments(ignoreExtraArgumentsAttribute.IgnoreExtraArguments);
                    break;

                case CommandAttribute commandAttribute:
                    builder.AddAliases(commandAttribute.Aliases);
                    break;

                case CheckBaseAttribute checkAttribute:
                    builder.AddCheck(checkAttribute);
                    break;

                case Attribute attribute:
                    builder.AddAttribute(attribute);
                    break;
                }
            }

            var parameters = methodInfo.GetParameters();

            for (var i = 0; i < parameters.Length; i++)
            {
                builder.AddParameters(BuildParameter(parameters[i], i + 1 == parameters.Length));
            }

            builder.WithCallback(CreateCommandCallback(typeInfo, methodInfo));

            return(builder);
        }