Browse Source

Merge 796d6df0c6 into 143fb2808b

pull/1132/merge
ericmck2000 GitHub 7 years ago
parent
commit
5db864ef2a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 6 deletions
  1. +25
    -6
      src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs

+ 25
- 6
src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs View File

@@ -196,6 +196,17 @@ namespace Discord
AddField(field);
return this;
}
public EmbedBuilder AddBlankField(bool inline = false)
{
var field = new EmbedFieldBuilder()
.WithIsInline(inline)
.WithName(null)
.WithValue(null);
AddField(field);
return this;
}
public EmbedBuilder AddField(EmbedFieldBuilder field)
{
if (Fields.Count >= MaxFieldCount)
@@ -231,6 +242,8 @@ namespace Discord
{
private string _name;
private string _value;
private const string emptyString = "_ _";
public const int MaxFieldNameLength = 256;
public const int MaxFieldValueLength = 1024;

@@ -239,9 +252,12 @@ namespace Discord
get => _name;
set
{
if (string.IsNullOrWhiteSpace(value)) throw new ArgumentException($"Field name must not be null, empty or entirely whitespace.", nameof(Name));
if (value.Length > MaxFieldNameLength) throw new ArgumentException($"Field name length must be less than or equal to {MaxFieldNameLength}.", nameof(Name));
_name = value;
if (string.IsNullOrWhiteSpace(value))
_name = emptyString;
else if (value.Length > MaxFieldNameLength)
throw new ArgumentException($"Field name length must be less than or equal to {MaxFieldNameLength}.", nameof(Name));
else
_name = value;
}
}

@@ -251,9 +267,12 @@ namespace Discord
set
{
var stringValue = value?.ToString();
if (string.IsNullOrEmpty(stringValue)) throw new ArgumentException($"Field value must not be null or empty.", nameof(Value));
if (stringValue.Length > MaxFieldValueLength) throw new ArgumentException($"Field value length must be less than or equal to {MaxFieldValueLength}.", nameof(Value));
_value = stringValue;
if (string.IsNullOrWhiteSpace(stringValue))
_value = emptyString;
else if (stringValue.Length > MaxFieldValueLength)
throw new ArgumentException($"Field value length must be less than or equal to {MaxFieldValueLength}.", nameof(Value));
else
_value = stringValue;
}
}
public bool IsInline { get; set; }


Loading…
Cancel
Save