diff --git a/DisCatSharp/Entities/Application/DiscordApplicationCommandOption.cs b/DisCatSharp/Entities/Application/DiscordApplicationCommandOption.cs index 0fe683425..e183d0a2f 100644 --- a/DisCatSharp/Entities/Application/DiscordApplicationCommandOption.cs +++ b/DisCatSharp/Entities/Application/DiscordApplicationCommandOption.cs @@ -1,181 +1,181 @@ // This file is part of the DisCatSharp project, based off DSharpPlus. // // Copyright (c) 2021-2022 AITSYS // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using DisCatSharp.Enums; using Newtonsoft.Json; namespace DisCatSharp.Entities; /// /// Represents a parameter for a . /// public sealed class DiscordApplicationCommandOption { /// /// Gets the type of this command parameter. /// [JsonProperty("type")] public ApplicationCommandOptionType Type { get; internal set; } /// /// Gets the name of this command parameter. /// [JsonProperty("name")] public string Name { get; internal set; } /// /// Sets the name localizations. /// [JsonProperty("name_localizations", NullValueHandling = NullValueHandling.Ignore)] internal Dictionary RawNameLocalizations { get; set; } /// /// Gets the name localizations. /// [JsonIgnore] public DiscordApplicationCommandLocalization NameLocalizations => new(this.RawNameLocalizations); /// /// Gets the description of this command parameter. /// [JsonProperty("description")] public string Description { get; internal set; } /// /// Sets the description localizations. /// [JsonProperty("description_localizations", NullValueHandling = NullValueHandling.Ignore)] internal Dictionary RawDescriptionLocalizations { get; set; } /// /// Gets the description localizations. /// [JsonIgnore] public DiscordApplicationCommandLocalization DescriptionLocalizations => new(this.RawDescriptionLocalizations); /// /// Gets whether this command parameter is required. /// [JsonProperty("required", NullValueHandling = NullValueHandling.Ignore)] public bool? Required { get; internal set; } /// /// Gets the optional choices for this command parameter. /// Not applicable for auto-complete options. /// [JsonProperty("choices", NullValueHandling = NullValueHandling.Ignore)] public IReadOnlyCollection Choices { get; internal set; } /// /// Gets the optional subcommand parameters for this parameter. /// [JsonProperty("options", NullValueHandling = NullValueHandling.Ignore)] public IReadOnlyCollection Options { get; internal set; } /// /// Gets the optional allowed channel types. /// [JsonProperty("channel_types", NullValueHandling = NullValueHandling.Ignore)] public IReadOnlyCollection ChannelTypes { get; internal set; } /// /// Gets whether this option provides autocompletion. /// [JsonProperty("autocomplete", NullValueHandling = NullValueHandling.Ignore)] public bool? AutoComplete { get; internal set; } /// /// Gets the minimum value for this slash command parameter. /// [JsonProperty("min_value", NullValueHandling = NullValueHandling.Ignore)] public object MinimumValue { get; internal set; } /// /// Gets the maximum value for this slash command parameter. /// - [JsonProperty("min_length", NullValueHandling = NullValueHandling.Ignore)] - public int? MaximumLength { get; internal set; } + [JsonProperty("max_value", NullValueHandling = NullValueHandling.Ignore)] + public object MaximumValue { get; internal set; } /// - /// Gets the minimum value for this slash command parameter. + /// Gets the maximum value for this slash command parameter. /// - [JsonProperty("max_length", NullValueHandling = NullValueHandling.Ignore)] + [JsonProperty("min_length", NullValueHandling = NullValueHandling.Ignore)] public int? MinimumLength { get; internal set; } /// - /// Gets the maximum value for this slash command parameter. + /// Gets the minimum value for this slash command parameter. /// - [JsonProperty("max_value", NullValueHandling = NullValueHandling.Ignore)] - public object MaximumValue { get; internal set; } + [JsonProperty("max_length", NullValueHandling = NullValueHandling.Ignore)] + public int? MaximumLength { get; internal set; } /// /// Creates a new instance of a . /// /// The name of this parameter. /// The description of the parameter. /// The type of this parameter. /// Whether the parameter is required. /// The optional choice selection for this parameter. /// The optional subcommands for this parameter. /// If the option is a channel type, the channels shown will be restricted to these types. /// Whether this option provides autocompletion. /// The minimum value for this parameter. Only valid for types or . /// The maximum value for this parameter. Only valid for types or . /// The localizations of the parameter name. /// The localizations of the parameter description. /// The minimum allowed length of the string. (Min 0) /// The maximum allowed length of the string. (Min 1) public DiscordApplicationCommandOption(string name, string description, ApplicationCommandOptionType type, bool? required = null, IEnumerable choices = null, IEnumerable options = null, IEnumerable channelTypes = null, bool? autocomplete = null, object minimumValue = null, object maximumValue = null, DiscordApplicationCommandLocalization nameLocalizations = null, DiscordApplicationCommandLocalization descriptionLocalizations = null, int? minimumLength = null, int? maximumLength = null) { if (!Utilities.IsValidSlashCommandName(name)) throw new ArgumentException("Invalid application command option name specified. It must be below 32 characters and not contain any whitespace.", nameof(name)); if (name.Any(char.IsUpper)) throw new ArgumentException("Application command option name cannot have any upper case characters.", nameof(name)); if (description.Length > 100) throw new ArgumentException("Application command option description cannot exceed 100 characters.", nameof(description)); if ((autocomplete ?? false) && (choices?.Any() ?? false)) throw new InvalidOperationException("Auto-complete slash command options cannot provide choices."); this.Name = name; this.Description = description; this.Type = type; this.Required = required; this.Choices = choices != null ? new ReadOnlyCollection(choices.ToList()) : null; this.Options = options != null ? new ReadOnlyCollection(options.ToList()) : null; this.ChannelTypes = channelTypes != null ? new ReadOnlyCollection(channelTypes.ToList()) : null; this.AutoComplete = autocomplete; this.MinimumValue = minimumValue; this.MaximumValue = maximumValue; this.MinimumLength = minimumLength; this.MaximumLength = maximumLength; this.RawNameLocalizations = nameLocalizations?.GetKeyValuePairs(); this.RawDescriptionLocalizations = descriptionLocalizations?.GetKeyValuePairs(); } }