Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public List<SelectMenuOptionBuilder> Options
}
}

/// <summary>
/// Gets or sets whether the current menu is required to answer in a modal (defaults to <see langword="true"/>).
/// </summary>
public bool IsRequired { get ; set; } = true;

/// <summary>
/// Gets or sets whether the current menu is disabled.
/// </summary>
Expand Down Expand Up @@ -168,11 +173,13 @@ public SelectMenuBuilder(SelectMenuComponent selectMenu)
CustomId = selectMenu.CustomId;
MaxValues = selectMenu.MaxValues;
MinValues = selectMenu.MinValues;
IsRequired = selectMenu.IsRequired;
IsDisabled = selectMenu.IsDisabled;
Type = selectMenu.Type;
Options = selectMenu.Options?
.Select(x => new SelectMenuOptionBuilder(x.Label, x.Value, x.Description, x.Emote, x.IsDefault))
.ToList();
ChannelTypes = selectMenu.ChannelTypes?.ToList();
DefaultValues = selectMenu.DefaultValues?.ToList();
Id = selectMenu.Id;
}
Expand All @@ -188,12 +195,16 @@ public SelectMenuBuilder(SelectMenuComponent selectMenu)
/// <param name="isDisabled">Disabled this select menu or not.</param>
/// <param name="type">The <see cref="ComponentType"/> of this select menu.</param>
/// <param name="channelTypes">The types of channels this menu can select (only valid on <see cref="ComponentType.ChannelSelect"/>s)</param>
public SelectMenuBuilder(string customId, List<SelectMenuOptionBuilder> options = null, string placeholder = null, int maxValues = 1, int minValues = 1,
bool isDisabled = false, ComponentType type = ComponentType.SelectMenu, List<ChannelType> channelTypes = null, List<SelectMenuDefaultValue> defaultValues = null, int? id = null)
/// <param name="defaultValues">The list of default values.</param>
/// <param name="id">An optional id for the component.</param>
/// <param name="isRequired">Whether the current menu is required to answer in a modal.</param>
public SelectMenuBuilder(string customId, List<SelectMenuOptionBuilder> options = null, string placeholder = null, int maxValues = 1, int minValues = 1, bool isDisabled = false,
ComponentType type = ComponentType.SelectMenu, List<ChannelType> channelTypes = null, List<SelectMenuDefaultValue> defaultValues = null, int? id = null, bool isRequired = true)
{
CustomId = customId;
Options = options;
Placeholder = placeholder;
IsRequired = isRequired;
IsDisabled = isDisabled;
MaxValues = maxValues;
MinValues = minValues;
Expand Down Expand Up @@ -352,6 +363,19 @@ public SelectMenuBuilder WithDefaultValues(params SelectMenuDefaultValue[] defau
return this;
}

/// <summary>
/// Sets whether the current menu is required to answer in a modal.
/// </summary>
/// <param name="isRequired">Whether the current menu is required to answer in a modal.</param>
/// <returns>
/// The current builder.
/// </returns>
public SelectMenuBuilder WithRequired(bool isRequired)
{
IsRequired = isRequired;
return this;
}

/// <summary>
/// Sets whether the current menu is disabled.
/// </summary>
Expand Down Expand Up @@ -414,7 +438,7 @@ public SelectMenuComponent Build()
{
var options = Options?.Select(x => x.Build()).ToList();

return new SelectMenuComponent(CustomId, options, Placeholder, MinValues, MaxValues, IsDisabled, Type, Id, ChannelTypes, DefaultValues);
return new SelectMenuComponent(CustomId, options, Placeholder, MinValues, MaxValues, IsRequired, IsDisabled, Type, Id, ChannelTypes, DefaultValues);
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public class SelectMenuComponent : IInteractableComponent
/// </summary>
public int MaxValues { get; }

/// <summary>
/// Gets whether this menu is required to answer in a modal.
/// </summary>
public bool IsRequired { get;}

/// <summary>
/// Gets whether this menu is disabled or not.
/// </summary>
Expand All @@ -58,14 +63,15 @@ public class SelectMenuComponent : IInteractableComponent
public SelectMenuBuilder ToBuilder()
=> new(this);

internal SelectMenuComponent(string customId, List<SelectMenuOption> options, string placeholder, int minValues, int maxValues,
internal SelectMenuComponent(string customId, List<SelectMenuOption> options, string placeholder, int minValues, int maxValues, bool required,
bool disabled, ComponentType type, int? id, IEnumerable<ChannelType> channelTypes = null, IEnumerable<SelectMenuDefaultValue> defaultValues = null)
{
CustomId = customId;
Options = options;
Placeholder = placeholder;
MinValues = minValues;
MaxValues = maxValues;
IsRequired = required;
IsDisabled = disabled;
Type = type;
Id = id;
Expand Down
38 changes: 24 additions & 14 deletions src/Discord.Net.Core/Entities/Interactions/Modals/ModalBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public ModalBuilder AddLabel(
return this;
}

/// <inheritdoc cref="ModalComponentBuilder.WithSelectMenu(string, string, List{SelectMenuOptionBuilder}, string, int, int, bool, ComponentType, ChannelType[], int?, string, int?)"/>
/// <inheritdoc cref="ModalComponentBuilder.WithSelectMenu(string, string, List{SelectMenuOptionBuilder}, string, int, int, bool, bool, ComponentType, ChannelType[], SelectMenuDefaultValue[], int?, string, int?)"/>
/// <returns>The current <see cref="ModalBuilder"/>.</returns>
public ModalBuilder AddSelectMenu(
string label,
Expand All @@ -174,9 +174,11 @@ public ModalBuilder AddSelectMenu(
string placeholder = null,
int minValues = 1,
int maxValues = 1,
bool required = true,
bool disabled = false,
ComponentType type = ComponentType.SelectMenu,
ChannelType[] channelTypes = null,
SelectMenuDefaultValue[] defaultValues = null,
int? id = null,
string description = null,
int? labelId = null
Expand All @@ -189,9 +191,11 @@ public ModalBuilder AddSelectMenu(
placeholder,
minValues,
maxValues,
required,
disabled,
type,
channelTypes,
defaultValues,
id,
description,
labelId
Expand Down Expand Up @@ -624,9 +628,11 @@ public ModalComponentBuilder WithLabel(
/// <param name="placeholder">The placeholder of the <see cref="SelectMenuBuilder"/>.</param>
/// <param name="minValues">The min values of the <see cref="SelectMenuBuilder"/>.</param>
/// <param name="maxValues">The max values of the <see cref="SelectMenuBuilder"/>.</param>
/// <param name="required">Whether the <see cref="SelectMenuBuilder"/> is required to be answered.</param>
/// <param name="disabled">Whether the <see cref="SelectMenuBuilder"/> is disabled.</param>
/// <param name="type">The type of the <see cref="SelectMenuBuilder"/>.</param>
/// <param name="channelTypes">The channel types of the <see cref="SelectMenuBuilder"/>.</param>
/// <param name="defaultValues">The default values of the <see cref="SelectMenuBuilder"/>.</param>
/// <param name="id">The id of the <see cref="SelectMenuBuilder"/>.</param>
/// <param name="description">The description around the <see cref="SelectMenuBuilder"/>.</param>
/// <param name="labelId">
Expand All @@ -640,9 +646,11 @@ public ModalComponentBuilder WithSelectMenu(
string placeholder = null,
int minValues = 1,
int maxValues = 1,
bool required = true,
bool disabled = false,
ComponentType type = ComponentType.SelectMenu,
ChannelType[] channelTypes = null,
SelectMenuDefaultValue[] defaultValues = null,
int? id = null,
string description = null,
int? labelId = null
Expand All @@ -655,9 +663,11 @@ public ModalComponentBuilder WithSelectMenu(
.WithPlaceholder(placeholder)
.WithMaxValues(maxValues)
.WithMinValues(minValues)
.WithRequired(required)
.WithDisabled(disabled)
.WithType(type)
.WithChannelTypes(channelTypes),
.WithChannelTypes(channelTypes)
.WithDefaultValues(defaultValues),
description,
labelId
);
Expand Down Expand Up @@ -695,11 +705,11 @@ public ModalComponentBuilder WithSelectMenu(
/// Constructs and adds a <see cref="LabelBuilder"/> with the provided
/// <see cref="FileUploadComponentBuilder"/> to the current <see cref="ModalComponentBuilder"/>.
/// </summary>
/// <param name="label">The label around the <see cref="SelectMenuBuilder"/>.</param>
/// <param name="label">The label around the <see cref="FileUploadComponentBuilder"/>.</param>
/// <param name="fileUpload">The file upload to add.</param>
/// <param name="description">The description around the <see cref="SelectMenuBuilder"/>.</param>
/// <param name="description">The description around the <see cref="FileUploadComponentBuilder"/>.</param>
/// <param name="labelId">
/// The id of the <see cref="LabelBuilder"/> wrapping the <see cref="SelectMenuBuilder"/>.
/// The id of the <see cref="LabelBuilder"/> wrapping the <see cref="FileUploadComponentBuilder"/>.
/// </param>
/// <returns>The current <see cref="ModalComponentBuilder"/>.</returns>
public ModalComponentBuilder WithFileUpload(
Expand All @@ -713,15 +723,15 @@ public ModalComponentBuilder WithFileUpload(
/// Constructs and adds a <see cref="LabelBuilder"/> with a <see cref="FileUploadComponentBuilder"/>
/// to the current <see cref="ModalComponentBuilder"/>.
/// </summary>
/// <param name="label">The label around the <see cref="SelectMenuBuilder"/>.</param>
/// <param name="label">The label around the <see cref="FileUploadComponentBuilder"/>.</param>
/// <param name="customId">The custom id of the <see cref="FileUploadComponentBuilder"/>.</param>
/// <param name="minValues">The min values of the <see cref="FileUploadComponentBuilder"/>.</param>
/// <param name="maxValues">The max values of the <see cref="FileUploadComponentBuilder"/>.</param>
/// <param name="isRequired">Whether the <see cref="FileUploadComponentBuilder"/> is required.</param>
/// <param name="id">The id of the <see cref="FileUploadComponentBuilder"/>.</param>
/// <param name="description">The description around the <see cref="SelectMenuBuilder"/>.</param>
/// <param name="description">The description around the <see cref="FileUploadComponentBuilder"/>.</param>
/// <param name="labelId">
/// The id of the <see cref="LabelBuilder"/> wrapping the <see cref="SelectMenuBuilder"/>.
/// The id of the <see cref="LabelBuilder"/> wrapping the <see cref="FileUploadComponentBuilder"/>.
/// </param>
/// <returns>The current <see cref="ModalComponentBuilder"/>.</returns>
public ModalComponentBuilder WithFileUpload(
Expand Down Expand Up @@ -767,11 +777,11 @@ public ModalComponentBuilder WithTextDisplay(string content, int? id = null)
/// Constructs and adds a <see cref="LabelBuilder"/> with the provided <see cref="TextInputBuilder"/> to
/// the current <see cref="ModalComponentBuilder"/>.
/// </summary>
/// <param name="label">The label around the <see cref="SelectMenuBuilder"/>.</param>
/// <param name="label">The label around the <see cref="TextInputBuilder"/>.</param>
/// <param name="textInput">The text input to add.</param>
/// <param name="description">The description around the <see cref="SelectMenuBuilder"/>.</param>
/// <param name="description">The description around the <see cref="TextInputBuilder"/>.</param>
/// <param name="labelId">
/// The id of the <see cref="LabelBuilder"/> wrapping the <see cref="SelectMenuBuilder"/>.
/// The id of the <see cref="LabelBuilder"/> wrapping the <see cref="TextInputBuilder"/>.
/// </param>
/// <returns>The current <see cref="ModalComponentBuilder"/>.</returns>
public ModalComponentBuilder WithTextInput(
Expand Down Expand Up @@ -823,7 +833,7 @@ public ModalComponentBuilder WithTextInput(TextInputBuilder text, int row)
/// Constructs and adds a <see cref="LabelBuilder"/> with a <see cref="TextInputBuilder"/>
/// to the current <see cref="ModalComponentBuilder"/>.
/// </summary>
/// <param name="label">The label around the <see cref="SelectMenuBuilder"/>.</param>
/// <param name="label">The label around the <see cref="TextInputBuilder"/>.</param>
/// <param name="customId">The custom id of the <see cref="TextInputBuilder"/>.</param>
/// <param name="style">The style of the <see cref="TextInputBuilder"/>.</param>
/// <param name="placeholder">The placeholder of the <see cref="TextInputBuilder"/>.</param>
Expand All @@ -833,9 +843,9 @@ public ModalComponentBuilder WithTextInput(TextInputBuilder text, int row)
/// <param name="required">Whether the <see cref="TextInputBuilder"/> is required.</param>
/// <param name="value">The value of the <see cref="TextInputBuilder"/>.</param>
/// <param name="id">The id of the <see cref="TextInputBuilder"/>.</param>
/// <param name="description">The description around the <see cref="SelectMenuBuilder"/>.</param>
/// <param name="description">The description around the <see cref="TextInputBuilder"/>.</param>
/// <param name="labelId">
/// The id of the <see cref="LabelBuilder"/> wrapping the <see cref="SelectMenuBuilder"/>.
/// The id of the <see cref="LabelBuilder"/> wrapping the <see cref="TextInputBuilder"/>.
/// </param>
/// <returns>The current <see cref="ModalComponentBuilder"/>.</returns>
public ModalComponentBuilder WithTextInput(
Expand Down
4 changes: 4 additions & 0 deletions src/Discord.Net.Rest/API/Common/SelectMenuComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ internal class SelectMenuComponent : IInteractableComponent
[JsonProperty("max_values")]
public int MaxValues { get; set; }

[JsonProperty("required")]
public bool Required { get; set; }

[JsonProperty("disabled")]
public bool Disabled { get; set; }

Expand All @@ -51,6 +54,7 @@ public SelectMenuComponent(Discord.SelectMenuComponent component)
Placeholder = component.Placeholder;
MinValues = component.MinValues;
MaxValues = component.MaxValues;
Required = component.IsRequired;
Disabled = component.IsDisabled;
ChannelTypes = component.ChannelTypes.ToArray();
DefaultValues = component.DefaultValues.Select(x => new SelectMenuDefaultValue {Id = x.Id, Type = x.Type}).ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ internal static IMessageComponent ToEntity(this IMessageComponent component)
parsed.Placeholder.GetValueOrDefault(),
parsed.MinValues,
parsed.MaxValues,
parsed.Required,
parsed.Disabled,
parsed.Type,
parsed.Id.ToNullable(),
Expand Down