[Fix] Prevent multiline values in short TextInputs (#2789)

* Prevent multiline values in short Textinputs

* Change exception

* Move check to build method

* Update src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs

---------

Co-authored-by: Mihail Gribkov <61027276+Misha-133@users.noreply.github.com>
This commit is contained in:
Karlo
2023-10-17 19:43:56 +02:00
committed by GitHub
parent 7b5c40aab6
commit 33e8340765

View File

@@ -1406,6 +1406,9 @@ namespace Discord
/// <exception cref="ArgumentOutOfRangeException">
/// <see cref="Value"/>.Length is greater than <see cref="LargestMaxLength"/> or <see cref="MaxLength"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// <see cref="Style"/> is <see cref="TextInputStyle.Short"/> and <see cref="Value"/> contains a new line character.
/// </exception>
public string Value
{
get => _value;
@@ -1415,6 +1418,7 @@ namespace Discord
throw new ArgumentOutOfRangeException(nameof(value), $"Value must not be longer than {MaxLength ?? LargestMaxLength}.");
if (value?.Length < (MinLength ?? 0))
throw new ArgumentOutOfRangeException(nameof(value), $"Value must not be shorter than {MinLength}");
_value = value;
}
}
@@ -1550,6 +1554,9 @@ namespace Discord
throw new ArgumentException("TextInputComponents must have a custom id.", nameof(CustomId));
if (string.IsNullOrWhiteSpace(Label))
throw new ArgumentException("TextInputComponents must have a label.", nameof(Label));
if (Style == TextInputStyle.Short && Value?.Contains('\n') == true)
throw new ArgumentException($"Value must not contain new line characters when style is {TextInputStyle.Short}.", nameof(Value));
return new TextInputComponent(CustomId, Label, Placeholder, MinLength, MaxLength, Style, Required, Value);
}
}