| @@ -31,7 +31,8 @@ namespace Discord | |||||
| /// <param name="components">The message components to be included with this message. Used for interactions.</param> | /// <param name="components">The message components to be included with this message. Used for interactions.</param> | ||||
| /// <param name="stickers">A collection of stickers to send with the message.</param> | /// <param name="stickers">A collection of stickers to send with the message.</param> | ||||
| /// <param name="embeds">A array of <see cref="Embed"/>s to send with this response. Max 10.</param> | /// <param name="embeds">A array of <see cref="Embed"/>s to send with this response. Max 10.</param> | ||||
| /// <param name="flags">A message flag to be applied to the sent message, only <see cref="MessageFlags.SuppressEmbeds"/> is permitted.</param> | |||||
| /// <param name="flags">A message flag to be applied to the sent message, only <see cref="MessageFlags.SuppressEmbeds"/> | |||||
| /// and <see cref="MessageFlags.SuppressNotification"/> is permitted.</param> | |||||
| /// <returns> | /// <returns> | ||||
| /// A task that represents an asynchronous send operation for delivering the message. The task result | /// A task that represents an asynchronous send operation for delivering the message. The task result | ||||
| /// contains the sent message. | /// contains the sent message. | ||||
| @@ -72,7 +73,7 @@ namespace Discord | |||||
| /// <param name="components">The message components to be included with this message. Used for interactions.</param> | /// <param name="components">The message components to be included with this message. Used for interactions.</param> | ||||
| /// <param name="stickers">A collection of stickers to send with the file.</param> | /// <param name="stickers">A collection of stickers to send with the file.</param> | ||||
| /// <param name="embeds">A array of <see cref="Embed"/>s to send with this response. Max 10.</param> | /// <param name="embeds">A array of <see cref="Embed"/>s to send with this response. Max 10.</param> | ||||
| /// <param name="flags">A message flag to be applied to the sent message, only <see cref="MessageFlags.SuppressEmbeds"/> is permitted.</param> | |||||
| /// <param name="flags">A message flag to be applied to the sent message, only <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.SuppressNotification"/> is permitted.</param> | |||||
| /// <returns> | /// <returns> | ||||
| /// A task that represents an asynchronous send operation for delivering the message. The task result | /// A task that represents an asynchronous send operation for delivering the message. The task result | ||||
| /// contains the sent message. | /// contains the sent message. | ||||
| @@ -110,7 +111,7 @@ namespace Discord | |||||
| /// <param name="components">The message components to be included with this message. Used for interactions.</param> | /// <param name="components">The message components to be included with this message. Used for interactions.</param> | ||||
| /// <param name="stickers">A collection of stickers to send with the file.</param> | /// <param name="stickers">A collection of stickers to send with the file.</param> | ||||
| /// <param name="embeds">A array of <see cref="Embed"/>s to send with this response. Max 10.</param> | /// <param name="embeds">A array of <see cref="Embed"/>s to send with this response. Max 10.</param> | ||||
| /// <param name="flags">A message flag to be applied to the sent message, only <see cref="MessageFlags.SuppressEmbeds"/> is permitted.</param> | |||||
| /// <param name="flags">A message flag to be applied to the sent message, only <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.SuppressNotification"/> is permitted.</param> | |||||
| /// <returns> | /// <returns> | ||||
| /// A task that represents an asynchronous send operation for delivering the message. The task result | /// A task that represents an asynchronous send operation for delivering the message. The task result | ||||
| /// contains the sent message. | /// contains the sent message. | ||||
| @@ -140,7 +141,7 @@ namespace Discord | |||||
| /// <param name="components">The message components to be included with this message. Used for interactions.</param> | /// <param name="components">The message components to be included with this message. Used for interactions.</param> | ||||
| /// <param name="stickers">A collection of stickers to send with the file.</param> | /// <param name="stickers">A collection of stickers to send with the file.</param> | ||||
| /// <param name="embeds">A array of <see cref="Embed"/>s to send with this response. Max 10.</param> | /// <param name="embeds">A array of <see cref="Embed"/>s to send with this response. Max 10.</param> | ||||
| /// <param name="flags">A message flag to be applied to the sent message, only <see cref="MessageFlags.SuppressEmbeds"/> is permitted.</param> | |||||
| /// <param name="flags">A message flag to be applied to the sent message, only <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.SuppressNotification"/> is permitted.</param> | |||||
| /// <returns> | /// <returns> | ||||
| /// A task that represents an asynchronous send operation for delivering the message. The task result | /// A task that represents an asynchronous send operation for delivering the message. The task result | ||||
| /// contains the sent message. | /// contains the sent message. | ||||
| @@ -170,7 +171,7 @@ namespace Discord | |||||
| /// <param name="components">The message components to be included with this message. Used for interactions.</param> | /// <param name="components">The message components to be included with this message. Used for interactions.</param> | ||||
| /// <param name="stickers">A collection of stickers to send with the file.</param> | /// <param name="stickers">A collection of stickers to send with the file.</param> | ||||
| /// <param name="embeds">A array of <see cref="Embed"/>s to send with this response. Max 10.</param> | /// <param name="embeds">A array of <see cref="Embed"/>s to send with this response. Max 10.</param> | ||||
| /// <param name="flags">A message flag to be applied to the sent message, only <see cref="MessageFlags.SuppressEmbeds"/> is permitted.</param> | |||||
| /// <param name="flags">A message flag to be applied to the sent message, only <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.SuppressNotification"/> is permitted.</param> | |||||
| /// <returns> | /// <returns> | ||||
| /// A task that represents an asynchronous send operation for delivering the message. The task result | /// A task that represents an asynchronous send operation for delivering the message. The task result | ||||
| /// contains the sent message. | /// contains the sent message. | ||||
| @@ -6,7 +6,7 @@ namespace Discord.API.Rest | |||||
| internal class CreateMessageParams | internal class CreateMessageParams | ||||
| { | { | ||||
| [JsonProperty("content")] | [JsonProperty("content")] | ||||
| public string Content { get; } | |||||
| public Optional<string> Content { get; set; } | |||||
| [JsonProperty("nonce")] | [JsonProperty("nonce")] | ||||
| public Optional<string> Nonce { get; set; } | public Optional<string> Nonce { get; set; } | ||||
| @@ -31,10 +31,5 @@ namespace Discord.API.Rest | |||||
| [JsonProperty("flags")] | [JsonProperty("flags")] | ||||
| public Optional<MessageFlags> Flags { get; set; } | public Optional<MessageFlags> Flags { get; set; } | ||||
| public CreateMessageParams(string content) | |||||
| { | |||||
| Content = content; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -816,16 +816,24 @@ namespace Discord.API | |||||
| endpoint = () => $"channels/{channelId}/messages?limit={limit}"; | endpoint = () => $"channels/{channelId}/messages?limit={limit}"; | ||||
| return await SendAsync<IReadOnlyCollection<Message>>("GET", endpoint, ids, options: options).ConfigureAwait(false); | return await SendAsync<IReadOnlyCollection<Message>>("GET", endpoint, ids, options: options).ConfigureAwait(false); | ||||
| } | } | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| public async Task<Message> CreateMessageAsync(ulong channelId, CreateMessageParams args, RequestOptions options = null) | public async Task<Message> CreateMessageAsync(ulong channelId, CreateMessageParams args, RequestOptions options = null) | ||||
| { | { | ||||
| Preconditions.NotNull(args, nameof(args)); | Preconditions.NotNull(args, nameof(args)); | ||||
| Preconditions.NotEqual(channelId, 0, nameof(channelId)); | Preconditions.NotEqual(channelId, 0, nameof(channelId)); | ||||
| if ((!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) && (!args.Stickers.IsSpecified || args.Stickers.Value == null || args.Stickers.Value.Length == 0)) | |||||
| Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content)); | |||||
| if (args.Content?.Length > DiscordConfig.MaxMessageSize) | |||||
| if ((!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) | |||||
| && (!args.Stickers.IsSpecified || args.Stickers.Value == null || args.Stickers.Value.Length == 0) | |||||
| && (!args.Content.IsSpecified || args.Content.Value is null || string.IsNullOrWhiteSpace(args.Content.Value)) | |||||
| && (!args.Components.IsSpecified || args.Components.Value is null || args.Components.Value.Length == 0)) | |||||
| { | |||||
| throw new ArgumentException("At least one of 'Content', 'Embeds', 'Stickers' or 'Components' must be specified.", nameof(args)); | |||||
| } | |||||
| if (args.Content.IsSpecified && args.Content.Value is not null && args.Content.Value.Length > DiscordConfig.MaxMessageSize) | |||||
| throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); | throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); | ||||
| options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
| var ids = new BucketIds(channelId: channelId); | var ids = new BucketIds(channelId: channelId); | ||||
| @@ -842,10 +850,14 @@ namespace Discord.API | |||||
| Preconditions.NotNull(args, nameof(args)); | Preconditions.NotNull(args, nameof(args)); | ||||
| Preconditions.NotEqual(webhookId, 0, nameof(webhookId)); | Preconditions.NotEqual(webhookId, 0, nameof(webhookId)); | ||||
| if (!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) | |||||
| Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content)); | |||||
| if ((!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) | |||||
| && (!args.Content.IsSpecified || args.Content.Value is null || string.IsNullOrWhiteSpace(args.Content.Value)) | |||||
| && (!args.Components.IsSpecified || args.Components.Value is null || args.Components.Value.Length == 0)) | |||||
| { | |||||
| throw new ArgumentException("At least one of 'Content', 'Embeds' or 'Components' must be specified.", nameof(args)); | |||||
| } | |||||
| if (args.Content.IsSpecified && args.Content.Value?.Length > DiscordConfig.MaxMessageSize) | |||||
| if (args.Content.IsSpecified && args.Content.Value is not null && args.Content.Value.Length > DiscordConfig.MaxMessageSize) | |||||
| throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); | throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); | ||||
| options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
| @@ -875,6 +887,28 @@ namespace Discord.API | |||||
| await SendJsonAsync<Message>("PATCH", () => $"webhooks/{webhookId}/{AuthToken}/messages/{messageId}?{WebhookQuery(false, threadId)}", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); | await SendJsonAsync<Message>("PATCH", () => $"webhooks/{webhookId}/{AuthToken}/messages/{messageId}?{WebhookQuery(false, threadId)}", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); | ||||
| } | } | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | |||||
| /// <exception cref="InvalidOperationException">This operation may only be called with a <see cref="TokenType.Webhook"/> token.</exception> | |||||
| public async Task ModifyWebhookMessageAsync(ulong webhookId, ulong messageId, UploadWebhookFileParams args, RequestOptions options = null, ulong? threadId = null) | |||||
| { | |||||
| if (AuthTokenType != TokenType.Webhook) | |||||
| throw new InvalidOperationException($"This operation may only be called with a {nameof(TokenType.Webhook)} token."); | |||||
| Preconditions.NotNull(args, nameof(args)); | |||||
| Preconditions.NotEqual(webhookId, 0, nameof(webhookId)); | |||||
| Preconditions.NotEqual(messageId, 0, nameof(messageId)); | |||||
| if (args.Embeds.IsSpecified) | |||||
| Preconditions.AtMost(args.Embeds.Value.Length, 10, nameof(args.Embeds), "A max of 10 Embeds are allowed."); | |||||
| if (args.Content.IsSpecified && args.Content.Value.Length > DiscordConfig.MaxMessageSize) | |||||
| throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); | |||||
| options = RequestOptions.CreateOrClone(options); | |||||
| var ids = new BucketIds(webhookId: webhookId); | |||||
| await SendMultipartAsync<Message>("PATCH", () => $"webhooks/{webhookId}/{AuthToken}/messages/{messageId}?{WebhookQuery(false, threadId)}", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); | |||||
| } | |||||
| /// <exception cref="InvalidOperationException">This operation may only be called with a <see cref="TokenType.Webhook"/> token.</exception> | /// <exception cref="InvalidOperationException">This operation may only be called with a <see cref="TokenType.Webhook"/> token.</exception> | ||||
| public async Task DeleteWebhookMessageAsync(ulong webhookId, ulong messageId, RequestOptions options = null, ulong? threadId = null) | public async Task DeleteWebhookMessageAsync(ulong webhookId, ulong messageId, RequestOptions options = null, ulong? threadId = null) | ||||
| { | { | ||||
| @@ -897,10 +931,17 @@ namespace Discord.API | |||||
| Preconditions.NotEqual(channelId, 0, nameof(channelId)); | Preconditions.NotEqual(channelId, 0, nameof(channelId)); | ||||
| options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
| if (args.Content.GetValueOrDefault(null) == null) | |||||
| args.Content = ""; | |||||
| else if (args.Content.IsSpecified && args.Content.Value?.Length > DiscordConfig.MaxMessageSize) | |||||
| throw new ArgumentOutOfRangeException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content)); | |||||
| if ((!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) | |||||
| && (!args.Stickers.IsSpecified || args.Stickers.Value == null || args.Stickers.Value.Length == 0) | |||||
| && (!args.Content.IsSpecified || args.Content.Value is null || string.IsNullOrWhiteSpace(args.Content.Value)) | |||||
| && (!args.MessageComponent.IsSpecified || args.MessageComponent.Value is null || args.MessageComponent.Value.Length == 0) | |||||
| && (args.Files.Length == 0)) | |||||
| { | |||||
| throw new ArgumentException("At least one of 'Content', 'Embeds', 'Stickers', 'Attachments' or 'Components' must be specified.", nameof(args)); | |||||
| } | |||||
| if (args.Content.IsSpecified && args.Content.Value is not null && args.Content.Value.Length > DiscordConfig.MaxMessageSize) | |||||
| throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); | |||||
| var ids = new BucketIds(channelId: channelId); | var ids = new BucketIds(channelId: channelId); | ||||
| return await SendMultipartAsync<Message>("POST", () => $"channels/{channelId}/messages", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); | return await SendMultipartAsync<Message>("POST", () => $"channels/{channelId}/messages", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); | ||||
| @@ -917,19 +958,23 @@ namespace Discord.API | |||||
| Preconditions.NotEqual(webhookId, 0, nameof(webhookId)); | Preconditions.NotEqual(webhookId, 0, nameof(webhookId)); | ||||
| options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
| if (args.Content.GetValueOrDefault(null) == null) | |||||
| args.Content = ""; | |||||
| else if (args.Content.IsSpecified) | |||||
| if ((!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) | |||||
| && (!args.Content.IsSpecified || args.Content.Value is null || string.IsNullOrWhiteSpace(args.Content.Value)) | |||||
| && (!args.MessageComponents.IsSpecified || args.MessageComponents.Value is null || args.MessageComponents.Value.Length == 0) | |||||
| && (args.Files.Length == 0)) | |||||
| { | { | ||||
| if (args.Content.Value == null) | |||||
| args.Content = ""; | |||||
| if (args.Content.Value?.Length > DiscordConfig.MaxMessageSize) | |||||
| throw new ArgumentOutOfRangeException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content)); | |||||
| throw new ArgumentException("At least one of 'Content', 'Embeds', 'Stickers', 'Attachments' or 'Components' must be specified.", nameof(args)); | |||||
| } | } | ||||
| if (args.Content.IsSpecified && args.Content.Value is not null && args.Content.Value.Length > DiscordConfig.MaxMessageSize) | |||||
| throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); | |||||
| var ids = new BucketIds(webhookId: webhookId); | var ids = new BucketIds(webhookId: webhookId); | ||||
| return await SendMultipartAsync<Message>("POST", () => $"webhooks/{webhookId}/{AuthToken}?{WebhookQuery(true, threadId)}", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); | return await SendMultipartAsync<Message>("POST", () => $"webhooks/{webhookId}/{AuthToken}?{WebhookQuery(true, threadId)}", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); | ||||
| } | } | ||||
| public async Task DeleteMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) | public async Task DeleteMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) | ||||
| { | { | ||||
| Preconditions.NotEqual(channelId, 0, nameof(channelId)); | Preconditions.NotEqual(channelId, 0, nameof(channelId)); | ||||
| @@ -939,6 +984,7 @@ namespace Discord.API | |||||
| var ids = new BucketIds(channelId: channelId); | var ids = new BucketIds(channelId: channelId); | ||||
| await SendAsync("DELETE", () => $"channels/{channelId}/messages/{messageId}", ids, options: options).ConfigureAwait(false); | await SendAsync("DELETE", () => $"channels/{channelId}/messages/{messageId}", ids, options: options).ConfigureAwait(false); | ||||
| } | } | ||||
| public async Task DeleteMessagesAsync(ulong channelId, DeleteMessagesParams args, RequestOptions options = null) | public async Task DeleteMessagesAsync(ulong channelId, DeleteMessagesParams args, RequestOptions options = null) | ||||
| { | { | ||||
| Preconditions.NotEqual(channelId, 0, nameof(channelId)); | Preconditions.NotEqual(channelId, 0, nameof(channelId)); | ||||
| @@ -967,8 +1013,10 @@ namespace Discord.API | |||||
| Preconditions.NotEqual(channelId, 0, nameof(channelId)); | Preconditions.NotEqual(channelId, 0, nameof(channelId)); | ||||
| Preconditions.NotEqual(messageId, 0, nameof(messageId)); | Preconditions.NotEqual(messageId, 0, nameof(messageId)); | ||||
| Preconditions.NotNull(args, nameof(args)); | Preconditions.NotNull(args, nameof(args)); | ||||
| if (args.Content.IsSpecified && args.Content.Value?.Length > DiscordConfig.MaxMessageSize) | if (args.Content.IsSpecified && args.Content.Value?.Length > DiscordConfig.MaxMessageSize) | ||||
| throw new ArgumentOutOfRangeException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content)); | throw new ArgumentOutOfRangeException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content)); | ||||
| options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
| var ids = new BucketIds(channelId: channelId); | var ids = new BucketIds(channelId: channelId); | ||||
| @@ -980,8 +1028,10 @@ namespace Discord.API | |||||
| Preconditions.NotEqual(channelId, 0, nameof(channelId)); | Preconditions.NotEqual(channelId, 0, nameof(channelId)); | ||||
| Preconditions.NotEqual(messageId, 0, nameof(messageId)); | Preconditions.NotEqual(messageId, 0, nameof(messageId)); | ||||
| Preconditions.NotNull(args, nameof(args)); | Preconditions.NotNull(args, nameof(args)); | ||||
| if (args.Content.IsSpecified && args.Content.Value?.Length > DiscordConfig.MaxMessageSize) | if (args.Content.IsSpecified && args.Content.Value?.Length > DiscordConfig.MaxMessageSize) | ||||
| throw new ArgumentOutOfRangeException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content)); | throw new ArgumentOutOfRangeException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content)); | ||||
| options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
| var ids = new BucketIds(channelId: channelId); | var ids = new BucketIds(channelId: channelId); | ||||
| @@ -1444,8 +1494,15 @@ namespace Discord.API | |||||
| public async Task<Message> CreateInteractionFollowupMessageAsync(CreateWebhookMessageParams args, string token, RequestOptions options = null) | public async Task<Message> CreateInteractionFollowupMessageAsync(CreateWebhookMessageParams args, string token, RequestOptions options = null) | ||||
| { | { | ||||
| if ((!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) && !args.File.IsSpecified) | |||||
| Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content)); | |||||
| if ((!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) | |||||
| && (!args.Content.IsSpecified || args.Content.Value is null || string.IsNullOrWhiteSpace(args.Content.Value)) | |||||
| && (!args.Components.IsSpecified || args.Components.Value is null || args.Components.Value.Length == 0)) | |||||
| { | |||||
| throw new ArgumentException("At least one of 'Content', 'Embeds', 'File' or 'Components' must be specified.", nameof(args)); | |||||
| } | |||||
| if (args.Content.IsSpecified && args.Content.Value is not null && args.Content.Value.Length > DiscordConfig.MaxMessageSize) | |||||
| throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); | |||||
| if (args.Content.IsSpecified && args.Content.Value?.Length > DiscordConfig.MaxMessageSize) | if (args.Content.IsSpecified && args.Content.Value?.Length > DiscordConfig.MaxMessageSize) | ||||
| throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); | throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); | ||||
| @@ -1460,9 +1517,12 @@ namespace Discord.API | |||||
| public async Task<Message> CreateInteractionFollowupMessageAsync(UploadWebhookFileParams args, string token, RequestOptions options = null) | public async Task<Message> CreateInteractionFollowupMessageAsync(UploadWebhookFileParams args, string token, RequestOptions options = null) | ||||
| { | { | ||||
| if ((!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) && !args.Files.Any()) | |||||
| Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content)); | |||||
| if ((!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) | |||||
| && (!args.Content.IsSpecified || args.Content.Value is null || string.IsNullOrWhiteSpace(args.Content.Value)) | |||||
| && (!args.MessageComponents.IsSpecified || args.MessageComponents.Value is null || args.MessageComponents.Value.Length == 0)) | |||||
| { | |||||
| throw new ArgumentException("At least one of 'Content', 'Embeds', 'Files' or 'Components' must be specified.", nameof(args)); | |||||
| } | |||||
| if (args.Content.IsSpecified && args.Content.Value?.Length > DiscordConfig.MaxMessageSize) | if (args.Content.IsSpecified && args.Content.Value?.Length > DiscordConfig.MaxMessageSize) | ||||
| throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); | throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); | ||||
| @@ -301,12 +301,12 @@ namespace Discord.Rest | |||||
| Preconditions.AtMost(stickers.Length, 3, nameof(stickers), "A max of 3 stickers are allowed."); | Preconditions.AtMost(stickers.Length, 3, nameof(stickers), "A max of 3 stickers are allowed."); | ||||
| } | } | ||||
| if (flags is not MessageFlags.None and not MessageFlags.SuppressEmbeds) | |||||
| if (flags is not MessageFlags.None and not MessageFlags.SuppressEmbeds and not MessageFlags.SuppressNotification) | |||||
| throw new ArgumentException("The only valid MessageFlags are SuppressEmbeds and none.", nameof(flags)); | throw new ArgumentException("The only valid MessageFlags are SuppressEmbeds and none.", nameof(flags)); | ||||
| var args = new CreateMessageParams(text) | |||||
| var args = new CreateMessageParams | |||||
| { | { | ||||
| Content = text, | |||||
| IsTTS = isTTS, | IsTTS = isTTS, | ||||
| Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional<API.Embed[]>.Unspecified, | Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional<API.Embed[]>.Unspecified, | ||||
| AllowedMentions = allowedMentions?.ToModel(), | AllowedMentions = allowedMentions?.ToModel(), | ||||
| @@ -343,7 +343,7 @@ namespace Discord.Rest | |||||
| /// <exception cref="NotSupportedException"><paramref name="filePath" /> is in an invalid format.</exception> | /// <exception cref="NotSupportedException"><paramref name="filePath" /> is in an invalid format.</exception> | ||||
| /// <exception cref="IOException">An I/O error occurred while opening the file.</exception> | /// <exception cref="IOException">An I/O error occurred while opening the file.</exception> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/>, <see cref="MessageFlags.SuppressNotification"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public static async Task<RestUserMessage> SendFileAsync(IMessageChannel channel, BaseDiscordClient client, | public static async Task<RestUserMessage> SendFileAsync(IMessageChannel channel, BaseDiscordClient client, | ||||
| string filePath, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, | string filePath, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, | ||||
| MessageReference messageReference, MessageComponent components, ISticker[] stickers, RequestOptions options, | MessageReference messageReference, MessageComponent components, ISticker[] stickers, RequestOptions options, | ||||
| @@ -376,7 +376,7 @@ namespace Discord.Rest | |||||
| => SendFilesAsync(channel, client, new[] { attachment }, text, isTTS, embed, allowedMentions, messageReference, | => SendFilesAsync(channel, client, new[] { attachment }, text, isTTS, embed, allowedMentions, messageReference, | ||||
| components, stickers, options, embeds, flags); | components, stickers, options, embeds, flags); | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/>, <see cref="MessageFlags.SuppressNotification"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public static async Task<RestUserMessage> SendFilesAsync(IMessageChannel channel, BaseDiscordClient client, | public static async Task<RestUserMessage> SendFilesAsync(IMessageChannel channel, BaseDiscordClient client, | ||||
| IEnumerable<FileAttachment> attachments, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, | IEnumerable<FileAttachment> attachments, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, | ||||
| MessageReference messageReference, MessageComponent components, ISticker[] stickers, RequestOptions options, | MessageReference messageReference, MessageComponent components, ISticker[] stickers, RequestOptions options, | ||||
| @@ -127,7 +127,7 @@ namespace Discord.Rest | |||||
| /// <exception cref="IOException">An I/O error occurred while opening the file.</exception> | /// <exception cref="IOException">An I/O error occurred while opening the file.</exception> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | ||||
| public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, | |||||
| public Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, | |||||
| RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -135,7 +135,7 @@ namespace Discord.Rest | |||||
| components, stickers, options, isSpoiler, embeds, flags); | components, stickers, options, isSpoiler, embeds, flags); | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, | |||||
| public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -144,7 +144,7 @@ namespace Discord.Rest | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| public Task<RestUserMessage> SendFileAsync(FileAttachment attachment, string text, bool isTTS = false, | |||||
| public Task<RestUserMessage> SendFileAsync(FileAttachment attachment, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -153,7 +153,7 @@ namespace Discord.Rest | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| public Task<RestUserMessage> SendFilesAsync(IEnumerable<FileAttachment> attachments, string text, bool isTTS = false, | |||||
| public Task<RestUserMessage> SendFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -137,7 +137,7 @@ namespace Discord.Rest | |||||
| /// <exception cref="IOException">An I/O error occurred while opening the file.</exception> | /// <exception cref="IOException">An I/O error occurred while opening the file.</exception> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | ||||
| public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, | |||||
| public Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, | |||||
| RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -146,7 +146,7 @@ namespace Discord.Rest | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | ||||
| public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, | |||||
| public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -155,7 +155,7 @@ namespace Discord.Rest | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | ||||
| public Task<RestUserMessage> SendFileAsync(FileAttachment attachment, string text, bool isTTS = false, | |||||
| public Task<RestUserMessage> SendFileAsync(FileAttachment attachment, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -164,7 +164,7 @@ namespace Discord.Rest | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | ||||
| public Task<RestUserMessage> SendFilesAsync(IEnumerable<FileAttachment> attachments, string text, bool isTTS = false, | |||||
| public Task<RestUserMessage> SendFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -110,7 +110,7 @@ namespace Discord.Rest | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/>, <see cref="MessageFlags.SuppressNotification"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, | public virtual Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, | ||||
| RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, | RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, | ||||
| MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -142,8 +142,8 @@ namespace Discord.Rest | |||||
| /// <exception cref="NotSupportedException"><paramref name="filePath" /> is in an invalid format.</exception> | /// <exception cref="NotSupportedException"><paramref name="filePath" /> is in an invalid format.</exception> | ||||
| /// <exception cref="IOException">An I/O error occurred while opening the file.</exception> | /// <exception cref="IOException">An I/O error occurred while opening the file.</exception> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, | |||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/>, <see cref="MessageFlags.SuppressNotification"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, | |||||
| RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -152,8 +152,8 @@ namespace Discord.Rest | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, | |||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/>, <see cref="MessageFlags.SuppressNotification"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -162,8 +162,8 @@ namespace Discord.Rest | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendFileAsync(FileAttachment attachment, string text, bool isTTS = false, | |||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/>, <see cref="MessageFlags.SuppressNotification"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendFileAsync(FileAttachment attachment, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -172,8 +172,8 @@ namespace Discord.Rest | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendFilesAsync(IEnumerable<FileAttachment> attachments, string text, bool isTTS = false, | |||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/>, <see cref="MessageFlags.SuppressNotification"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -148,7 +148,7 @@ namespace Discord.WebSocket | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | ||||
| public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, | |||||
| public Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, | |||||
| RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -157,7 +157,7 @@ namespace Discord.WebSocket | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | ||||
| public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, | |||||
| public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -166,7 +166,7 @@ namespace Discord.WebSocket | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | ||||
| public Task<RestUserMessage> SendFileAsync(FileAttachment attachment, string text, bool isTTS = false, | |||||
| public Task<RestUserMessage> SendFileAsync(FileAttachment attachment, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -175,7 +175,7 @@ namespace Discord.WebSocket | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | ||||
| public Task<RestUserMessage> SendFilesAsync(IEnumerable<FileAttachment> attachments, string text, bool isTTS = false, | |||||
| public Task<RestUserMessage> SendFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -187,7 +187,7 @@ namespace Discord.WebSocket | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | ||||
| public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, | |||||
| public Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, | |||||
| RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -196,7 +196,7 @@ namespace Discord.WebSocket | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | ||||
| public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, | |||||
| public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -205,7 +205,7 @@ namespace Discord.WebSocket | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | ||||
| public Task<RestUserMessage> SendFileAsync(FileAttachment attachment, string text, bool isTTS = false, | |||||
| public Task<RestUserMessage> SendFileAsync(FileAttachment attachment, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -214,7 +214,7 @@ namespace Discord.WebSocket | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | ||||
| public Task<RestUserMessage> SendFilesAsync(IEnumerable<FileAttachment> attachments, string text, bool isTTS = false, | |||||
| public Task<RestUserMessage> SendFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -218,7 +218,7 @@ namespace Discord.WebSocket | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/>, <see cref="MessageFlags.SuppressNotification"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, | public virtual Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, | ||||
| RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, | RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, | ||||
| MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -226,8 +226,8 @@ namespace Discord.WebSocket | |||||
| components, stickers, options, embeds, flags); | components, stickers, options, embeds, flags); | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, | |||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/>, <see cref="MessageFlags.SuppressNotification"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, | |||||
| RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -235,8 +235,8 @@ namespace Discord.WebSocket | |||||
| components, stickers, options, isSpoiler, embeds, flags); | components, stickers, options, isSpoiler, embeds, flags); | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, | |||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/>, <see cref="MessageFlags.SuppressNotification"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -244,8 +244,8 @@ namespace Discord.WebSocket | |||||
| messageReference, components, stickers, options, isSpoiler, embeds, flags); | messageReference, components, stickers, options, isSpoiler, embeds, flags); | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendFileAsync(FileAttachment attachment, string text, bool isTTS = false, | |||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/>, <see cref="MessageFlags.SuppressNotification"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendFileAsync(FileAttachment attachment, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -253,8 +253,8 @@ namespace Discord.WebSocket | |||||
| messageReference, components, stickers, options, embeds, flags); | messageReference, components, stickers, options, embeds, flags); | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendFilesAsync(IEnumerable<FileAttachment> attachments, string text, bool isTTS = false, | |||||
| /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/>, <see cref="MessageFlags.SuppressNotification"/> and <see cref="MessageFlags.None"/>.</exception> | |||||
| public virtual Task<RestUserMessage> SendFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, bool isTTS = false, | |||||
| Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | ||||
| MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, | ||||
| Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | Embed[] embeds = null, MessageFlags flags = MessageFlags.None) | ||||
| @@ -1,5 +1,6 @@ | |||||
| using Discord.Logging; | using Discord.Logging; | ||||
| using Discord.Rest; | using Discord.Rest; | ||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Globalization; | using System.Globalization; | ||||
| @@ -7,195 +8,237 @@ using System.IO; | |||||
| using System.Text.RegularExpressions; | using System.Text.RegularExpressions; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| namespace Discord.Webhook | |||||
| namespace Discord.Webhook; | |||||
| /// <summary> | |||||
| /// A client responsible for connecting as a Webhook. | |||||
| /// </summary> | |||||
| public class DiscordWebhookClient : IDisposable | |||||
| { | { | ||||
| /// <summary> A client responsible for connecting as a Webhook. </summary> | |||||
| public class DiscordWebhookClient : IDisposable | |||||
| public event Func<LogMessage, Task> Log | |||||
| { | { | ||||
| public event Func<LogMessage, Task> Log { add { _logEvent.Add(value); } remove { _logEvent.Remove(value); } } | |||||
| internal readonly AsyncEvent<Func<LogMessage, Task>> _logEvent = new AsyncEvent<Func<LogMessage, Task>>(); | |||||
| private readonly ulong _webhookId; | |||||
| internal IWebhook Webhook; | |||||
| internal readonly Logger _restLogger; | |||||
| internal API.DiscordRestApiClient ApiClient { get; } | |||||
| internal LogManager LogManager { get; } | |||||
| /// <summary> Creates a new Webhook Discord client. </summary> | |||||
| public DiscordWebhookClient(IWebhook webhook) | |||||
| : this(webhook.Id, webhook.Token, new DiscordRestConfig()) { } | |||||
| /// <summary> Creates a new Webhook Discord client. </summary> | |||||
| public DiscordWebhookClient(ulong webhookId, string webhookToken) | |||||
| : this(webhookId, webhookToken, new DiscordRestConfig()) { } | |||||
| /// <summary> Creates a new Webhook Discord client. </summary> | |||||
| public DiscordWebhookClient(string webhookUrl) | |||||
| : this(webhookUrl, new DiscordRestConfig()) { } | |||||
| // regex pattern to match webhook urls | |||||
| private static Regex WebhookUrlRegex = new Regex(@"^.*(discord|discordapp)\.com\/api\/webhooks\/([\d]+)\/([a-z0-9_-]+)$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); | |||||
| /// <summary> Creates a new Webhook Discord client. </summary> | |||||
| public DiscordWebhookClient(ulong webhookId, string webhookToken, DiscordRestConfig config) | |||||
| : this(config) | |||||
| { | |||||
| _webhookId = webhookId; | |||||
| ApiClient.LoginAsync(TokenType.Webhook, webhookToken).GetAwaiter().GetResult(); | |||||
| Webhook = WebhookClientHelper.GetWebhookAsync(this, webhookId).GetAwaiter().GetResult(); | |||||
| } | |||||
| /// <summary> Creates a new Webhook Discord client. </summary> | |||||
| public DiscordWebhookClient(IWebhook webhook, DiscordRestConfig config) | |||||
| : this(config) | |||||
| { | |||||
| Webhook = webhook; | |||||
| _webhookId = Webhook.Id; | |||||
| } | |||||
| add => _logEvent.Add(value); | |||||
| remove => _logEvent.Remove(value); | |||||
| } | |||||
| /// <summary> | |||||
| /// Creates a new Webhook Discord client. | |||||
| /// </summary> | |||||
| /// <param name="webhookUrl">The url of the webhook.</param> | |||||
| /// <param name="config">The configuration options to use for this client.</param> | |||||
| /// <exception cref="ArgumentException">Thrown if the <paramref name="webhookUrl"/> is an invalid format.</exception> | |||||
| /// <exception cref="ArgumentNullException">Thrown if the <paramref name="webhookUrl"/> is null or whitespace.</exception> | |||||
| public DiscordWebhookClient(string webhookUrl, DiscordRestConfig config) : this(config) | |||||
| { | |||||
| ParseWebhookUrl(webhookUrl, out _webhookId, out string token); | |||||
| ApiClient.LoginAsync(TokenType.Webhook, token).GetAwaiter().GetResult(); | |||||
| Webhook = WebhookClientHelper.GetWebhookAsync(this, _webhookId).GetAwaiter().GetResult(); | |||||
| } | |||||
| internal readonly AsyncEvent<Func<LogMessage, Task>> _logEvent = new AsyncEvent<Func<LogMessage, Task>>(); | |||||
| private readonly ulong _webhookId; | |||||
| internal IWebhook Webhook; | |||||
| internal readonly Logger _restLogger; | |||||
| internal API.DiscordRestApiClient ApiClient { get; } | |||||
| internal LogManager LogManager { get; } | |||||
| /// <summary> | |||||
| /// Creates a new Webhook Discord client. | |||||
| /// </summary> | |||||
| public DiscordWebhookClient(IWebhook webhook) | |||||
| : this(webhook.Id, webhook.Token, new DiscordRestConfig()) { } | |||||
| /// <summary> | |||||
| /// Creates a new Webhook Discord client. | |||||
| /// </summary> | |||||
| public DiscordWebhookClient(ulong webhookId, string webhookToken) | |||||
| : this(webhookId, webhookToken, new DiscordRestConfig()) { } | |||||
| /// <summary> | |||||
| /// Creates a new Webhook Discord client. | |||||
| /// </summary> | |||||
| public DiscordWebhookClient(string webhookUrl) | |||||
| : this(webhookUrl, new DiscordRestConfig()) { } | |||||
| // regex pattern to match webhook urls | |||||
| private static Regex WebhookUrlRegex = new Regex(@"^.*(discord|discordapp)\.com\/api\/webhooks\/([\d]+)\/([a-z0-9_-]+)$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); | |||||
| /// <summary> | |||||
| /// Creates a new Webhook Discord client. | |||||
| /// </summary> | |||||
| public DiscordWebhookClient(ulong webhookId, string webhookToken, DiscordRestConfig config) | |||||
| : this(config) | |||||
| { | |||||
| _webhookId = webhookId; | |||||
| ApiClient.LoginAsync(TokenType.Webhook, webhookToken).GetAwaiter().GetResult(); | |||||
| Webhook = WebhookClientHelper.GetWebhookAsync(this, webhookId).GetAwaiter().GetResult(); | |||||
| } | |||||
| /// <summary> Creates a new Webhook Discord client. </summary> | |||||
| public DiscordWebhookClient(IWebhook webhook, DiscordRestConfig config) | |||||
| : this(config) | |||||
| { | |||||
| Webhook = webhook; | |||||
| _webhookId = Webhook.Id; | |||||
| } | |||||
| private DiscordWebhookClient(DiscordRestConfig config) | |||||
| { | |||||
| ApiClient = CreateApiClient(config); | |||||
| LogManager = new LogManager(config.LogLevel); | |||||
| LogManager.Message += async msg => await _logEvent.InvokeAsync(msg).ConfigureAwait(false); | |||||
| _restLogger = LogManager.CreateLogger("Rest"); | |||||
| ApiClient.RequestQueue.RateLimitTriggered += async (id, info, endpoint) => | |||||
| { | |||||
| if (info == null) | |||||
| await _restLogger.VerboseAsync($"Preemptive Rate limit triggered: {endpoint} {(id.IsHashBucket ? $"(Bucket: {id.BucketHash})" : "")}").ConfigureAwait(false); | |||||
| else | |||||
| await _restLogger.WarningAsync($"Rate limit triggered: {endpoint} {(id.IsHashBucket ? $"(Bucket: {id.BucketHash})" : "")}").ConfigureAwait(false); | |||||
| }; | |||||
| ApiClient.SentRequest += async (method, endpoint, millis) => await _restLogger.VerboseAsync($"{method} {endpoint}: {millis} ms").ConfigureAwait(false); | |||||
| } | |||||
| private static API.DiscordRestApiClient CreateApiClient(DiscordRestConfig config) | |||||
| => new API.DiscordRestApiClient(config.RestClientProvider, DiscordRestConfig.UserAgent, useSystemClock: config.UseSystemClock, defaultRatelimitCallback: config.DefaultRatelimitCallback); | |||||
| /// <summary> Sends a message to the channel for this webhook. </summary> | |||||
| /// <returns> Returns the ID of the created message. </returns> | |||||
| public Task<ulong> SendMessageAsync(string text = null, bool isTTS = false, IEnumerable<Embed> embeds = null, | |||||
| string username = null, string avatarUrl = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | |||||
| MessageComponent components = null, MessageFlags flags = MessageFlags.None, ulong? threadId = null) | |||||
| => WebhookClientHelper.SendMessageAsync(this, text, isTTS, embeds, username, avatarUrl, allowedMentions, options, components, flags, threadId); | |||||
| /// <summary> | |||||
| /// Modifies a message posted using this webhook. | |||||
| /// </summary> | |||||
| /// <remarks> | |||||
| /// This method can only modify messages that were sent using the same webhook. | |||||
| /// </remarks> | |||||
| /// <param name="messageId">ID of the modified message.</param> | |||||
| /// <param name="func">A delegate containing the properties to modify the message with.</param> | |||||
| /// <param name="options">The options to be used when sending the request.</param> | |||||
| /// <returns> | |||||
| /// A task that represents the asynchronous modification operation. | |||||
| /// </returns> | |||||
| public Task ModifyMessageAsync(ulong messageId, Action<WebhookMessageProperties> func, RequestOptions options = null, ulong? threadId = null) | |||||
| => WebhookClientHelper.ModifyMessageAsync(this, messageId, func, options, threadId); | |||||
| /// <summary> | |||||
| /// Deletes a message posted using this webhook. | |||||
| /// </summary> | |||||
| /// <remarks> | |||||
| /// This method can only delete messages that were sent using the same webhook. | |||||
| /// </remarks> | |||||
| /// <param name="messageId">ID of the deleted message.</param> | |||||
| /// <param name="options">The options to be used when sending the request.</param> | |||||
| /// <returns> | |||||
| /// A task that represents the asynchronous deletion operation. | |||||
| /// </returns> | |||||
| public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null, ulong? threadId = null) | |||||
| => WebhookClientHelper.DeleteMessageAsync(this, messageId, options, threadId); | |||||
| /// <summary> Sends a message to the channel for this webhook with an attachment. </summary> | |||||
| /// <returns> Returns the ID of the created message. </returns> | |||||
| public Task<ulong> SendFileAsync(string filePath, string text, bool isTTS = false, | |||||
| IEnumerable<Embed> embeds = null, string username = null, string avatarUrl = null, | |||||
| RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | |||||
| MessageComponent components = null, MessageFlags flags = MessageFlags.None, ulong? threadId = null) | |||||
| => WebhookClientHelper.SendFileAsync(this, filePath, text, isTTS, embeds, username, avatarUrl, | |||||
| allowedMentions, options, isSpoiler, components, flags, threadId); | |||||
| /// <summary> Sends a message to the channel for this webhook with an attachment. </summary> | |||||
| /// <returns> Returns the ID of the created message. </returns> | |||||
| public Task<ulong> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, | |||||
| IEnumerable<Embed> embeds = null, string username = null, string avatarUrl = null, | |||||
| RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | |||||
| MessageComponent components = null, MessageFlags flags = MessageFlags.None, ulong? threadId = null) | |||||
| => WebhookClientHelper.SendFileAsync(this, stream, filename, text, isTTS, embeds, username, | |||||
| avatarUrl, allowedMentions, options, isSpoiler, components, flags, threadId); | |||||
| /// <summary> Sends a message to the channel for this webhook with an attachment. </summary> | |||||
| /// <returns> Returns the ID of the created message. </returns> | |||||
| public Task<ulong> SendFileAsync(FileAttachment attachment, string text, bool isTTS = false, | |||||
| IEnumerable<Embed> embeds = null, string username = null, string avatarUrl = null, | |||||
| RequestOptions options = null, AllowedMentions allowedMentions = null, MessageComponent components = null, | |||||
| MessageFlags flags = MessageFlags.None, ulong? threadId = null) | |||||
| => WebhookClientHelper.SendFileAsync(this, attachment, text, isTTS, embeds, username, | |||||
| avatarUrl, allowedMentions, components, options, flags, threadId); | |||||
| /// <summary> Sends a message to the channel for this webhook with an attachment. </summary> | |||||
| /// <returns> Returns the ID of the created message. </returns> | |||||
| public Task<ulong> SendFilesAsync(IEnumerable<FileAttachment> attachments, string text, bool isTTS = false, | |||||
| IEnumerable<Embed> embeds = null, string username = null, string avatarUrl = null, | |||||
| RequestOptions options = null, AllowedMentions allowedMentions = null, MessageComponent components = null, | |||||
| MessageFlags flags = MessageFlags.None, ulong? threadId = null) | |||||
| => WebhookClientHelper.SendFilesAsync(this, attachments, text, isTTS, embeds, username, avatarUrl, | |||||
| allowedMentions, components, options, flags, threadId); | |||||
| /// <summary> Modifies the properties of this webhook. </summary> | |||||
| public Task ModifyWebhookAsync(Action<WebhookProperties> func, RequestOptions options = null) | |||||
| => Webhook.ModifyAsync(func, options); | |||||
| /// <summary> Deletes this webhook from Discord and disposes the client. </summary> | |||||
| public async Task DeleteWebhookAsync(RequestOptions options = null) | |||||
| { | |||||
| await Webhook.DeleteAsync(options).ConfigureAwait(false); | |||||
| Dispose(); | |||||
| } | |||||
| /// <summary> | |||||
| /// Creates a new Webhook Discord client. | |||||
| /// </summary> | |||||
| /// <param name="webhookUrl">The url of the webhook.</param> | |||||
| /// <param name="config">The configuration options to use for this client.</param> | |||||
| /// <exception cref="ArgumentException">Thrown if the <paramref name="webhookUrl"/> is an invalid format.</exception> | |||||
| /// <exception cref="ArgumentNullException">Thrown if the <paramref name="webhookUrl"/> is null or whitespace.</exception> | |||||
| public DiscordWebhookClient(string webhookUrl, DiscordRestConfig config) : this(config) | |||||
| { | |||||
| ParseWebhookUrl(webhookUrl, out _webhookId, out string token); | |||||
| ApiClient.LoginAsync(TokenType.Webhook, token).GetAwaiter().GetResult(); | |||||
| Webhook = WebhookClientHelper.GetWebhookAsync(this, _webhookId).GetAwaiter().GetResult(); | |||||
| } | |||||
| public void Dispose() | |||||
| { | |||||
| ApiClient?.Dispose(); | |||||
| } | |||||
| private DiscordWebhookClient(DiscordRestConfig config) | |||||
| { | |||||
| ApiClient = CreateApiClient(config); | |||||
| LogManager = new LogManager(config.LogLevel); | |||||
| LogManager.Message += async msg => await _logEvent.InvokeAsync(msg).ConfigureAwait(false); | |||||
| _restLogger = LogManager.CreateLogger("Rest"); | |||||
| internal static void ParseWebhookUrl(string webhookUrl, out ulong webhookId, out string webhookToken) | |||||
| ApiClient.RequestQueue.RateLimitTriggered += async (id, info, endpoint) => | |||||
| { | { | ||||
| if (string.IsNullOrWhiteSpace(webhookUrl)) | |||||
| throw new ArgumentNullException(paramName: nameof(webhookUrl), message: | |||||
| "The given webhook Url cannot be null or whitespace."); | |||||
| // thrown when groups are not populated/valid, or when there is no match | |||||
| ArgumentException ex(string reason = null) | |||||
| => new ArgumentException(paramName: nameof(webhookUrl), message: | |||||
| $"The given webhook Url was not in a valid format. {reason}"); | |||||
| var match = WebhookUrlRegex.Match(webhookUrl); | |||||
| if (match != null) | |||||
| { | |||||
| // ensure that the first group is a ulong, set the _webhookId | |||||
| // 0th group is always the entire match, and 1 is the domain; so start at index 2 | |||||
| if (!(match.Groups[2].Success && ulong.TryParse(match.Groups[2].Value, NumberStyles.None, CultureInfo.InvariantCulture, out webhookId))) | |||||
| throw ex("The webhook Id could not be parsed."); | |||||
| if (!match.Groups[3].Success) | |||||
| throw ex("The webhook token could not be parsed."); | |||||
| webhookToken = match.Groups[3].Value; | |||||
| } | |||||
| if (info == null) | |||||
| await _restLogger.VerboseAsync($"Preemptive Rate limit triggered: {endpoint} {(id.IsHashBucket ? $"(Bucket: {id.BucketHash})" : "")}").ConfigureAwait(false); | |||||
| else | else | ||||
| throw ex(); | |||||
| await _restLogger.WarningAsync($"Rate limit triggered: {endpoint} {(id.IsHashBucket ? $"(Bucket: {id.BucketHash})" : "")}").ConfigureAwait(false); | |||||
| }; | |||||
| ApiClient.SentRequest += async (method, endpoint, millis) => await _restLogger.VerboseAsync($"{method} {endpoint}: {millis} ms").ConfigureAwait(false); | |||||
| } | |||||
| private static API.DiscordRestApiClient CreateApiClient(DiscordRestConfig config) | |||||
| => new (config.RestClientProvider, DiscordConfig.UserAgent, useSystemClock: config.UseSystemClock, defaultRatelimitCallback: config.DefaultRatelimitCallback); | |||||
| /// <summary> | |||||
| /// Sends a message to the channel for this webhook. | |||||
| /// </summary> | |||||
| /// <returns> | |||||
| /// Returns the ID of the created message. | |||||
| /// </returns> | |||||
| public Task<ulong> SendMessageAsync(string text = null, bool isTTS = false, IEnumerable<Embed> embeds = null, | |||||
| string username = null, string avatarUrl = null, RequestOptions options = null, AllowedMentions allowedMentions = null, | |||||
| MessageComponent components = null, MessageFlags flags = MessageFlags.None, ulong? threadId = null) | |||||
| => WebhookClientHelper.SendMessageAsync(this, text, isTTS, embeds, username, avatarUrl, allowedMentions, options, components, flags, threadId); | |||||
| /// <summary> | |||||
| /// Modifies a message posted using this webhook. | |||||
| /// </summary> | |||||
| /// <remarks> | |||||
| /// This method can only modify messages that were sent using the same webhook. | |||||
| /// </remarks> | |||||
| /// <param name="messageId">ID of the modified message.</param> | |||||
| /// <param name="func">A delegate containing the properties to modify the message with.</param> | |||||
| /// <param name="options">The options to be used when sending the request.</param> | |||||
| /// <returns> | |||||
| /// A task that represents the asynchronous modification operation. | |||||
| /// </returns> | |||||
| public Task ModifyMessageAsync(ulong messageId, Action<WebhookMessageProperties> func, RequestOptions options = null, ulong? threadId = null) | |||||
| => WebhookClientHelper.ModifyMessageAsync(this, messageId, func, options, threadId); | |||||
| /// <summary> | |||||
| /// Deletes a message posted using this webhook. | |||||
| /// </summary> | |||||
| /// <remarks> | |||||
| /// This method can only delete messages that were sent using the same webhook. | |||||
| /// </remarks> | |||||
| /// <param name="messageId">ID of the deleted message.</param> | |||||
| /// <param name="options">The options to be used when sending the request.</param> | |||||
| /// <returns> | |||||
| /// A task that represents the asynchronous deletion operation. | |||||
| /// </returns> | |||||
| public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null, ulong? threadId = null) | |||||
| => WebhookClientHelper.DeleteMessageAsync(this, messageId, options, threadId); | |||||
| /// <summary> | |||||
| /// Sends a message to the channel for this webhook with an attachment. | |||||
| /// </summary> | |||||
| /// <returns> | |||||
| /// Returns the ID of the created message. | |||||
| /// </returns> | |||||
| public Task<ulong> SendFileAsync(string filePath, string text, bool isTTS = false, | |||||
| IEnumerable<Embed> embeds = null, string username = null, string avatarUrl = null, | |||||
| RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | |||||
| MessageComponent components = null, MessageFlags flags = MessageFlags.None, ulong? threadId = null) | |||||
| => WebhookClientHelper.SendFileAsync(this, filePath, text, isTTS, embeds, username, avatarUrl, | |||||
| allowedMentions, options, isSpoiler, components, flags, threadId); | |||||
| /// <summary> | |||||
| /// Sends a message to the channel for this webhook with an attachment. | |||||
| /// </summary> | |||||
| /// <returns> | |||||
| /// Returns the ID of the created message. | |||||
| /// </returns> | |||||
| public Task<ulong> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, | |||||
| IEnumerable<Embed> embeds = null, string username = null, string avatarUrl = null, | |||||
| RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, | |||||
| MessageComponent components = null, MessageFlags flags = MessageFlags.None, ulong? threadId = null) | |||||
| => WebhookClientHelper.SendFileAsync(this, stream, filename, text, isTTS, embeds, username, | |||||
| avatarUrl, allowedMentions, options, isSpoiler, components, flags, threadId); | |||||
| /// <summary> | |||||
| /// Sends a message to the channel for this webhook with an attachment. | |||||
| /// </summary> | |||||
| /// <returns> | |||||
| /// Returns the ID of the created message. | |||||
| /// </returns> | |||||
| public Task<ulong> SendFileAsync(FileAttachment attachment, string text, bool isTTS = false, | |||||
| IEnumerable<Embed> embeds = null, string username = null, string avatarUrl = null, | |||||
| RequestOptions options = null, AllowedMentions allowedMentions = null, MessageComponent components = null, | |||||
| MessageFlags flags = MessageFlags.None, ulong? threadId = null) | |||||
| => WebhookClientHelper.SendFileAsync(this, attachment, text, isTTS, embeds, username, | |||||
| avatarUrl, allowedMentions, components, options, flags, threadId); | |||||
| /// <summary> | |||||
| /// Sends a message to the channel for this webhook with an attachment. | |||||
| /// </summary> | |||||
| /// <returns> | |||||
| /// Returns the ID of the created message. | |||||
| /// </returns> | |||||
| public Task<ulong> SendFilesAsync(IEnumerable<FileAttachment> attachments, string text, bool isTTS = false, | |||||
| IEnumerable<Embed> embeds = null, string username = null, string avatarUrl = null, | |||||
| RequestOptions options = null, AllowedMentions allowedMentions = null, MessageComponent components = null, | |||||
| MessageFlags flags = MessageFlags.None, ulong? threadId = null) | |||||
| => WebhookClientHelper.SendFilesAsync(this, attachments, text, isTTS, embeds, username, avatarUrl, | |||||
| allowedMentions, components, options, flags, threadId); | |||||
| /// <summary> | |||||
| /// Modifies the properties of this webhook. | |||||
| /// </summary> | |||||
| public Task ModifyWebhookAsync(Action<WebhookProperties> func, RequestOptions options = null) | |||||
| => Webhook.ModifyAsync(func, options); | |||||
| /// <summary> | |||||
| /// Deletes this webhook from Discord and disposes the client. | |||||
| /// </summary> | |||||
| public async Task DeleteWebhookAsync(RequestOptions options = null) | |||||
| { | |||||
| await Webhook.DeleteAsync(options).ConfigureAwait(false); | |||||
| Dispose(); | |||||
| } | |||||
| public void Dispose() | |||||
| { | |||||
| ApiClient?.Dispose(); | |||||
| } | |||||
| internal static void ParseWebhookUrl(string webhookUrl, out ulong webhookId, out string webhookToken) | |||||
| { | |||||
| if (string.IsNullOrWhiteSpace(webhookUrl)) | |||||
| throw new ArgumentNullException(nameof(webhookUrl), "The given webhook Url cannot be null or whitespace."); | |||||
| // thrown when groups are not populated/valid, or when there is no match | |||||
| ArgumentException ex(string reason = null) | |||||
| => new ($"The given webhook Url was not in a valid format. {reason}", nameof(webhookUrl)); | |||||
| var match = WebhookUrlRegex.Match(webhookUrl); | |||||
| if (match != null) | |||||
| { | |||||
| // ensure that the first group is a ulong, set the _webhookId | |||||
| // 0th group is always the entire match, and 1 is the domain; so start at index 2 | |||||
| if (!(match.Groups[2].Success && ulong.TryParse(match.Groups[2].Value, NumberStyles.None, CultureInfo.InvariantCulture, out webhookId))) | |||||
| throw ex("The webhook Id could not be parsed."); | |||||
| if (!match.Groups[3].Success) | |||||
| throw ex("The webhook token could not be parsed."); | |||||
| webhookToken = match.Groups[3].Value; | |||||
| } | } | ||||
| else | |||||
| throw ex(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -26,5 +26,9 @@ namespace Discord.Webhook | |||||
| /// Gets or sets the components that the message should display. | /// Gets or sets the components that the message should display. | ||||
| /// </summary> | /// </summary> | ||||
| public Optional<MessageComponent> Components { get; set; } | public Optional<MessageComponent> Components { get; set; } | ||||
| /// <summary> | |||||
| /// Gets or sets the attachments for the message. | |||||
| /// </summary> | |||||
| public Optional<IEnumerable<FileAttachment>> Attachments { get; set; } | |||||
| } | } | ||||
| } | } | ||||
| @@ -20,6 +20,7 @@ namespace Discord.Webhook | |||||
| throw new InvalidOperationException("Could not find a webhook with the supplied credentials."); | throw new InvalidOperationException("Could not find a webhook with the supplied credentials."); | ||||
| return RestInternalWebhook.Create(client, model); | return RestInternalWebhook.Create(client, model); | ||||
| } | } | ||||
| public static async Task<ulong> SendMessageAsync(DiscordWebhookClient client, | public static async Task<ulong> SendMessageAsync(DiscordWebhookClient client, | ||||
| string text, bool isTTS, IEnumerable<Embed> embeds, string username, string avatarUrl, | string text, bool isTTS, IEnumerable<Embed> embeds, string username, string avatarUrl, | ||||
| AllowedMentions allowedMentions, RequestOptions options, MessageComponent components, MessageFlags flags, ulong? threadId = null) | AllowedMentions allowedMentions, RequestOptions options, MessageComponent components, MessageFlags flags, ulong? threadId = null) | ||||
| @@ -82,26 +83,49 @@ namespace Discord.Webhook | |||||
| } | } | ||||
| } | } | ||||
| var apiArgs = new ModifyWebhookMessageParams | |||||
| if (!args.Attachments.IsSpecified) | |||||
| { | { | ||||
| Content = args.Content.IsSpecified ? args.Content.Value : Optional.Create<string>(), | |||||
| Embeds = | |||||
| args.Embeds.IsSpecified | |||||
| ? args.Embeds.Value.Select(embed => embed.ToModel()).ToArray() | |||||
| : Optional.Create<API.Embed[]>(), | |||||
| AllowedMentions = args.AllowedMentions.IsSpecified | |||||
| ? args.AllowedMentions.Value.ToModel() | |||||
| : Optional.Create<API.AllowedMentions>(), | |||||
| Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified, | |||||
| }; | |||||
| await client.ApiClient.ModifyWebhookMessageAsync(client.Webhook.Id, messageId, apiArgs, options, threadId) | |||||
| .ConfigureAwait(false); | |||||
| var apiArgs = new ModifyWebhookMessageParams | |||||
| { | |||||
| Content = args.Content.IsSpecified ? args.Content.Value : Optional.Create<string>(), | |||||
| Embeds = | |||||
| args.Embeds.IsSpecified | |||||
| ? args.Embeds.Value.Select(embed => embed.ToModel()).ToArray() | |||||
| : Optional.Create<API.Embed[]>(), | |||||
| AllowedMentions = args.AllowedMentions.IsSpecified | |||||
| ? args.AllowedMentions.Value.ToModel() | |||||
| : Optional.Create<API.AllowedMentions>(), | |||||
| Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified, | |||||
| }; | |||||
| await client.ApiClient.ModifyWebhookMessageAsync(client.Webhook.Id, messageId, apiArgs, options, threadId) | |||||
| .ConfigureAwait(false); | |||||
| } | |||||
| else | |||||
| { | |||||
| var apiArgs = new UploadWebhookFileParams(args.Attachments.Value.ToArray()) | |||||
| { | |||||
| Content = args.Content.IsSpecified ? args.Content.Value : Optional.Create<string>(), | |||||
| Embeds = | |||||
| args.Embeds.IsSpecified | |||||
| ? args.Embeds.Value.Select(embed => embed.ToModel()).ToArray() | |||||
| : Optional.Create<API.Embed[]>(), | |||||
| AllowedMentions = args.AllowedMentions.IsSpecified | |||||
| ? args.AllowedMentions.Value.ToModel() | |||||
| : Optional.Create<API.AllowedMentions>(), | |||||
| MessageComponents = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified, | |||||
| }; | |||||
| await client.ApiClient.ModifyWebhookMessageAsync(client.Webhook.Id, messageId, apiArgs, options, threadId) | |||||
| .ConfigureAwait(false); | |||||
| } | |||||
| } | } | ||||
| public static async Task DeleteMessageAsync(DiscordWebhookClient client, ulong messageId, RequestOptions options, ulong? threadId) | public static async Task DeleteMessageAsync(DiscordWebhookClient client, ulong messageId, RequestOptions options, ulong? threadId) | ||||
| { | { | ||||
| await client.ApiClient.DeleteWebhookMessageAsync(client.Webhook.Id, messageId, options, threadId).ConfigureAwait(false); | await client.ApiClient.DeleteWebhookMessageAsync(client.Webhook.Id, messageId, options, threadId).ConfigureAwait(false); | ||||
| } | } | ||||
| public static async Task<ulong> SendFileAsync(DiscordWebhookClient client, string filePath, string text, bool isTTS, | public static async Task<ulong> SendFileAsync(DiscordWebhookClient client, string filePath, string text, bool isTTS, | ||||
| IEnumerable<Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options, | IEnumerable<Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options, | ||||
| bool isSpoiler, MessageComponent components, MessageFlags flags = MessageFlags.None, ulong? threadId = null) | bool isSpoiler, MessageComponent components, MessageFlags flags = MessageFlags.None, ulong? threadId = null) | ||||
| @@ -110,6 +134,7 @@ namespace Discord.Webhook | |||||
| using (var file = File.OpenRead(filePath)) | using (var file = File.OpenRead(filePath)) | ||||
| return await SendFileAsync(client, file, filename, text, isTTS, embeds, username, avatarUrl, allowedMentions, options, isSpoiler, components, flags, threadId).ConfigureAwait(false); | return await SendFileAsync(client, file, filename, text, isTTS, embeds, username, avatarUrl, allowedMentions, options, isSpoiler, components, flags, threadId).ConfigureAwait(false); | ||||
| } | } | ||||
| public static Task<ulong> SendFileAsync(DiscordWebhookClient client, Stream stream, string filename, string text, bool isTTS, | public static Task<ulong> SendFileAsync(DiscordWebhookClient client, Stream stream, string filename, string text, bool isTTS, | ||||
| IEnumerable<Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options, bool isSpoiler, | IEnumerable<Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options, bool isSpoiler, | ||||
| MessageComponent components, MessageFlags flags, ulong? threadId) | MessageComponent components, MessageFlags flags, ulong? threadId) | ||||
| @@ -152,8 +177,8 @@ namespace Discord.Webhook | |||||
| } | } | ||||
| } | } | ||||
| if (flags is not MessageFlags.None and not MessageFlags.SuppressEmbeds) | |||||
| throw new ArgumentException("The only valid MessageFlags are SuppressEmbeds and none.", nameof(flags)); | |||||
| if (flags is not MessageFlags.None and not MessageFlags.SuppressEmbeds and not MessageFlags.SuppressNotification) | |||||
| throw new ArgumentException("The only valid MessageFlags are SuppressEmbeds, SuppressNotification and none.", nameof(flags)); | |||||
| var args = new UploadWebhookFileParams(attachments.ToArray()) | var args = new UploadWebhookFileParams(attachments.ToArray()) | ||||
| { | { | ||||
| @@ -170,8 +195,7 @@ namespace Discord.Webhook | |||||
| return msg.Id; | return msg.Id; | ||||
| } | } | ||||
| public static async Task<WebhookModel> ModifyAsync(DiscordWebhookClient client, | |||||
| Action<WebhookProperties> func, RequestOptions options) | |||||
| public static async Task<WebhookModel> ModifyAsync(DiscordWebhookClient client, Action<WebhookProperties> func, RequestOptions options) | |||||
| { | { | ||||
| var args = new WebhookProperties(); | var args = new WebhookProperties(); | ||||
| func(args); | func(args); | ||||