Ejemplo n.º 1
0
        protected override void OnValidate()
        {
            switch (EntityType)
            {
            case GuildEventTargetType.Stage:
            case GuildEventTargetType.Voice:
            {
                OptionalGuard.HasValue(ChannelId, "Stage or Voice events must have a channel ID set.");
                OptionalGuard.HasNoValue(EntityMetadata, "Stage or Voice events must not have entity metadata set.");
                break;
            }

            case GuildEventTargetType.External:
            {
                OptionalGuard.HasNoValue(ChannelId, "External events must not have a channel ID set.");
                OptionalGuard.CheckValue(EntityMetadata, metadata =>
                    {
                        Guard.IsNotNull(metadata);
                        ContentValidation.GuildEvents.Metadata.ValidateLocation(metadata.Location);
                    });
                OptionalGuard.HasValue(ScheduledEndTime, "External events must have an end time set.");
                break;
            }
            }

            ContentValidation.GuildEvents.ValidateName(Name);
            ContentValidation.GuildEvents.ValidateDescription(Description);
        }
Ejemplo n.º 2
0
 public static void ValidateLocation(Optional <string> location, [CallerArgumentExpression("location")] string nameExpression = null)
 {
     OptionalGuard.CheckValue(location, value =>
     {
         Guard.IsNotNullOrWhiteSpace(value);
         Guard.HasSizeBetweenOrEqualTo(value, Discord.Limits.GuildEvents.Metadata.MinLocationLength, Discord.Limits.GuildEvents.Metadata.MaxLocationLength);
     }, nameExpression);
 }
Ejemplo n.º 3
0
 public static void ValidateDescription(Optional <string> description, [CallerArgumentExpression("description")] string nameExpression = null)
 {
     OptionalGuard.CheckValue(description, value =>
     {
         Guard.IsNotNullOrWhiteSpace(value);
         Guard.HasSizeBetweenOrEqualTo(value, Discord.Limits.ApplicationCommands.MinDescriptionLength, Discord.Limits.ApplicationCommands.MaxDescriptionLength);
     }, nameExpression);
 }
Ejemplo n.º 4
0
        protected override void OnValidate()
        {
            Guard.IsDefined(Type);

            Guard.IsNotNullOrWhiteSpace(Name);
            Guard.HasSizeBetweenOrEqualTo(Name, Discord.Limits.ApplicationCommands.Options.MinNameLength, Discord.Limits.ApplicationCommands.Options.MaxNameLength);

            Guard.IsNotNullOrWhiteSpace(Description);
            Guard.HasSizeBetweenOrEqualTo(Description, Discord.Limits.ApplicationCommands.Options.MinDescriptionLength, Discord.Limits.ApplicationCommands.Options.MaxDescriptionLength);

            if (Type is not SlashCommandOptionType.String and not SlashCommandOptionType.Integer and not SlashCommandOptionType.Number)
            {
                OptionalGuard.HasNoValue(Choices, "Choices can only be specified for string, integer, and number options.");
            }

            if (Type is not SlashCommandOptionType.Subcommand and not SlashCommandOptionType.SubcommandGroup)
            {
                OptionalGuard.HasNoValue(Options, "Nested options can only be specified for subcommands and subcommand groups.");
            }

            OptionalGuard.CheckValue(Choices, value =>
            {
                Guard.IsNotNull(value);
                Guard.HasSizeLessThanOrEqualTo(value, Discord.Limits.ApplicationCommands.Options.MaxChoiceAmount);

                foreach (var choice in value)
                {
                    Guard.IsNotNull(choice);
                    choice.Validate();
                }
            });

            OptionalGuard.CheckValue(Options, value =>
            {
                Guard.IsNotNull(value);
                Guard.HasSizeLessThanOrEqualTo(value, Discord.Limits.ApplicationCommands.MaxOptionsAmount);

                foreach (var option in value)
                {
                    Guard.IsNotNull(option);
                    option.Validate();
                }
            });

            OptionalGuard.CheckValue(ChannelTypes, value =>
            {
                Guard.IsNotNull(value);

                foreach (var channelType in value)
                {
                    Guard.IsDefined(channelType);
                }
            });
        }
        protected override void OnValidate()
        {
            OptionalGuard.CheckValue(Choices, value =>
            {
                Guard.IsNotNull(value);
                Guard.HasSizeLessThanOrEqualTo(value, Discord.Limits.ApplicationCommands.Options.MaxChoiceAmount);

                foreach (var choice in value)
                {
                    Guard.IsNotNull(choice);
                    choice.Validate();
                }
            });
        }
Ejemplo n.º 6
0
            public static void ValidateOptions(Optional <ApplicationCommandOptionJsonModel[]> options, [CallerArgumentExpression("options")] string nameExpression = null)
            {
                OptionalGuard.CheckValue(options, value =>
                {
                    Guard.IsNotNull(value);
                    Guard.HasSizeLessThanOrEqualTo(value, Discord.Limits.ApplicationCommands.MaxOptionsAmount);

                    var isRequired = true;
                    foreach (var option in value)
                    {
                        if (!isRequired && option.Required.GetValueOrDefault())
                        {
                            Throw.ArgumentException("Required options must appear before optional ones.", nameof(value));
                            return;
                        }

                        isRequired = option.Required.GetValueOrDefault();
                        option.Validate();
                    }
                }, nameExpression);
            }
 protected override void OnValidate()
 {
     OptionalGuard.CheckValue(Name, value => ContentValidation.ApplicationCommands.ValidateName(value));
     ContentValidation.ApplicationCommands.ValidateDescription(Description);
     ContentValidation.ApplicationCommands.ValidateOptions(Options);
 }