protected override void OnValidate() { OptionalGuard.HasValue(Type); switch (Type.Value) { case ApplicationCommandType.Slash: { OptionalGuard.HasValue(Description, "Slash commands must have descriptions set."); // "CHAT_INPUT command names and command option names must match the following regex ^[\w-]{1,32}$ with the unicode flag set. // If there is a lowercase variant of any letters used, you must use those. // Characters with no lowercase variants and/or uncased letters are still allowed." // ☜(゚ヮ゚☜) break; } case ApplicationCommandType.User: case ApplicationCommandType.Message: { OptionalGuard.HasNoValue(Description, "Context menu commands must not have descriptions set."); break; } } ContentValidation.ApplicationCommands.ValidateName(Name); ContentValidation.ApplicationCommands.ValidateDescription(Description); ContentValidation.ApplicationCommands.ValidateOptions(Options); }
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); }
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() { if (Type == default) { throw new InvalidOperationException("The interaction response's type must be set."); } switch (Type) { case InteractionResponseType.Pong: OptionalGuard.HasNoValue(Data); break; case InteractionResponseType.ApplicationCommandAutoComplete: Guard.IsAssignableToType <InteractionCallbackAutoCompleteDataJsonModel>(Data.Value); break; case InteractionResponseType.ChannelMessage or InteractionResponseType.MessageUpdate: Guard.IsAssignableToType <InteractionCallbackMessageDataJsonModel>(Data.Value); break; } }