Skip to content

Commit

Permalink
Allow empty options through in ComponentJsonModel
Browse files Browse the repository at this point in the history
  • Loading branch information
Quahu committed Aug 2, 2024
1 parent 6db87ea commit 9391df6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,24 @@ protected override void OnValidate()
if (Type == ComponentType.StringSelection)
{
OptionalGuard.HasValue(Options);
Guard.IsLessThanOrEqualTo(Options.Value.Length, Discord.Limits.Component.Selection.MaxOptionAmount);
Guard.HasSizeLessThanOrEqualTo(Options.Value, Discord.Limits.Component.Selection.MaxOptionAmount);

for (var i = 0; i < Options.Value.Length; i++)
Options.Value[i].Validate();
}
else
{
OptionalGuard.HasNoValue(Options, "Options are not supported by entity selection components.");
OptionalGuard.CheckValue(Options, options =>
{
try
{
Guard.HasSizeEqualTo(options, 0);
}
catch (Exception ex)
{
throw new ArgumentException("Options are not supported by entity selection components.", ex);
}
});
}

OptionalGuard.CheckValue(Placeholder, placeholder =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ protected internal override LocalComponent ToLocalComponent()
MinimumSelectedOptions = Optional.FromNullable(_minimumSelectedOptions),
MaximumSelectedOptions = Optional.FromNullable(_maximumSelectedOptions),
IsDisabled = _isDisabled,
Options = _options.ToArray()
};

if (_type is SelectionComponentType.Channel or SelectionComponentType.Mentionable
Expand All @@ -198,6 +197,11 @@ protected internal override LocalComponent ToLocalComponent()
selection.WithChannelTypes(_channelTypes);
}

if (_type != SelectionComponentType.String)
{
selection.WithOptions(_options);
}

return selection;
}
}

0 comments on commit 9391df6

Please sign in to comment.