@@ -4,19 +4,13 @@ using Newtonsoft.Json; | |||
namespace Discord.API.Rest | |||
{ | |||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
internal class EditWebhookMessageParams | |||
internal class ModifyWebhookMessageParams | |||
{ | |||
[JsonProperty("content")] | |||
public string Content { get; } | |||
public string Content { get; set; } | |||
[JsonProperty("embeds")] | |||
public Optional<Embed[]> Embeds { get; set; } | |||
[JsonProperty("allowed_mentions")] | |||
public Optional<AllowedMentions> AllowedMentions { get; set; } | |||
public EditWebhookMessageParams(string content) | |||
{ | |||
Content = content; | |||
} | |||
} | |||
} |
@@ -526,7 +526,7 @@ namespace Discord.API | |||
/// <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 EditWebhookMessageAsync(ulong webhookId, ulong messageId, EditWebhookMessageParams args, RequestOptions options = null) | |||
public async Task ModifyWebhookMessageAsync(ulong webhookId, ulong messageId, ModifyWebhookMessageParams args, RequestOptions options = null) | |||
{ | |||
if (AuthTokenType != TokenType.Webhook) | |||
throw new InvalidOperationException($"This operation may only be called with a {nameof(TokenType.Webhook)} token."); | |||
@@ -534,9 +534,9 @@ namespace Discord.API | |||
Preconditions.NotNull(args, nameof(args)); | |||
Preconditions.NotEqual(webhookId, 0, nameof(webhookId)); | |||
Preconditions.NotEqual(messageId, 0, nameof(messageId)); | |||
if (!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) | |||
Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content)); | |||
if (args.Embeds.IsSpecified) | |||
Preconditions.AtMost(args.Embeds.Value.Length, 10, nameof(args.Embeds), "A max of 10 Embeds are allowed."); | |||
if (args.Content?.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); | |||
@@ -91,12 +91,34 @@ namespace Discord.Webhook | |||
string username = null, string avatarUrl = null, RequestOptions options = null, AllowedMentions allowedMentions = null) | |||
=> WebhookClientHelper.SendMessageAsync(this, text, isTTS, embeds, username, avatarUrl, allowedMentions, options); | |||
/// <summary> Edits a message posted using this webhook. </summary> | |||
public Task EditMessageAsync(ulong messageId, string text = null, IEnumerable<Embed> embeds = null, | |||
/// <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="text">The message to be sent.</param> | |||
/// <param name="embeds">The <see cref="Discord.EmbedType.Rich" /> <see cref="Embed" /> enumeration to be sent.</param> | |||
/// <param name="allowedMentions"> | |||
/// Specifies if notifications are sent for mentioned users and roles in the message <paramref name="text"/>. | |||
/// If <c>null</c>, all mentioned roles and users will be notified. | |||
/// </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, string text = null, IEnumerable<Embed> embeds = null, | |||
AllowedMentions allowedMentions = null, RequestOptions options = null) | |||
=> WebhookClientHelper.EditMessageAsync(this, messageId, text, embeds, allowedMentions, options); | |||
=> WebhookClientHelper.ModifyMessageAsync(this, messageId, text, embeds, allowedMentions, options); | |||
/// <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) | |||
=> WebhookClientHelper.DeleteMessageAsync(this, messageId, options); | |||
@@ -36,16 +36,16 @@ namespace Discord.Webhook | |||
var model = await client.ApiClient.CreateWebhookMessageAsync(client.Webhook.Id, args, options: options).ConfigureAwait(false); | |||
return model.Id; | |||
} | |||
public static async Task EditMessageAsync(DiscordWebhookClient client, ulong messageId, string text, IEnumerable<Embed> embeds, | |||
public static async Task ModifyMessageAsync(DiscordWebhookClient client, ulong messageId, string text, IEnumerable<Embed> embeds, | |||
AllowedMentions allowedMentions, RequestOptions options) | |||
{ | |||
var args = new EditWebhookMessageParams(text); | |||
var args = new ModifyWebhookMessageParams { Content = text }; | |||
if (embeds != null) | |||
args.Embeds = embeds.Select(x => x.ToModel()).ToArray(); | |||
if (allowedMentions != null) | |||
args.AllowedMentions = allowedMentions.ToModel(); | |||
await client.ApiClient.EditWebhookMessageAsync(client.Webhook.Id, messageId, args, options: options).ConfigureAwait(false); | |||
await client.ApiClient.ModifyWebhookMessageAsync(client.Webhook.Id, messageId, args, options: options).ConfigureAwait(false); | |||
} | |||
public static async Task DeleteMessageAsync(DiscordWebhookClient client, ulong messageId, RequestOptions options) | |||
{ | |||