Skip to content

Commit

Permalink
Added validation for default selection values
Browse files Browse the repository at this point in the history
  • Loading branch information
AnotherZane committed Dec 21, 2023
1 parent db4c542 commit e7fd6a6
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using Disqord.Serialization.Json;
using Qommon;

Expand Down Expand Up @@ -140,6 +141,27 @@ protected override void OnValidate()
if (MinValues.HasValue && MaxValues.HasValue)
Guard.IsLessThanOrEqualTo(MinValues.Value, MaxValues.Value);

OptionalGuard.CheckValue(DefaultValues, defaultValues =>
{
Guard.IsBetween(defaultValues.Length, MinValues.GetValueOrDefault(Discord.Limits.Component.Selection.MinMinimumSelectedOptions), MaxValues.GetValueOrDefault(Discord.Limits.Component.Selection.MaxMaximumSelectedOptions));
switch (Type)
{
case ComponentType.UserSelection:
Guard.IsTrue(defaultValues.All(x => x.Type == DefaultSelectionValueType.User));
break;
case ComponentType.RoleSelection:
Guard.IsTrue(defaultValues.All(x => x.Type == DefaultSelectionValueType.Role));
break;
case ComponentType.MentionableSelection:
Guard.IsTrue(defaultValues.All(x => x.Type == DefaultSelectionValueType.User || x.Type == DefaultSelectionValueType.Role));
break;
case ComponentType.ChannelSelection:
Guard.IsTrue(defaultValues.All(x => x.Type == DefaultSelectionValueType.Channel));
break;
}
});

break;
}
case ComponentType.TextInput:
Expand Down

0 comments on commit e7fd6a6

Please sign in to comment.