Skip to content

Commit

Permalink
Merge branch 'main' into cleanup/nullability-and-other-things
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Sep 21, 2023
2 parents b3a0213 + 3f8aed6 commit cd51930
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,16 @@ internal DiscordBaseSelectComponent(ComponentType type, string placeholder, stri
if (defaultValues is not null)
{
if (defaultValues.Count() > maxOptions)
throw new
OverflowException("The amount of default values cannot exceed the maximum amount of selectable options.");
throw new OverflowException("The amount of default values cannot exceed the maximum amount of selectable options.");
if (type == ComponentType.MentionableSelect && defaultValues.Any(x => x.Type == "channel"))
throw new ArgumentException("The default values for a mentionable select must be of type user or role.",
nameof(defaultValues));
if (type == ComponentType.ChannelSelect && defaultValues.Any(x => x.Type == "channel"))
throw new ArgumentException("The default values for a channel select menus must be of type channel.",
nameof(defaultValues));
throw new ArgumentException("The default values for a mentionable select must be of type user or role.", nameof(defaultValues));
if (type == ComponentType.ChannelSelect && defaultValues.Any(x => x.Type != "channel"))
throw new ArgumentException("The default values for a channel select menus must be of type channel.", nameof(defaultValues));
if (type == ComponentType.UserSelect && defaultValues.Any(x => x.Type != "user"))
throw new ArgumentException("The default values for a user select menus must be of type user.",
nameof(defaultValues));
throw new ArgumentException("The default values for a user select menus must be of type user.", nameof(defaultValues));
if (type == ComponentType.RoleSelect && defaultValues.Any(x => x.Type != "role"))
throw new ArgumentException("The default values for a role select menus must be of type role.",
nameof(defaultValues));
throw new ArgumentException("The default values for a role select menus must be of type role.", nameof(defaultValues));
}

this.DefaultValues = defaultValues?.ToList();
}

Expand Down Expand Up @@ -118,22 +112,16 @@ internal DiscordBaseSelectComponent(ComponentType type, string label, string pla
if (defaultValues is not null)
{
if (defaultValues.Count() > maxOptions)
throw new
OverflowException("The amount of default values cannot exceed the maximum amount of selectable options.");
throw new OverflowException("The amount of default values cannot exceed the maximum amount of selectable options.");
if (type == ComponentType.MentionableSelect && defaultValues.Any(x => x.Type == "channel"))
throw new ArgumentException("The default values for a mentionable select must be of type user or role.",
nameof(defaultValues));
if (type == ComponentType.ChannelSelect && defaultValues.Any(x => x.Type == "channel"))
throw new ArgumentException("The default values for a channel select menus must be of type channel.",
nameof(defaultValues));
throw new ArgumentException("The default values for a mentionable select must be of type user or role.", nameof(defaultValues));
if (type == ComponentType.ChannelSelect && defaultValues.Any(x => x.Type != "channel"))
throw new ArgumentException("The default values for a channel select menus must be of type channel.", nameof(defaultValues));
if (type == ComponentType.UserSelect && defaultValues.Any(x => x.Type != "user"))
throw new ArgumentException("The default values for a user select menus must be of type user.",
nameof(defaultValues));
throw new ArgumentException("The default values for a user select menus must be of type user.", nameof(defaultValues));
if (type == ComponentType.RoleSelect && defaultValues.Any(x => x.Type != "role"))
throw new ArgumentException("The default values for a role select menus must be of type role.",
nameof(defaultValues));
throw new ArgumentException("The default values for a role select menus must be of type role.", nameof(defaultValues));
}

this.DefaultValues = defaultValues?.ToList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,11 @@ public DiscordSelectDefaultValue(DiscordChannel channel)
this.Id = channel.Id;
this.Type = "channel";
}

/// <summary>
/// Constructs a new <see cref="DiscordSelectDefaultValue"/> for a channel.
/// </summary>
internal DiscordSelectDefaultValue()
{
}
}

0 comments on commit cd51930

Please sign in to comment.