示例#1
0
        public static SlashCommandProperties ToApplicationCommandProps(this SlashCommandInfo commandInfo)
        {
            var props = new SlashCommandBuilder()
            {
                Name                = commandInfo.Name,
                Description         = commandInfo.Description,
                IsDefaultPermission = commandInfo.DefaultPermission,
            }.Build();

            if (commandInfo.Parameters.Count > SlashCommandBuilder.MaxOptionsCount)
            {
                throw new InvalidOperationException($"Slash Commands cannot have more than {SlashCommandBuilder.MaxOptionsCount} command parameters");
            }

            props.Options = commandInfo.Parameters.Select(x => x.ToApplicationCommandOptionProps())?.ToList() ?? Optional <List <ApplicationCommandOptionProperties> > .Unspecified;

            return(props);
        }
示例#2
0
        public static SlashCommandProperties ToApplicationCommandProps(this SlashCommandInfo commandInfo)
        {
            var props = new SlashCommandBuilder()
            {
                Name        = commandInfo.Name,
                Description = commandInfo.Description,
                IsDMEnabled = commandInfo.IsEnabledInDm,
                DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(),
            }.Build();

            if (commandInfo.Parameters.Count > SlashCommandBuilder.MaxOptionsCount)
            {
                throw new InvalidOperationException($"Slash Commands cannot have more than {SlashCommandBuilder.MaxOptionsCount} command parameters");
            }

            props.Options = commandInfo.FlattenedParameters.Select(x => x.ToApplicationCommandOptionProps())?.ToList() ?? Optional <List <ApplicationCommandOptionProperties> > .Unspecified;

            return(props);
        }
        internal SlashCommandParameterInfo(Builders.SlashCommandParameterBuilder builder, SlashCommandInfo command) : base(builder, command)
        {
            TypeConverter          = builder.TypeConverter;
            AutocompleteHandler    = builder.AutocompleteHandler;
            Description            = builder.Description;
            MaxValue               = builder.MaxValue;
            MinValue               = builder.MinValue;
            IsComplexParameter     = builder.IsComplexParameter;
            IsAutocomplete         = builder.Autocomplete;
            Choices                = builder.Choices.ToImmutableArray();
            ChannelTypes           = builder.ChannelTypes.ToImmutableArray();
            ComplexParameterFields = builder.ComplexParameterFields?.Select(x => x.Build(command)).ToImmutableArray();

            _complexParameterInitializer = builder.ComplexParameterInitializer;
        }
示例#4
0
 public static ApplicationCommandOptionProperties ToApplicationCommandOptionProps(this SlashCommandInfo commandInfo) =>
 new ApplicationCommandOptionProperties
 {
     Name        = commandInfo.Name,
     Description = commandInfo.Description,
     Type        = ApplicationCommandOptionType.SubCommand,
     IsRequired  = false,
     Options     = commandInfo.Parameters?.Select(x => x.ToApplicationCommandOptionProps())?.ToList()
 };
 internal SlashCommandParameterInfo(Builders.SlashCommandParameterBuilder builder, SlashCommandInfo command) : base(builder, command)
 {
     TypeConverter       = builder.TypeConverter;
     AutocompleteHandler = builder.AutocompleteHandler;
     Description         = builder.Description;
     MaxValue            = builder.MaxValue;
     MinValue            = builder.MinValue;
     IsAutocomplete      = builder.Autocomplete;
     Choices             = builder.Choices.ToImmutableArray();
     ChannelTypes        = builder.ChannelTypes.ToImmutableArray();
 }