diff --git a/src/Discord.Net.Core/Discord.Net.Core.xml b/src/Discord.Net.Core/Discord.Net.Core.xml index a4b16057d..469250410 100644 --- a/src/Discord.Net.Core/Discord.Net.Core.xml +++ b/src/Discord.Net.Core/Discord.Net.Core.xml @@ -4886,59 +4886,74 @@ Gets or sets the options for this command. + + + Build the current builder into a class. + + A that can be used to create slash commands over rest. + + + + Sets the field name. + + The value to set the field name to. + + The current builder. + + Sets the description of the current command. - The description of this command. + The description of this command. The current builder. Adds an option to the current slash command. - The name of the option to add. - The type of this option. - The description of this option. - If this option is required for this command. - If this option is the default option. - The options of the option to add. - The choices of this option. + The name of the option to add. + The type of this option. + The description of this option. + If this option is required for this command. + If this option is the default option. + The options of the option to add. + The choices of this option. The current builder. Adds an option to the current slash command. - The name of the option to add. - The type of this option. - The description of this option. - If this option is required for this command. - If this option is the default option. - The choices of this option. + The name of the option to add. + The type of this option. + The description of this option. + If this option is required for this command. + If this option is the default option. + The choices of this option. The current builder. Adds an option to the current slash command. - The name of the option to add. - The type of this option. - The sescription of this option. + The name of the option to add. + The type of this option. + The sescription of this option. The current builder. Adds an option to this slash command. - The option to add. + The option to add. The current builder. Adds a collection of options to the current slash command. - The collection of options to add. + The collection of options to add. The current builder. diff --git a/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs index 33665210d..6aa847d96 100644 --- a/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs @@ -102,7 +102,7 @@ namespace Discord else { ActionRowBuilder actionRow = null; - if (_actionRows.Count < row) + if (_actionRows.Count > row) actionRow = _actionRows.ElementAt(row); else { @@ -167,7 +167,7 @@ namespace Discord /// The button to add. /// The row to add the button. /// The current builder. - public ComponentBuilder WithButton(ButtonBuilder button, int row) + public ComponentBuilder WithButton(ButtonBuilder button, int row = 0) { Preconditions.LessThan(row, 5, nameof(row)); @@ -185,7 +185,7 @@ namespace Discord else { ActionRowBuilder actionRow = null; - if(_actionRows.Count < row) + if(_actionRows.Count > row) actionRow = _actionRows.ElementAt(row); else { @@ -295,7 +295,10 @@ namespace Discord case ComponentType.ActionRow: return false; case ComponentType.Button: - return this.Components.Count < 5; + if (this.Components.Any(x => x.Type == ComponentType.SelectMenu)) + return false; + else + return this.Components.Count < 5; case ComponentType.SelectMenu: return this.Components.Count == 0; default: diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommandBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommandBuilder.cs index 8011f9c8e..948527f29 100644 --- a/src/Discord.Net.Core/Entities/Interactions/SlashCommandBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommandBuilder.cs @@ -86,6 +86,10 @@ namespace Discord private string _description { get; set; } private List _options { get; set; } + /// + /// Build the current builder into a class. + /// + /// A that can be used to create slash commands over rest. public SlashCommandCreationProperties Build() { SlashCommandCreationProperties props = new SlashCommandCreationProperties() @@ -107,67 +111,75 @@ namespace Discord } - public SlashCommandBuilder WithName(string Name) + /// + /// Sets the field name. + /// + /// The value to set the field name to. + /// + /// The current builder. + /// + public SlashCommandBuilder WithName(string name) { - this.Name = Name; + this.Name = name; return this; } /// /// Sets the description of the current command. /// - /// The description of this command. + /// The description of this command. /// The current builder. - public SlashCommandBuilder WithDescription(string Description) + public SlashCommandBuilder WithDescription(string description) { - this.Description = Description; + this.Description = description; return this; } /// /// Adds an option to the current slash command. /// - /// The name of the option to add. - /// The type of this option. - /// The description of this option. - /// If this option is required for this command. - /// If this option is the default option. - /// The options of the option to add. - /// The choices of this option. + /// The name of the option to add. + /// The type of this option. + /// The description of this option. + /// If this option is required for this command. + /// If this option is the default option. + /// The options of the option to add. + /// The choices of this option. /// The current builder. - public SlashCommandBuilder AddOption(string Name, ApplicationCommandOptionType Type, - string Description, bool Required = true, bool Default = false, List Options = null, params ApplicationCommandOptionChoiceProperties[] Choices) + public SlashCommandBuilder AddOption(string name, ApplicationCommandOptionType type, + string description, bool required = true, bool isDefault = false, List options = null, params ApplicationCommandOptionChoiceProperties[] choices) { // Make sure the name matches the requirements from discord - Preconditions.NotNullOrEmpty(Name, nameof(Name)); - Preconditions.AtLeast(Name.Length, 3, nameof(Name)); - Preconditions.AtMost(Name.Length, MaxNameLength, nameof(Name)); + Preconditions.NotNullOrEmpty(name, nameof(name)); + Preconditions.AtLeast(name.Length, 3, nameof(name)); + Preconditions.AtMost(name.Length, MaxNameLength, nameof(name)); // Discord updated the docs, this regex prevents special characters like @!$%( and s p a c e s.. etc, // https://discord.com/developers/docs/interactions/slash-commands#applicationcommand - if (!Regex.IsMatch(Name, @"^[\w-]{3,32}$")) - throw new ArgumentException("Command name cannot contian any special characters or whitespaces!", nameof(Name)); + if (!Regex.IsMatch(name, @"^[\w-]{3,32}$")) + throw new ArgumentException("Command name cannot contian any special characters or whitespaces!", nameof(name)); // same with description - Preconditions.NotNullOrEmpty(Description, nameof(Description)); - Preconditions.AtLeast(Description.Length, 3, nameof(Description)); - Preconditions.AtMost(Description.Length, MaxDescriptionLength, nameof(Description)); + Preconditions.NotNullOrEmpty(description, nameof(description)); + Preconditions.AtLeast(description.Length, 3, nameof(description)); + Preconditions.AtMost(description.Length, MaxDescriptionLength, nameof(description)); // make sure theres only one option with default set to true - if (Default) + if (isDefault) { if (this.Options != null) - if (this.Options.Any(x => x.Default)) - throw new ArgumentException("There can only be one command option with default set to true!", nameof(Default)); + if (this.Options.Any(x => x.Default.HasValue && x.Default.Value)) + throw new ArgumentException("There can only be one command option with default set to true!", nameof(isDefault)); } SlashCommandOptionBuilder option = new SlashCommandOptionBuilder(); - option.Name = Name; - option.Description = Description; - option.Required = Required; - option.Default = Default; - option.Options = Options; - option.Choices = Choices != null ? new List(Choices) : null; + option.Name = name; + option.Description = description; + option.Required = required; + option.Default = isDefault; + option.Options = options; + option.Type = type; + option.Choices = choices != null ? new List(choices) : null; return AddOption(option); } @@ -175,33 +187,33 @@ namespace Discord /// /// Adds an option to the current slash command. /// - /// The name of the option to add. - /// The type of this option. - /// The description of this option. - /// If this option is required for this command. - /// If this option is the default option. - /// The choices of this option. + /// The name of the option to add. + /// The type of this option. + /// The description of this option. + /// If this option is required for this command. + /// If this option is the default option. + /// The choices of this option. /// The current builder. - public SlashCommandBuilder AddOption(string Name, ApplicationCommandOptionType Type, - string Description, bool Required = true, bool Default = false, params ApplicationCommandOptionChoiceProperties[] Choices) - => AddOption(Name, Type, Description, Required, Default, null, Choices); + public SlashCommandBuilder AddOption(string name, ApplicationCommandOptionType type, + string description, bool required = true, bool isDefault = false, params ApplicationCommandOptionChoiceProperties[] choices) + => AddOption(name, type, description, required, isDefault, null, choices); /// /// Adds an option to the current slash command. /// - /// The name of the option to add. - /// The type of this option. - /// The sescription of this option. + /// The name of the option to add. + /// The type of this option. + /// The sescription of this option. /// The current builder. - public SlashCommandBuilder AddOption(string Name, ApplicationCommandOptionType Type, string Description) - => AddOption(Name, Type, Description, Options: null, Choices: null); + public SlashCommandBuilder AddOption(string name, ApplicationCommandOptionType type, string description) + => AddOption(name, type, description, options: null, choices: null); /// /// Adds an option to this slash command. /// - /// The option to add. + /// The option to add. /// The current builder. - public SlashCommandBuilder AddOption(SlashCommandOptionBuilder Option) + public SlashCommandBuilder AddOption(SlashCommandOptionBuilder option) { if (this.Options == null) this.Options = new List(); @@ -209,32 +221,32 @@ namespace Discord if (this.Options.Count >= MaxOptionsCount) throw new ArgumentOutOfRangeException(nameof(Options), $"Cannot have more than {MaxOptionsCount} options!"); - if (Option == null) - throw new ArgumentNullException(nameof(Option), "Option cannot be null"); + if (option == null) + throw new ArgumentNullException(nameof(option), "Option cannot be null"); - this.Options.Add(Option); + this.Options.Add(option); return this; } /// /// Adds a collection of options to the current slash command. /// - /// The collection of options to add. + /// The collection of options to add. /// The current builder. - public SlashCommandBuilder AddOptions(params SlashCommandOptionBuilder[] Options) + public SlashCommandBuilder AddOptions(params SlashCommandOptionBuilder[] options) { - if (Options == null) - throw new ArgumentNullException(nameof(Options), "Options cannot be null!"); + if (options == null) + throw new ArgumentNullException(nameof(options), "Options cannot be null!"); - if (Options.Length == 0) - throw new ArgumentException(nameof(Options), "Options cannot be empty!"); + if (options.Length == 0) + throw new ArgumentException(nameof(options), "Options cannot be empty!"); if (this.Options == null) this.Options = new List(); - if (this.Options.Count + Options.Length > MaxOptionsCount) - throw new ArgumentOutOfRangeException(nameof(Options), $"Cannot have more than {MaxOptionsCount} options!"); + if (this.Options.Count + options.Length > MaxOptionsCount) + throw new ArgumentOutOfRangeException(nameof(options), $"Cannot have more than {MaxOptionsCount} options!"); - this.Options.AddRange(Options); + this.Options.AddRange(options); return this; } } @@ -303,7 +315,7 @@ namespace Discord /// /// The first required option for the user to complete. only one option can be default. /// - public bool Default { get; set; } + public bool? Default { get; set; } /// /// if this option is required for this command, otherwise . @@ -369,10 +381,10 @@ namespace Discord /// /// Adds a choice to the current option. /// - /// The name of the choice. - /// The value of the choice. + /// The name of the choice. + /// The value of the choice. /// The current builder. - public SlashCommandOptionBuilder AddChoice(string Name, int Value) + public SlashCommandOptionBuilder AddChoice(string name, int value) { if (Choices == null) Choices = new List(); @@ -380,16 +392,16 @@ namespace Discord if (Choices.Count >= MaxChoiceCount) throw new ArgumentOutOfRangeException(nameof(Choices), $"Cannot add more than {MaxChoiceCount} choices!"); - if (Name == null) - throw new ArgumentNullException($"{nameof(Name)} cannot be null!"); + if (name == null) + throw new ArgumentNullException($"{nameof(name)} cannot be null!"); - Preconditions.AtLeast(Name.Length, 1, nameof(Name)); - Preconditions.AtMost(Name.Length, 100, nameof(Name)); + Preconditions.AtLeast(name.Length, 1, nameof(name)); + Preconditions.AtMost(name.Length, 100, nameof(name)); Choices.Add(new ApplicationCommandOptionChoiceProperties() { - Name = Name, - Value = Value + Name = name, + Value = value }); return this; @@ -398,10 +410,10 @@ namespace Discord /// /// Adds a choice to the current option. /// - /// The name of the choice. - /// The value of the choice. + /// The name of the choice. + /// The value of the choice. /// The current builder. - public SlashCommandOptionBuilder AddChoice(string Name, string Value) + public SlashCommandOptionBuilder AddChoice(string name, string value) { if (Choices == null) Choices = new List(); @@ -409,22 +421,22 @@ namespace Discord if (Choices.Count >= MaxChoiceCount) throw new ArgumentOutOfRangeException(nameof(Choices), $"Cannot add more than {MaxChoiceCount} choices!"); - if (Name == null) - throw new ArgumentNullException($"{nameof(Name)} cannot be null!"); + if (name == null) + throw new ArgumentNullException($"{nameof(name)} cannot be null!"); - if (Value == null) - throw new ArgumentNullException($"{nameof(Value)} cannot be null!"); + if (value == null) + throw new ArgumentNullException($"{nameof(value)} cannot be null!"); - Preconditions.AtLeast(Name.Length, 1, nameof(Name)); - Preconditions.AtMost(Name.Length, 100, nameof(Name)); + Preconditions.AtLeast(name.Length, 1, nameof(name)); + Preconditions.AtMost(name.Length, 100, nameof(name)); - Preconditions.AtLeast(Value.Length, 1, nameof(Value)); - Preconditions.AtMost(Value.Length, 100, nameof(Value)); + Preconditions.AtLeast(value.Length, 1, nameof(value)); + Preconditions.AtMost(value.Length, 100, nameof(value)); Choices.Add(new ApplicationCommandOptionChoiceProperties() { - Name = Name, - Value = Value + Name = name, + Value = value }); return this; @@ -433,11 +445,11 @@ namespace Discord /// /// Sets the current builders name. /// - /// The name to set the current option builder. + /// The name to set the current option builder. /// The current builder. - public SlashCommandOptionBuilder WithName(string Name) + public SlashCommandOptionBuilder WithName(string name) { - this.Name = Name; + this.Name = name; return this; } @@ -445,11 +457,11 @@ namespace Discord /// /// Sets the current builders description. /// - /// The description to set. + /// The description to set. /// The current builder. - public SlashCommandOptionBuilder WithDescription(string Description) + public SlashCommandOptionBuilder WithDescription(string description) { - this.Description = Description; + this.Description = description; return this; } @@ -478,11 +490,11 @@ namespace Discord /// /// Sets the current type of this builder. /// - /// The type to set. + /// The type to set. /// The current builder. - public SlashCommandOptionBuilder WithType(ApplicationCommandOptionType Type) + public SlashCommandOptionBuilder WithType(ApplicationCommandOptionType type) { - this.Type = Type; + this.Type = type; return this; } } diff --git a/src/Discord.Net.Rest/Discord.Net.Rest.csproj b/src/Discord.Net.Rest/Discord.Net.Rest.csproj index ed8dbb66e..3793f680e 100644 --- a/src/Discord.Net.Rest/Discord.Net.Rest.csproj +++ b/src/Discord.Net.Rest/Discord.Net.Rest.csproj @@ -1,4 +1,4 @@ - + @@ -9,7 +9,7 @@ netstandard2.0;netstandard2.1 Temporary.png https://github.com/Discord-Net-Labs/Discord.Net-Labs - 2.3.9-pre + 2.3.9-dev Discord.Net.Labs.Rest https://github.com/Discord-Net-Labs/Discord.Net-Labs 2.3.4 diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs index 542e8efc5..44a60015b 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs @@ -42,7 +42,7 @@ namespace Discord.WebSocket internal override void Update(Model model) { var data = model.Data.IsSpecified ? - (model.Data.Value as JToken).ToObject(Discord._serializer) + (DataModel)model.Data.Value : null; this.Data.Update(data); diff --git a/src/Discord.Net/Discord.Net.nuspec b/src/Discord.Net/Discord.Net.nuspec index f3ed97f4b..2aaa72d02 100644 --- a/src/Discord.Net/Discord.Net.nuspec +++ b/src/Discord.Net/Discord.Net.nuspec @@ -2,7 +2,7 @@ Discord.Net.Labs - 2.3.7$suffix$ + 2.3.8-dev$suffix$ Discord.Net Labs Discord.Net Contributors quinchs @@ -14,23 +14,23 @@ https://avatars.githubusercontent.com/u/84047264 - - - + + + - - - + + + - - - + + +