diff --git a/DiscordLab.Bot/API/Features/Embed/EmbedAuthorBuilder.cs b/DiscordLab.Bot/API/Features/Embed/EmbedAuthorBuilder.cs index c5eb37e..5f57aed 100644 --- a/DiscordLab.Bot/API/Features/Embed/EmbedAuthorBuilder.cs +++ b/DiscordLab.Bot/API/Features/Embed/EmbedAuthorBuilder.cs @@ -12,7 +12,6 @@ public class EmbedAuthorBuilder /// public EmbedAuthorBuilder() { - Base = new(); } /// @@ -22,42 +21,54 @@ public EmbedAuthorBuilder() /// The instance. public EmbedAuthorBuilder(Discord.EmbedAuthorBuilder builder) { - Base = builder; + Name = builder.Name; + IconUrl = builder.IconUrl; + Url = builder.Url; } /// /// Gets or sets the author name. /// [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitNull)] - public string? Name - { - get => Base.Name; - set => Base.Name = value; - } + public string? Name { get; set; } /// /// Gets or sets the icon URL. /// [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitNull)] - public string? IconUrl - { - get => Base.IconUrl; - set => Base.IconUrl = value; - } + public string? IconUrl { get; set; } /// /// Gets or sets the URL. /// [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitNull)] - public string? Url - { - get => Base.Url; - set => Base.Url = value; - } + public string? Url { get; set; } /// /// Gets the base of this builder. /// [YamlIgnore] - public Discord.EmbedAuthorBuilder Base { get; init; } + [Obsolete("Please use the properties of the DiscordLab.Bot.API.Features.Embed.EmbedAuthorBuilder instead.")] + public Discord.EmbedAuthorBuilder Base => this; + + /// + /// Changes a into a instance. + /// + /// The instance. + /// A copy of the instance. + public static implicit operator Discord.EmbedAuthorBuilder(EmbedAuthorBuilder builder) + { + Discord.EmbedAuthorBuilder copy = new(); + + if (builder.Name != null) + copy.WithName(builder.Name); + + if (builder.Url != null) + copy.WithUrl(builder.Url); + + if (builder.IconUrl != null) + copy.WithIconUrl(builder.IconUrl); + + return copy; + } } \ No newline at end of file diff --git a/DiscordLab.Bot/API/Features/Embed/EmbedBuilder.cs b/DiscordLab.Bot/API/Features/Embed/EmbedBuilder.cs index 98c541c..4ace171 100644 --- a/DiscordLab.Bot/API/Features/Embed/EmbedBuilder.cs +++ b/DiscordLab.Bot/API/Features/Embed/EmbedBuilder.cs @@ -10,98 +10,56 @@ public class EmbedBuilder /// /// Gets or sets the embed title. /// - public string Title - { - get => Base.Title; - set => Base.Title = value; - } + [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitNull)] + public string? Title { get; set; } /// /// Gets or sets the embed description. /// - public string Description - { - get => Base.Description; - set => Base.Description = value; - } + [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitNull)] + public string? Description { get; set; } /// /// Gets or sets the embed fields. /// - public IEnumerable Fields - { - get => Base.Fields.Select(x => new EmbedFieldBuilder(x)); - set => Base.Fields = value.Select(x => x.Base).ToList(); - } + [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitNull)] + public IEnumerable? Fields { get; set; } /// /// Gets or sets the color of the embed. In string so #, 0x or the raw hex value will work. /// [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitNull)] - public string? Color - { - get => Base.Color?.ToString(); - set - { - if (value == null) - { - Base.Color = null; - return; - } - - Base.Color = Discord.Color.Parse(value); - } - } + public string? Color { get; set; } /// /// Gets or sets the thumbnail URL of the embed. /// [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitNull)] - public string? ThumbnailUrl - { - get => Base.ThumbnailUrl; - set => Base.ThumbnailUrl = value; - } + public string? ThumbnailUrl { get; set; } /// /// Gets or sets the image URL of the embed. /// [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitNull)] - public string? ImageUrl - { - get => Base.ImageUrl; - set => Base.ImageUrl = value; - } + public string? ImageUrl { get; set; } /// /// Gets or sets the URL of the embed. /// [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitNull)] - public string? Url - { - get => Base.Url; - set => Base.Url = value; - } + public string? Url { get; set; } /// /// Gets or sets the footer of the embed. /// [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitNull)] - public EmbedFooterBuilder? Footer - { - get => Base.Footer != null ? new(Base.Footer) : null; - set => Base.Footer = value?.Base; - } + public EmbedFooterBuilder? Footer { get; set; } /// /// Gets or sets the author of the embed. /// [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitNull)] - public EmbedAuthorBuilder? Author - { - get => Base.Author != null ? new(Base.Author) : null; - set => Base.Author = value?.Base; - } + public EmbedAuthorBuilder? Author { get; set; } /// /// Gets or sets a value indicating whether a timestamp will be added to the footer of this embed. @@ -109,9 +67,6 @@ public EmbedAuthorBuilder? Author [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] public bool Timestamp { get; set; } - [YamlIgnore] - private Discord.EmbedBuilder Base { get; } = new(); - /// /// Changes a into a instance. /// @@ -119,38 +74,52 @@ public EmbedAuthorBuilder? Author /// A copy of the instance. public static implicit operator Discord.EmbedBuilder(EmbedBuilder builder) { + if ( + string.IsNullOrEmpty(builder.Title) + && string.IsNullOrEmpty(builder.Description) + && string.IsNullOrEmpty(builder.ThumbnailUrl) + && string.IsNullOrEmpty(builder.ImageUrl) + && (builder.Author == null || string.IsNullOrEmpty(builder.Author.Name)) + && (builder.Fields == null || !builder.Fields.Any())) + { + 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."); + } + Discord.EmbedBuilder copy = new(); - if (builder.Base.Title != null) - copy.WithTitle(builder.Base.Title); + if (builder.Title != null) + copy.WithTitle(builder.Title); - if (builder.Base.Description != null) - copy.WithDescription(builder.Base.Description); + if (builder.Description != null) + copy.WithDescription(builder.Description); - if (builder.Base.Color.HasValue) - copy.WithColor(builder.Base.Color.Value); + if (builder.Color != null) + copy.WithColor(Discord.Color.Parse(builder.Color)); - if (builder.Base.Url != null) - copy.WithUrl(builder.Base.Url); + if (builder.Url != null) + copy.WithUrl(builder.Url); - if (builder.Base.ImageUrl != null) - copy.WithImageUrl(builder.Base.ImageUrl); + if (builder.ImageUrl != null) + copy.WithImageUrl(builder.ImageUrl); - if (builder.Base.ThumbnailUrl != null) - copy.WithThumbnailUrl(builder.Base.ThumbnailUrl); + if (builder.ThumbnailUrl != null) + copy.WithThumbnailUrl(builder.ThumbnailUrl); if (builder.Timestamp) copy.WithCurrentTimestamp(); - if (builder.Base.Footer != null) - copy.WithFooter(builder.Base.Footer); + if (builder.Footer != null) + copy.WithFooter(builder.Footer); - if (builder.Base.Author != null) - copy.WithAuthor(builder.Base.Author); + if (builder.Author != null) + copy.WithAuthor(builder.Author); - foreach (Discord.EmbedFieldBuilder field in builder.Base.Fields) + if (builder.Fields != null) { - copy.AddField(field.Name, field.Value, field.IsInline); + foreach (var field in builder.Fields) + { + copy.AddField(field); + } } return copy; diff --git a/DiscordLab.Bot/API/Features/Embed/EmbedFieldBuilder.cs b/DiscordLab.Bot/API/Features/Embed/EmbedFieldBuilder.cs index 4511390..ead2016 100644 --- a/DiscordLab.Bot/API/Features/Embed/EmbedFieldBuilder.cs +++ b/DiscordLab.Bot/API/Features/Embed/EmbedFieldBuilder.cs @@ -12,7 +12,6 @@ public class EmbedFieldBuilder /// public EmbedFieldBuilder() { - Base = new(); } /// @@ -22,40 +21,52 @@ public EmbedFieldBuilder() /// The instance. public EmbedFieldBuilder(Discord.EmbedFieldBuilder builder) { - Base = builder; + Name = builder.Name; + IsInline = builder.IsInline; + + if (builder.Value is string value) + Value = value; } /// /// Gets or sets the field name. /// - public string Name - { - get => Base.Name; - set => Base.Name = value; - } + public string Name { get; set; } = string.Empty; /// /// Gets or sets the field value. /// - public string Value - { - get => Base.Value.ToString(); - set => Base.Value = value; - } + public string? Value { get; set; } /// /// Gets or sets a value indicating whether the field is inline. /// [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] - public bool IsInline - { - get => Base.IsInline; - set => Base.IsInline = value; - } + public bool IsInline { get; set; } /// /// Gets the base builder. /// [YamlIgnore] - public Discord.EmbedFieldBuilder Base { get; init; } + [Obsolete("Please use the properties of the DiscordLab.Bot.API.Features.Embed.EmbedFieldBuilder instead.")] + public Discord.EmbedFieldBuilder Base => this; + + /// + /// Changes a into a instance. + /// + /// The instance. + /// A copy of the instance. + public static implicit operator Discord.EmbedFieldBuilder(EmbedFieldBuilder builder) + { + Discord.EmbedFieldBuilder copy = new(); + + copy.WithName(builder.Name); + + if (builder.Value != null) + copy.WithValue(builder.Value); + + copy.WithIsInline(builder.IsInline); + + return copy; + } } \ No newline at end of file diff --git a/DiscordLab.Bot/API/Features/Embed/EmbedFooterBuilder.cs b/DiscordLab.Bot/API/Features/Embed/EmbedFooterBuilder.cs index 50e8f1f..59ef80f 100644 --- a/DiscordLab.Bot/API/Features/Embed/EmbedFooterBuilder.cs +++ b/DiscordLab.Bot/API/Features/Embed/EmbedFooterBuilder.cs @@ -12,7 +12,6 @@ public class EmbedFooterBuilder /// public EmbedFooterBuilder() { - Base = new(); } /// @@ -22,32 +21,44 @@ public EmbedFooterBuilder() /// The instance. public EmbedFooterBuilder(Discord.EmbedFooterBuilder builder) { - Base = builder; + Text = builder.Text; + IconUrl = builder.IconUrl; } /// /// Gets or sets the text for this footer. /// [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitNull)] - public string? Text - { - get => Base.Text; - set => Base.Text = value; - } + public string? Text { get; set; } /// /// Gets or sets the icon URl for this footer. /// [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitNull)] - public string? IconUrl - { - get => Base.IconUrl; - set => Base.IconUrl = value; - } + public string? IconUrl { get; set; } /// /// Gets the base builder object. /// [YamlIgnore] - public Discord.EmbedFooterBuilder Base { get; init; } + [Obsolete("Please use the properties of the DiscordLab.Bot.API.Features.Embed.EmbedFooterBuilder instead.")] + public Discord.EmbedFooterBuilder Base => this; + + /// + /// Changes a into a instance. + /// + /// The instance. + /// A copy of the instance. + public static implicit operator Discord.EmbedFooterBuilder(EmbedFooterBuilder builder) + { + Discord.EmbedFooterBuilder copy = new(); + + if (builder.Text != null) + copy.WithText(builder.Text); + + if (builder.IconUrl != null) + copy.WithIconUrl(builder.IconUrl); + + return copy; + } } \ No newline at end of file