@@ -10,147 +10,116 @@ public class EmbedBuilder
1010 /// <summary>
1111 /// Gets or sets the embed title.
1212 /// </summary>
13- public string Title
14- {
15- get => Base . Title ;
16- set => Base . Title = value ;
17- }
13+ [ YamlMember ( DefaultValuesHandling = DefaultValuesHandling . OmitNull ) ]
14+ public string ? Title { get ; set ; }
1815
1916 /// <summary>
2017 /// Gets or sets the embed description.
2118 /// </summary>
22- public string Description
23- {
24- get => Base . Description ;
25- set => Base . Description = value ;
26- }
19+ [ YamlMember ( DefaultValuesHandling = DefaultValuesHandling . OmitNull ) ]
20+ public string ? Description { get ; set ; }
2721
2822 /// <summary>
2923 /// Gets or sets the embed fields.
3024 /// </summary>
31- public IEnumerable < EmbedFieldBuilder > Fields
32- {
33- get => Base . Fields . Select ( x => new EmbedFieldBuilder ( x ) ) ;
34- set => Base . Fields = value . Select ( x => x . Base ) . ToList ( ) ;
35- }
25+ [ YamlMember ( DefaultValuesHandling = DefaultValuesHandling . OmitNull ) ]
26+ public IEnumerable < EmbedFieldBuilder > ? Fields { get ; set ; }
3627
3728 /// <summary>
3829 /// Gets or sets the color of the embed. In string so #, 0x or the raw hex value will work.
3930 /// </summary>
4031 [ YamlMember ( DefaultValuesHandling = DefaultValuesHandling . OmitNull ) ]
41- public string ? Color
42- {
43- get => Base . Color ? . ToString ( ) ;
44- set
45- {
46- if ( value == null )
47- {
48- Base . Color = null ;
49- return ;
50- }
51-
52- Base . Color = Discord . Color . Parse ( value ) ;
53- }
54- }
32+ public string ? Color { get ; set ; }
5533
5634 /// <summary>
5735 /// Gets or sets the thumbnail URL of the embed.
5836 /// </summary>
5937 [ YamlMember ( DefaultValuesHandling = DefaultValuesHandling . OmitNull ) ]
60- public string ? ThumbnailUrl
61- {
62- get => Base . ThumbnailUrl ;
63- set => Base . ThumbnailUrl = value ;
64- }
38+ public string ? ThumbnailUrl { get ; set ; }
6539
6640 /// <summary>
6741 /// Gets or sets the image URL of the embed.
6842 /// </summary>
6943 [ YamlMember ( DefaultValuesHandling = DefaultValuesHandling . OmitNull ) ]
70- public string ? ImageUrl
71- {
72- get => Base . ImageUrl ;
73- set => Base . ImageUrl = value ;
74- }
44+ public string ? ImageUrl { get ; set ; }
7545
7646 /// <summary>
7747 /// Gets or sets the URL of the embed.
7848 /// </summary>
7949 [ YamlMember ( DefaultValuesHandling = DefaultValuesHandling . OmitNull ) ]
80- public string ? Url
81- {
82- get => Base . Url ;
83- set => Base . Url = value ;
84- }
50+ public string ? Url { get ; set ; }
8551
8652 /// <summary>
8753 /// Gets or sets the footer of the embed.
8854 /// </summary>
8955 [ YamlMember ( DefaultValuesHandling = DefaultValuesHandling . OmitNull ) ]
90- public EmbedFooterBuilder ? Footer
91- {
92- get => Base . Footer != null ? new ( Base . Footer ) : null ;
93- set => Base . Footer = value ? . Base ;
94- }
56+ public EmbedFooterBuilder ? Footer { get ; set ; }
9557
9658 /// <summary>
9759 /// Gets or sets the author of the embed.
9860 /// </summary>
9961 [ YamlMember ( DefaultValuesHandling = DefaultValuesHandling . OmitNull ) ]
100- public EmbedAuthorBuilder ? Author
101- {
102- get => Base . Author != null ? new ( Base . Author ) : null ;
103- set => Base . Author = value ? . Base ;
104- }
62+ public EmbedAuthorBuilder ? Author { get ; set ; }
10563
10664 /// <summary>
10765 /// Gets or sets a value indicating whether a timestamp will be added to the footer of this embed.
10866 /// </summary>
10967 [ YamlMember ( DefaultValuesHandling = DefaultValuesHandling . OmitDefaults ) ]
11068 public bool Timestamp { get ; set ; }
11169
112- [ YamlIgnore ]
113- private Discord . EmbedBuilder Base { get ; } = new ( ) ;
114-
11570 /// <summary>
11671 /// Changes a <see cref="EmbedBuilder"/> into a <see cref="Discord.EmbedBuilder"/> instance.
11772 /// </summary>
11873 /// <param name="builder">The <see cref="EmbedBuilder"/> instance.</param>
11974 /// <returns>A copy of the <see cref="Discord.EmbedBuilder"/> instance.</returns>
12075 public static implicit operator Discord . EmbedBuilder ( EmbedBuilder builder )
12176 {
77+ if (
78+ string . IsNullOrEmpty ( builder . Title )
79+ && string . IsNullOrEmpty ( builder . Description )
80+ && string . IsNullOrEmpty ( builder . ThumbnailUrl )
81+ && string . IsNullOrEmpty ( builder . ImageUrl )
82+ && ( builder . Author == null || string . IsNullOrEmpty ( builder . Author . Name ) )
83+ && ( builder . Fields == null || ! builder . Fields . Any ( ) ) )
84+ {
85+ throw new ArgumentNullException ( "An embed must contain at least on of the following: title, description, thumbnail, image, author (with a name) or at least 1 field." ) ;
86+ }
87+
12288 Discord . EmbedBuilder copy = new ( ) ;
12389
124- if ( builder . Base . Title != null )
125- copy . WithTitle ( builder . Base . Title ) ;
90+ if ( builder . Title != null )
91+ copy . WithTitle ( builder . Title ) ;
12692
127- if ( builder . Base . Description != null )
128- copy . WithDescription ( builder . Base . Description ) ;
93+ if ( builder . Description != null )
94+ copy . WithDescription ( builder . Description ) ;
12995
130- if ( builder . Base . Color . HasValue )
131- copy . WithColor ( builder . Base . Color . Value ) ;
96+ if ( builder . Color != null )
97+ copy . WithColor ( Discord . Color . Parse ( builder . Color ) ) ;
13298
133- if ( builder . Base . Url != null )
134- copy . WithUrl ( builder . Base . Url ) ;
99+ if ( builder . Url != null )
100+ copy . WithUrl ( builder . Url ) ;
135101
136- if ( builder . Base . ImageUrl != null )
137- copy . WithImageUrl ( builder . Base . ImageUrl ) ;
102+ if ( builder . ImageUrl != null )
103+ copy . WithImageUrl ( builder . ImageUrl ) ;
138104
139- if ( builder . Base . ThumbnailUrl != null )
140- copy . WithThumbnailUrl ( builder . Base . ThumbnailUrl ) ;
105+ if ( builder . ThumbnailUrl != null )
106+ copy . WithThumbnailUrl ( builder . ThumbnailUrl ) ;
141107
142108 if ( builder . Timestamp )
143109 copy . WithCurrentTimestamp ( ) ;
144110
145- if ( builder . Base . Footer != null )
146- copy . WithFooter ( builder . Base . Footer ) ;
111+ if ( builder . Footer != null )
112+ copy . WithFooter ( builder . Footer ) ;
147113
148- if ( builder . Base . Author != null )
149- copy . WithAuthor ( builder . Base . Author ) ;
114+ if ( builder . Author != null )
115+ copy . WithAuthor ( builder . Author ) ;
150116
151- foreach ( Discord . EmbedFieldBuilder field in builder . Base . Fields )
117+ if ( builder . Fields != null )
152118 {
153- copy . AddField ( field . Name , field . Value , field . IsInline ) ;
119+ foreach ( var field in builder . Fields )
120+ {
121+ copy . AddField ( field ) ;
122+ }
154123 }
155124
156125 return copy ;
0 commit comments