diff --git a/DisCatSharp.CommandsNext/CommandsNextExtension.cs b/DisCatSharp.CommandsNext/CommandsNextExtension.cs
index 5955d8e5ec..c8671306a6 100644
--- a/DisCatSharp.CommandsNext/CommandsNextExtension.cs
+++ b/DisCatSharp.CommandsNext/CommandsNextExtension.cs
@@ -380,7 +380,7 @@ public async Task DefaultHelpAsync(CommandContext ctx, [Description("Command to
var helpMessage = helpBuilder.Build();
- var builder = new DiscordMessageBuilder().WithContent(helpMessage.Content).WithEmbed(helpMessage.Embed);
+ var builder = new DiscordMessageBuilder().WithContent(helpMessage.Content).AddEmbed(helpMessage.Embed);
if (!ctx.Config.DmHelp || ctx.Channel is DiscordDmChannel || ctx.Guild == null)
await ctx.RespondAsync(builder).ConfigureAwait(false);
diff --git a/DisCatSharp.Interactivity/EventHandling/Paginator.cs b/DisCatSharp.Interactivity/EventHandling/Paginator.cs
index 5600978159..9907455897 100644
--- a/DisCatSharp.Interactivity/EventHandling/Paginator.cs
+++ b/DisCatSharp.Interactivity/EventHandling/Paginator.cs
@@ -249,7 +249,7 @@ private async Task PaginateAsync(IPaginationRequest p, DiscordEmoji emoji)
var page = await p.GetPageAsync().ConfigureAwait(false);
var builder = new DiscordMessageBuilder()
.WithContent(page.Content)
- .WithEmbed(page.Embed);
+ .AddEmbed(page.Embed);
await builder.ModifyAsync(msg).ConfigureAwait(false);
}
diff --git a/DisCatSharp.Interactivity/InteractivityExtension.cs b/DisCatSharp.Interactivity/InteractivityExtension.cs
index 7c6c68da67..436c15eb7f 100644
--- a/DisCatSharp.Interactivity/InteractivityExtension.cs
+++ b/DisCatSharp.Interactivity/InteractivityExtension.cs
@@ -746,7 +746,7 @@ public async Task SendPaginatedMessageAsync(
var builder = new DiscordMessageBuilder()
.WithContent(pages.First().Content)
- .WithEmbed(pages.First().Embed)
+ .AddEmbed(pages.First().Embed)
.AddComponents(bts.ButtonArray);
var message = await builder.SendAsync(channel).ConfigureAwait(false);
@@ -830,7 +830,7 @@ public async Task SendPaginatedMessageAsync(
{
var builder = new DiscordMessageBuilder()
.WithContent(pages.First().Content)
- .WithEmbed(pages.First().Embed);
+ .AddEmbed(pages.First().Embed);
var m = await builder.SendAsync(channel).ConfigureAwait(false);
var timeout = timeoutOverride ?? this.Config.Timeout;
diff --git a/DisCatSharp/Entities/Core/DisCatSharpBuilder.cs b/DisCatSharp/Entities/Core/DisCatSharpBuilder.cs
index 2d0e5b56d2..c944e17f49 100644
--- a/DisCatSharp/Entities/Core/DisCatSharpBuilder.cs
+++ b/DisCatSharp/Entities/Core/DisCatSharpBuilder.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
namespace DisCatSharp.Entities.Core;
@@ -8,12 +9,86 @@ namespace DisCatSharp.Entities.Core;
public class DisCatSharpBuilder
{
///
- /// The components.
+ /// The attachments of this builder.
///
- internal readonly List ComponentsInternal = [];
+ internal List AttachmentsInternal { get; } = [];
///
- /// Components to send.
+ /// The components of this builder.
+ ///
+ internal List ComponentsInternal { get; } = [];
+
+ ///
+ /// The embeds of this builder.
+ ///
+ internal List EmbedsInternal { get; } = [];
+
+ ///
+ /// The files of this builder.
+ ///
+ internal List FilesInternal { get; } = [];
+
+ ///
+ /// The content of this builder.
+ ///
+ internal string? ContentInternal { get; set; }
+
+ ///
+ /// The components of this builder.
///
public IReadOnlyList Components => this.ComponentsInternal;
+
+ ///
+ /// The content of this builder.
+ ///
+ public string? Content
+ {
+ get => this.ContentInternal;
+ set
+ {
+ if (value is { Length: > 2000 })
+ throw new ArgumentException("Content length cannot exceed 2000 characters.", nameof(value));
+
+ this.ContentInternal = value;
+ }
+ }
+
+ ///
+ /// The embeds for this builder.
+ ///
+ public IReadOnlyList Embeds => this.EmbedsInternal;
+
+ ///
+ /// The attachments of this builder.
+ ///
+ public IReadOnlyList Attachments => this.AttachmentsInternal;
+
+ ///
+ /// The files of this builder.
+ ///
+ public IReadOnlyList Files => this.FilesInternal;
+
+ ///
+ /// Clears the components on this builder.
+ ///
+ public void ClearComponents()
+ => this.ComponentsInternal.Clear();
+
+ ///
+ /// Allows for clearing the builder so that it can be used again.
+ ///
+ public virtual void Clear()
+ {
+ this.Content = null;
+ this.FilesInternal.Clear();
+ this.EmbedsInternal.Clear();
+ this.AttachmentsInternal.Clear();
+ this.ComponentsInternal.Clear();
+ }
+
+ ///
+ /// Validates the builder.
+ ///
+ internal virtual void Validate()
+ { }
}
diff --git a/DisCatSharp/Entities/Interaction/DiscordFollowupMessageBuilder.cs b/DisCatSharp/Entities/Interaction/DiscordFollowupMessageBuilder.cs
index 04126d5137..b5693d456f 100644
--- a/DisCatSharp/Entities/Interaction/DiscordFollowupMessageBuilder.cs
+++ b/DisCatSharp/Entities/Interaction/DiscordFollowupMessageBuilder.cs
@@ -12,14 +12,6 @@ namespace DisCatSharp.Entities;
///
public sealed class DiscordFollowupMessageBuilder : DisCatSharpBuilder
{
- private readonly List _embeds = [];
-
- private readonly List _files = [];
-
- internal readonly List AttachmentsInternal = [];
-
- private string _content;
-
///
/// Whether flags were changed.
///
@@ -91,36 +83,6 @@ public bool NotificationsSuppressed
private bool NOTI_SUP { get; set; }
- ///
- /// Message to send on followup message.
- ///
- public string Content
- {
- get => this._content;
- set
- {
- if (value is { Length: > 2000 })
- throw new ArgumentException("Content length cannot exceed 2000 characters.", nameof(value));
-
- this._content = value;
- }
- }
-
- ///
- /// Embeds to send on followup message.
- ///
- public IReadOnlyList Embeds => this._embeds;
-
- ///
- /// Files to send on this followup message.
- ///
- public IReadOnlyList Files => this._files;
-
- ///
- /// Attachments to be send with this followup request.
- ///
- public IReadOnlyList Attachments => this.AttachmentsInternal;
-
///
/// Mentions to send on this followup message.
///
@@ -217,7 +179,7 @@ public DiscordFollowupMessageBuilder WithContent(string content)
/// The builder to chain calls with.
public DiscordFollowupMessageBuilder AddEmbed(DiscordEmbed embed)
{
- this._embeds.Add(embed);
+ this.EmbedsInternal.Add(embed);
return this;
}
@@ -228,7 +190,7 @@ public DiscordFollowupMessageBuilder AddEmbed(DiscordEmbed embed)
/// The builder to chain calls with.
public DiscordFollowupMessageBuilder AddEmbeds(IEnumerable embeds)
{
- this._embeds.AddRange(embeds);
+ this.EmbedsInternal.AddRange(embeds);
return this;
}
@@ -248,13 +210,13 @@ public DiscordFollowupMessageBuilder AddFile(string filename, Stream data, bool
if (this.Files.Count >= 10)
throw new ArgumentException("Cannot send more than 10 files with a single message.");
- if (this._files.Any(x => x.Filename == filename))
+ if (this.FilesInternal.Any(x => x.Filename == filename))
throw new ArgumentException("A File with that filename already exists");
if (resetStreamPosition)
- this._files.Add(new(filename, data, data.Position, description: description));
+ this.FilesInternal.Add(new(filename, data, data.Position, description: description));
else
- this._files.Add(new(filename, data, null, description: description));
+ this.FilesInternal.Add(new(filename, data, null, description: description));
return this;
}
@@ -274,13 +236,13 @@ public DiscordFollowupMessageBuilder AddFile(FileStream stream, bool resetStream
if (this.Files.Count >= 10)
throw new ArgumentException("Cannot send more than 10 files with a single message.");
- if (this._files.Any(x => x.Filename == stream.Name))
+ if (this.FilesInternal.Any(x => x.Filename == stream.Name))
throw new ArgumentException("A File with that filename already exists");
if (resetStreamPosition)
- this._files.Add(new(stream.Name, stream, stream.Position, description: description));
+ this.FilesInternal.Add(new(stream.Name, stream, stream.Position, description: description));
else
- this._files.Add(new(stream.Name, stream, null, description: description));
+ this.FilesInternal.Add(new(stream.Name, stream, null, description: description));
return this;
}
@@ -301,13 +263,13 @@ public DiscordFollowupMessageBuilder AddFiles(Dictionary files,
foreach (var file in files)
{
- if (this._files.Any(x => x.Filename == file.Key))
+ if (this.FilesInternal.Any(x => x.Filename == file.Key))
throw new ArgumentException("A File with that filename already exists");
if (resetStreamPosition)
- this._files.Add(new(file.Key, file.Value, file.Value.Position));
+ this.FilesInternal.Add(new(file.Key, file.Value, file.Value.Position));
else
- this._files.Add(new(file.Key, file.Value, null));
+ this.FilesInternal.Add(new(file.Key, file.Value, null));
}
return this;
@@ -381,40 +343,28 @@ public DiscordFollowupMessageBuilder AsSilentMessage()
return this;
}
- ///
- /// Clears all message components on this builder.
- ///
- public void ClearComponents()
- => this.ComponentsInternal.Clear();
-
///
/// Clears the poll from this builder.
///
public void ClearPoll()
=> this.Poll = null;
- ///
- /// Allows for clearing the Followup Message builder so that it can be used again to send a new message.
- ///
- public void Clear()
+ ///
+ public override void Clear()
{
- this.Content = null;
- this._embeds.Clear();
this.IsTts = false;
this.Mentions = null;
- this._files.Clear();
this.IsEphemeral = false;
- this.ComponentsInternal.Clear();
+ base.Clear();
}
- ///
- /// Validates the builder.
- ///
- internal void Validate()
+ ///
+ internal override void Validate()
{
- if (this.Files?.Count == 0 && string.IsNullOrEmpty(this.Content) && !this.Embeds.Any() && !this.Components.Any() && this.Poll is null && this?.Attachments.Count == 0)
+ if (this.Files?.Count == 0 && string.IsNullOrEmpty(this.Content) && this.EmbedsInternal.Count == 0 && this.ComponentsInternal.Count == 0 && this.Poll is null && this.AttachmentsInternal.Count == 0)
throw new ArgumentException("You must specify content, an embed, a component, a poll, or at least one file.");
this.Poll?.Validate();
+ base.Validate();
}
}
diff --git a/DisCatSharp/Entities/Interaction/DiscordInteractionModalBuilder.cs b/DisCatSharp/Entities/Interaction/DiscordInteractionModalBuilder.cs
index 0a999cd6b8..42ddc26e4d 100644
--- a/DisCatSharp/Entities/Interaction/DiscordInteractionModalBuilder.cs
+++ b/DisCatSharp/Entities/Interaction/DiscordInteractionModalBuilder.cs
@@ -9,10 +9,15 @@ namespace DisCatSharp.Entities;
///
/// Constructs an interaction modal response.
///
-public sealed class DiscordInteractionModalBuilder : DisCatSharpBuilder
+public sealed class DiscordInteractionModalBuilder
{
private readonly List _callbackHints = [];
+ ///
+ /// The components.
+ ///
+ internal readonly List ComponentsInternal = [];
+
private string _title;
///
@@ -24,6 +29,11 @@ public DiscordInteractionModalBuilder(string title = null, string customId = nul
this.CustomId = customId ?? Guid.NewGuid().ToString();
}
+ ///
+ /// Components to send. Please use instead.
+ ///
+ public IReadOnlyList Components => this.ComponentsInternal;
+
///
/// Title of modal.
///
@@ -147,9 +157,7 @@ public DiscordInteractionModalBuilder AddModalComponents(params DiscordComponent
foreach (var ar in ara)
this.ComponentsInternal.Add(new DiscordActionRowComponent(
- [
- ar
- ]));
+ [ar]));
return this;
}
@@ -181,9 +189,7 @@ public DiscordInteractionModalBuilder AddModalComponents(IEnumerable _callbackHints = [];
- private readonly List _choices = [];
-
- private readonly List _embeds = [];
-
- private readonly List _files = [];
-
- internal readonly List AttachmentsInternal = [];
-
- private string _content;
-
///
/// Whether flags were changed.
///
@@ -42,12 +32,14 @@ public DiscordInteractionResponseBuilder()
/// The builder to copy.
public DiscordInteractionResponseBuilder(DiscordMessageBuilder builder)
{
- this._content = builder.Content;
+ this.Content = builder.Content;
this.Mentions = builder.Mentions;
- this._embeds.AddRange(builder.Embeds);
+ this.EmbedsInternal.AddRange(builder.Embeds);
this.ComponentsInternal.AddRange(builder.Components);
}
+ internal List ChoicesInternal { get; } = [];
+
///
/// Whether this interaction response is text-to-speech.
///
@@ -114,41 +106,11 @@ internal bool IsVoiceMessage
private bool VOICE_MSG { get; set; }
- ///
- /// Content of the message to send.
- ///
- public string Content
- {
- get => this._content;
- set
- {
- if (value is { Length: > 2000 })
- throw new ArgumentException("Content length cannot exceed 2000 characters.", nameof(value));
-
- this._content = value;
- }
- }
-
- ///
- /// Embeds to send on this interaction response.
- ///
- public IReadOnlyList Embeds => this._embeds;
-
- ///
- /// Files to send on this interaction response.
- ///
- public IReadOnlyList Files => this._files;
-
///
/// The choices to send on this interaction response.
/// Mutually exclusive with content, embed, and components.
///
- public IReadOnlyList Choices => this._choices;
-
- ///
- /// Attachments to be send with this interaction response.
- ///
- public IReadOnlyList Attachments => this.AttachmentsInternal;
+ public IReadOnlyList Choices => this.ChoicesInternal;
///
/// Mentions to send on this interaction response.
@@ -315,7 +277,7 @@ public DiscordInteractionResponseBuilder WithContent(string content)
public DiscordInteractionResponseBuilder AddEmbed(DiscordEmbed embed)
{
if (embed != null)
- this._embeds.Add(embed); // Interactions will 400 silently //
+ this.EmbedsInternal.Add(embed); // Interactions will 400 silently //
return this;
}
@@ -326,7 +288,7 @@ public DiscordInteractionResponseBuilder AddEmbed(DiscordEmbed embed)
/// The current builder to chain calls with.
public DiscordInteractionResponseBuilder AddEmbeds(IEnumerable embeds)
{
- this._embeds.AddRange(embeds);
+ this.EmbedsInternal.AddRange(embeds);
return this;
}
@@ -346,13 +308,13 @@ public DiscordInteractionResponseBuilder AddFile(string filename, Stream data, b
if (this.Files.Count >= 10)
throw new ArgumentException("Cannot send more than 10 files with a single message.");
- if (this._files.Any(x => x.Filename == filename))
+ if (this.FilesInternal.Any(x => x.Filename == filename))
throw new ArgumentException("A File with that filename already exists");
if (resetStreamPosition)
- this._files.Add(new(filename, data, data.Position, description: description));
+ this.FilesInternal.Add(new(filename, data, data.Position, description: description));
else
- this._files.Add(new(filename, data, null, description: description));
+ this.FilesInternal.Add(new(filename, data, null, description: description));
return this;
}
@@ -372,13 +334,13 @@ public DiscordInteractionResponseBuilder AddFile(FileStream stream, bool resetSt
if (this.Files.Count >= 10)
throw new ArgumentException("Cannot send more than 10 files with a single message.");
- if (this._files.Any(x => x.Filename == stream.Name))
+ if (this.FilesInternal.Any(x => x.Filename == stream.Name))
throw new ArgumentException("A File with that filename already exists");
if (resetStreamPosition)
- this._files.Add(new(stream.Name, stream, stream.Position, description: description));
+ this.FilesInternal.Add(new(stream.Name, stream, stream.Position, description: description));
else
- this._files.Add(new(stream.Name, stream, null, description: description));
+ this.FilesInternal.Add(new(stream.Name, stream, null, description: description));
return this;
}
@@ -399,13 +361,13 @@ public DiscordInteractionResponseBuilder AddFiles(Dictionary fil
foreach (var file in files)
{
- if (this._files.Any(x => x.Filename == file.Key))
+ if (this.FilesInternal.Any(x => x.Filename == file.Key))
throw new ArgumentException("A File with that filename already exists");
if (resetStreamPosition)
- this._files.Add(new(file.Key, file.Value, file.Value.Position));
+ this.FilesInternal.Add(new(file.Key, file.Value, file.Value.Position));
else
- this._files.Add(new(file.Key, file.Value, null));
+ this.FilesInternal.Add(new(file.Key, file.Value, null));
}
return this;
@@ -446,7 +408,7 @@ public DiscordInteractionResponseBuilder AddMentions(IEnumerable menti
/// The current builder to chain calls with.
public DiscordInteractionResponseBuilder AddAutoCompleteChoice(DiscordApplicationCommandAutocompleteChoice choice)
{
- this._choices.Add(choice);
+ this.ChoicesInternal.Add(choice);
return this;
}
@@ -457,7 +419,7 @@ public DiscordInteractionResponseBuilder AddAutoCompleteChoice(DiscordApplicatio
/// The current builder to chain calls with.
public DiscordInteractionResponseBuilder AddAutoCompleteChoices(IEnumerable choices)
{
- this._choices.AddRange(choices);
+ this.ChoicesInternal.AddRange(choices);
return this;
}
@@ -469,34 +431,22 @@ public DiscordInteractionResponseBuilder AddAutoCompleteChoices(IEnumerable this.AddAutoCompleteChoices((IEnumerable)choices);
- ///
- /// Clears all message components on this builder.
- ///
- public void ClearComponents()
- => this.ComponentsInternal.Clear();
-
///
/// Clears the poll from this builder.
///
public void ClearPoll()
=> this.Poll = null;
- ///
- /// Allows for clearing the Interaction Response Builder so that it can be used again to send a new response.
- ///
- public void Clear()
+ ///
+ public override void Clear()
{
- this.Content = null!;
- this._embeds.Clear();
- this.IsTts = false;
this.IsEphemeral = false;
this.Mentions = null;
- this.ComponentsInternal.Clear();
- this._choices.Clear();
- this._files.Clear();
+ this.ChoicesInternal.Clear();
this.Poll = null;
this.IsVoiceMessage = false;
this.NotificationsSuppressed = false;
this.EmbedsSuppressed = false;
+ base.Clear();
}
}
diff --git a/DisCatSharp/Entities/Message/DiscordMessageBuilder.cs b/DisCatSharp/Entities/Message/DiscordMessageBuilder.cs
index df3a0d393a..d81cc14e14 100644
--- a/DisCatSharp/Entities/Message/DiscordMessageBuilder.cs
+++ b/DisCatSharp/Entities/Message/DiscordMessageBuilder.cs
@@ -13,57 +13,16 @@ namespace DisCatSharp.Entities;
///
public sealed class DiscordMessageBuilder : DisCatSharpBuilder
{
- private readonly List _embeds = [];
-
- internal readonly List AttachmentsInternal = [];
-
- internal readonly List FilesInternal = [];
-
- private string _content;
-
///
/// Whether to keep previous attachments.
///
internal bool? KeepAttachmentsInternal;
- ///
- /// Gets or Sets the Message to be sent.
- ///
- public string Content
- {
- get => this._content;
- set
- {
- if (value is { Length: > 2000 })
- throw new ArgumentException("Content cannot exceed 2000 characters.", nameof(value));
-
- this._content = value;
- }
- }
-
- ///
- /// Gets or sets the embed for the builder. This will always set the builder to have one embed.
- ///
- public DiscordEmbed Embed
- {
- get => this._embeds.Count > 0 ? this._embeds[0] : null;
- set
- {
- this._embeds.Clear();
- this._embeds.Add(value);
- }
- }
-
///
/// Gets the Sticker to be send.
///
public DiscordSticker Sticker { get; set; }
- ///
- /// Gets the Embeds to be sent.
- ///
- public IReadOnlyList Embeds => this._embeds;
-
///
/// Gets or Sets if the message should be TTS.
///
@@ -90,16 +49,6 @@ public DiscordEmbed Embed
///
public List? Mentions { get; private set; }
- ///
- /// Gets the Files to be sent in the Message.
- ///
- public IReadOnlyCollection Files => this.FilesInternal;
-
- ///
- /// Gets the Attachments to be sent in the Message.
- ///
- public IReadOnlyList Attachments => this.AttachmentsInternal;
-
///
/// Gets the Reply Message ID.
///
@@ -315,20 +264,6 @@ public DiscordMessageBuilder AsSilentMessage(bool silent = true)
return this;
}
- ///
- /// Sets the embed for the current builder.
- ///
- /// The embed that should be set.
- /// The current builder to be chained.
- public DiscordMessageBuilder WithEmbed(DiscordEmbed embed)
- {
- if (embed == null)
- return this;
-
- this.Embed = embed;
- return this;
- }
-
///
/// Appends an embed to the current builder.
///
@@ -339,7 +274,7 @@ public DiscordMessageBuilder AddEmbed(DiscordEmbed embed)
if (embed == null)
return this; //Providing null embeds will produce a 400 response from Discord.//
- this._embeds.Add(embed);
+ this.EmbedsInternal.Add(embed);
return this;
}
@@ -350,7 +285,7 @@ public DiscordMessageBuilder AddEmbed(DiscordEmbed embed)
/// The current builder to be chained.
public DiscordMessageBuilder AddEmbeds(IEnumerable embeds)
{
- this._embeds.AddRange(embeds);
+ this.EmbedsInternal.AddRange(embeds);
return this;
}
@@ -528,12 +463,6 @@ public Task SendAsync(DiscordChannel channel)
public Task ModifyAsync(DiscordMessage msg)
=> msg.ModifyAsync(this);
- ///
- /// Clears all message components on this builder.
- ///
- public void ClearComponents()
- => this.ComponentsInternal.Clear();
-
///
/// Clears the poll from this builder.
///
@@ -543,25 +472,21 @@ public void ClearPoll()
///
/// Allows for clearing the Message Builder so that it can be used again to send a new message.
///
- public void Clear()
+ public override void Clear()
{
- this.Content = "";
- this._embeds.Clear();
this.IsTts = false;
this.Mentions = null;
- this.FilesInternal.Clear();
this.ReplyId = null;
this.MentionOnReply = false;
- this.ComponentsInternal.Clear();
this.Suppressed = false;
this.Sticker = null!;
- this.AttachmentsInternal.Clear();
this.KeepAttachmentsInternal = false;
this.Nonce = null;
this.EnforceNonce = false;
this.Poll = null;
this.IsVoiceMessage = false;
this.IsUIKit = false;
+ base.Clear();
}
///
@@ -570,7 +495,7 @@ public void Clear()
/// Tells the method to perform the Modify Validation or Create Validation.
internal void Validate(bool isModify = false)
{
- if (this._embeds.Count > 10)
+ if (this.EmbedsInternal.Count > 10)
throw new ArgumentException("A message can only have up to 10 embeds.");
if (isModify)
@@ -599,5 +524,7 @@ internal void Validate(bool isModify = false)
}
else if (this.Poll is not null)
throw new InvalidOperationException("Messages with polls can't be edited.");
+
+ base.Validate();
}
}
diff --git a/DisCatSharp/Entities/Webhook/DiscordWebhookBuilder.cs b/DisCatSharp/Entities/Webhook/DiscordWebhookBuilder.cs
index 50ae089730..33b20a7f2a 100644
--- a/DisCatSharp/Entities/Webhook/DiscordWebhookBuilder.cs
+++ b/DisCatSharp/Entities/Webhook/DiscordWebhookBuilder.cs
@@ -16,14 +16,6 @@ public sealed class DiscordWebhookBuilder : DisCatSharpBuilder
{
private readonly List _appliedTags = [];
- private readonly List _embeds = [];
-
- private readonly List _files = [];
-
- private string _content;
-
- internal readonly List AttachmentsInternal = [];
-
///
/// Whether flags were changed.
///
@@ -71,47 +63,17 @@ public DiscordWebhookBuilder()
///
public bool IsVoiceMessage { get; private set; }
- ///
- /// Message to send on this webhook request.
- ///
- public string Content
- {
- get => this._content;
- set
- {
- if (value is { Length: > 2000 })
- throw new ArgumentException("Content length cannot exceed 2000 characters.", nameof(value));
-
- this._content = value;
- }
- }
-
///
/// Name of the new thread.
/// Only works if the webhook is send in a .
///
public string? ThreadName { get; set; }
- ///
- /// Embeds to send on this webhook request.
- ///
- public IReadOnlyList Embeds => this._embeds;
-
- ///
- /// Files to send on this webhook request.
- ///
- public IReadOnlyList Files => this._files;
-
///
/// Mentions to send on this webhook request.
///
public List? Mentions { get; private set; }
- ///
- /// Attachments to keep on this webhook request.
- ///
- public IReadOnlyList Attachments => this.AttachmentsInternal;
-
///
/// Forum post tags to send on this webhook request.
///
@@ -273,7 +235,7 @@ public DiscordWebhookBuilder WithThreadName(string name)
public DiscordWebhookBuilder AddEmbed(DiscordEmbed embed)
{
if (embed != null)
- this._embeds.Add(embed);
+ this.EmbedsInternal.Add(embed);
return this;
}
@@ -284,7 +246,7 @@ public DiscordWebhookBuilder AddEmbed(DiscordEmbed embed)
/// Embeds to add.
public DiscordWebhookBuilder AddEmbeds(IEnumerable embeds)
{
- this._embeds.AddRange(embeds);
+ this.EmbedsInternal.AddRange(embeds);
return this;
}
@@ -300,16 +262,16 @@ public DiscordWebhookBuilder AddEmbeds(IEnumerable embeds)
/// Description of the file.
public DiscordWebhookBuilder AddFile(string filename, Stream data, bool resetStreamPosition = false, string description = null)
{
- if (this.Files.Count > 10)
+ if (this.FilesInternal.Count > 10)
throw new ArgumentException("Cannot send more than 10 files with a single message.");
- if (this._files.Any(x => x.Filename == filename))
+ if (this.FilesInternal.Any(x => x.Filename == filename))
throw new ArgumentException("A File with that filename already exists");
if (resetStreamPosition)
- this._files.Add(new(filename, data, data.Position, description: description));
+ this.FilesInternal.Add(new(filename, data, data.Position, description: description));
else
- this._files.Add(new(filename, data, null, description: description));
+ this.FilesInternal.Add(new(filename, data, null, description: description));
return this;
}
@@ -329,13 +291,13 @@ public DiscordWebhookBuilder AddFile(FileStream stream, bool resetStreamPosition
if (this.Files.Count > 10)
throw new ArgumentException("Cannot send more than 10 files with a single message.");
- if (this._files.Any(x => x.Filename == stream.Name))
+ if (this.FilesInternal.Any(x => x.Filename == stream.Name))
throw new ArgumentException("A File with that filename already exists");
if (resetStreamPosition)
- this._files.Add(new(stream.Name, stream, stream.Position, description: description));
+ this.FilesInternal.Add(new(stream.Name, stream, stream.Position, description: description));
else
- this._files.Add(new(stream.Name, stream, null, description: description));
+ this.FilesInternal.Add(new(stream.Name, stream, null, description: description));
return this;
}
@@ -355,13 +317,13 @@ public DiscordWebhookBuilder AddFiles(Dictionary files, bool res
foreach (var file in files)
{
- if (this._files.Any(x => x.Filename == file.Key))
+ if (this.FilesInternal.Any(x => x.Filename == file.Key))
throw new ArgumentException("A File with that filename already exists");
if (resetStreamPosition)
- this._files.Add(new(file.Key, file.Value, file.Value.Position));
+ this.FilesInternal.Add(new(file.Key, file.Value, file.Value.Position));
else
- this._files.Add(new(file.Key, file.Value, null));
+ this.FilesInternal.Add(new(file.Key, file.Value, null));
}
return this;
@@ -429,7 +391,8 @@ public DiscordWebhookBuilder WithAppliedTags(IEnumerable tags)
///
/// The webhook that should be executed.
/// The message sent
- public async Task SendAsync(DiscordWebhook webhook) => await webhook.ExecuteAsync(this).ConfigureAwait(false);
+ public async Task SendAsync(DiscordWebhook webhook)
+ => await webhook.ExecuteAsync(this).ConfigureAwait(false);
///
/// Executes a webhook.
@@ -437,7 +400,8 @@ public DiscordWebhookBuilder WithAppliedTags(IEnumerable tags)
/// The webhook that should be executed.
/// Target thread id.
/// The message sent
- public async Task SendAsync(DiscordWebhook webhook, ulong threadId) => await webhook.ExecuteAsync(this, threadId.ToString()).ConfigureAwait(false);
+ public async Task SendAsync(DiscordWebhook webhook, ulong threadId)
+ => await webhook.ExecuteAsync(this, threadId.ToString()).ConfigureAwait(false);
///
/// Sends the modified webhook message.
@@ -445,7 +409,8 @@ public DiscordWebhookBuilder WithAppliedTags(IEnumerable tags)
/// The webhook that should be executed.
/// The message to modify.
/// The modified message
- public async Task ModifyAsync(DiscordWebhook webhook, DiscordMessage message) => await this.ModifyAsync(webhook, message.Id).ConfigureAwait(false);
+ public async Task ModifyAsync(DiscordWebhook webhook, DiscordMessage message)
+ => await this.ModifyAsync(webhook, message.Id).ConfigureAwait(false);
///
/// Sends the modified webhook message.
@@ -453,7 +418,8 @@ public DiscordWebhookBuilder WithAppliedTags(IEnumerable tags)
/// The webhook that should be executed.
/// The id of the message to modify.
/// The modified message
- public async Task ModifyAsync(DiscordWebhook webhook, ulong messageId) => await webhook.EditMessageAsync(messageId, this).ConfigureAwait(false);
+ public async Task ModifyAsync(DiscordWebhook webhook, ulong messageId)
+ => await webhook.EditMessageAsync(messageId, this).ConfigureAwait(false);
///
/// Sends the modified webhook message.
@@ -462,7 +428,8 @@ public DiscordWebhookBuilder WithAppliedTags(IEnumerable tags)
/// The message to modify.
/// Target thread.
/// The modified message
- public async Task ModifyAsync(DiscordWebhook webhook, DiscordMessage message, DiscordThreadChannel thread) => await this.ModifyAsync(webhook, message.Id, thread.Id).ConfigureAwait(false);
+ public async Task ModifyAsync(DiscordWebhook webhook, DiscordMessage message, DiscordThreadChannel thread)
+ => await this.ModifyAsync(webhook, message.Id, thread.Id).ConfigureAwait(false);
///
/// Sends the modified webhook message.
@@ -471,13 +438,8 @@ public DiscordWebhookBuilder WithAppliedTags(IEnumerable tags)
/// The id of the message to modify.
/// Target thread id.
/// The modified message
- public async Task ModifyAsync(DiscordWebhook webhook, ulong messageId, ulong threadId) => await webhook.EditMessageAsync(messageId, this, threadId.ToString()).ConfigureAwait(false);
-
- ///
- /// Clears all message components on this builder.
- ///
- public void ClearComponents()
- => this.ComponentsInternal.Clear();
+ public async Task ModifyAsync(DiscordWebhook webhook, ulong messageId, ulong threadId)
+ => await webhook.EditMessageAsync(messageId, this, threadId.ToString()).ConfigureAwait(false);
///
/// Clears the poll from this builder.
@@ -488,15 +450,10 @@ public void ClearPoll()
///
/// Allows for clearing the Webhook Builder so that it can be used again to send a new message.
///
- public void Clear()
+ public override void Clear()
{
- this.Content = "";
- this._embeds.Clear();
this.IsTts = false;
this.Mentions = null;
- this._files.Clear();
- this.AttachmentsInternal.Clear();
- this.ComponentsInternal.Clear();
this.KeepAttachmentsInternal = false;
this.ThreadName = null;
this.Poll = null;
@@ -504,6 +461,7 @@ public void Clear()
this.NotificationsSuppressed = false;
this.IsTts = false;
this.IsVoiceMessage = false;
+ base.Clear();
}
///
@@ -549,5 +507,7 @@ internal void Validate(bool isModify = false, bool isFollowup = false, bool isIn
throw new ArgumentException("You must specify content, an embed, a component, a poll, or at least one file.");
this.Poll?.Validate();
+
+ base.Validate();
}
}