* Added webhook components for hooks having an application ID.pull/1923/head
| @@ -10089,6 +10089,11 @@ | |||||
| Gets the user that created this webhook. | Gets the user that created this webhook. | ||||
| </summary> | </summary> | ||||
| </member> | </member> | ||||
| <member name="P:Discord.IWebhook.ApplicationId"> | |||||
| <summary> | |||||
| Gets the ID of the application owning this webhook. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="M:Discord.IWebhook.ModifyAsync(System.Action{Discord.WebhookProperties},Discord.RequestOptions)"> | <member name="M:Discord.IWebhook.ModifyAsync(System.Action{Discord.WebhookProperties},Discord.RequestOptions)"> | ||||
| <summary> | <summary> | ||||
| Modifies this webhook. | Modifies this webhook. | ||||
| @@ -1,4 +1,4 @@ | |||||
| using System; | |||||
| using System; | |||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| namespace Discord | namespace Discord | ||||
| @@ -49,6 +49,11 @@ namespace Discord | |||||
| /// </summary> | /// </summary> | ||||
| IUser Creator { get; } | IUser Creator { get; } | ||||
| /// <summary> | |||||
| /// Gets the ID of the application owning this webhook. | |||||
| /// </summary> | |||||
| ulong? ApplicationId { get; } | |||||
| /// <summary> | /// <summary> | ||||
| /// Modifies this webhook. | /// Modifies this webhook. | ||||
| /// </summary> | /// </summary> | ||||
| @@ -21,5 +21,7 @@ namespace Discord.API | |||||
| [JsonProperty("user")] | [JsonProperty("user")] | ||||
| public Optional<User> Creator { get; set; } | public Optional<User> Creator { get; set; } | ||||
| [JsonProperty("application_id")] | |||||
| public Optional<ulong> ApplicationId { get; set; } | |||||
| } | } | ||||
| } | } | ||||
| @@ -12,5 +12,7 @@ namespace Discord.API.Rest | |||||
| public Optional<Embed[]> Embeds { get; set; } | public Optional<Embed[]> Embeds { get; set; } | ||||
| [JsonProperty("allowed_mentions")] | [JsonProperty("allowed_mentions")] | ||||
| public Optional<AllowedMentions> AllowedMentions { get; set; } | public Optional<AllowedMentions> AllowedMentions { get; set; } | ||||
| [JsonProperty("components")] | |||||
| public Optional<API.ActionRowComponent[]> Components { get; set; } | |||||
| } | } | ||||
| } | } | ||||
| @@ -4766,6 +4766,9 @@ | |||||
| <member name="P:Discord.Rest.RestWebhook.Creator"> | <member name="P:Discord.Rest.RestWebhook.Creator"> | ||||
| <inheritdoc /> | <inheritdoc /> | ||||
| </member> | </member> | ||||
| <member name="P:Discord.Rest.RestWebhook.ApplicationId"> | |||||
| <inheritdoc /> | |||||
| </member> | |||||
| <member name="P:Discord.Rest.RestWebhook.CreatedAt"> | <member name="P:Discord.Rest.RestWebhook.CreatedAt"> | ||||
| <inheritdoc /> | <inheritdoc /> | ||||
| </member> | </member> | ||||
| @@ -24,6 +24,8 @@ namespace Discord.Rest | |||||
| public ulong? GuildId { get; private set; } | public ulong? GuildId { get; private set; } | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public IUser Creator { get; private set; } | public IUser Creator { get; private set; } | ||||
| /// <inheritdoc /> | |||||
| public ulong? ApplicationId { get; private set; } | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); | public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); | ||||
| @@ -66,6 +68,8 @@ namespace Discord.Rest | |||||
| GuildId = model.GuildId.Value; | GuildId = model.GuildId.Value; | ||||
| if (model.Name.IsSpecified) | if (model.Name.IsSpecified) | ||||
| Name = model.Name.Value; | Name = model.Name.Value; | ||||
| if (model.ApplicationId.IsSpecified) | |||||
| ApplicationId = model.ApplicationId.Value; | |||||
| } | } | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| @@ -68,6 +68,7 @@ namespace Discord.Rest | |||||
| model.Video = entity.Video.Value.ToModel(); | model.Video = entity.Video.Value.ToModel(); | ||||
| return model; | return model; | ||||
| } | } | ||||
| public static API.AllowedMentions ToModel(this AllowedMentions entity) | public static API.AllowedMentions ToModel(this AllowedMentions entity) | ||||
| { | { | ||||
| return new API.AllowedMentions() | return new API.AllowedMentions() | ||||
| @@ -31,7 +31,7 @@ | |||||
| <exception cref="T:System.ArgumentException">Thrown if the <paramref name="webhookUrl"/> is an invalid format.</exception> | <exception cref="T:System.ArgumentException">Thrown if the <paramref name="webhookUrl"/> is an invalid format.</exception> | ||||
| <exception cref="T:System.ArgumentNullException">Thrown if the <paramref name="webhookUrl"/> is null or whitespace.</exception> | <exception cref="T:System.ArgumentNullException">Thrown if the <paramref name="webhookUrl"/> is null or whitespace.</exception> | ||||
| </member> | </member> | ||||
| <member name="M:Discord.Webhook.DiscordWebhookClient.SendMessageAsync(System.String,System.Boolean,System.Collections.Generic.IEnumerable{Discord.Embed},System.String,System.String,Discord.RequestOptions,Discord.AllowedMentions)"> | |||||
| <member name="M:Discord.Webhook.DiscordWebhookClient.SendMessageAsync(System.String,System.Boolean,System.Collections.Generic.IEnumerable{Discord.Embed},System.String,System.String,Discord.RequestOptions,Discord.AllowedMentions,Discord.MessageComponent)"> | |||||
| <summary> Sends a message to the channel for this webhook. </summary> | <summary> Sends a message to the channel for this webhook. </summary> | ||||
| <returns> Returns the ID of the created message. </returns> | <returns> Returns the ID of the created message. </returns> | ||||
| </member> | </member> | ||||
| @@ -99,6 +99,11 @@ | |||||
| Gets or sets the allowed mentions of the message. | Gets or sets the allowed mentions of the message. | ||||
| </summary> | </summary> | ||||
| </member> | </member> | ||||
| <member name="P:Discord.Webhook.WebhookMessageProperties.Components"> | |||||
| <summary> | |||||
| Gets or sets the components that the message should display. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="M:Discord.Webhook.WebhookClientHelper.GetWebhookAsync(Discord.Webhook.DiscordWebhookClient,System.UInt64)"> | <member name="M:Discord.Webhook.WebhookClientHelper.GetWebhookAsync(Discord.Webhook.DiscordWebhookClient,System.UInt64)"> | ||||
| <exception cref="T:System.InvalidOperationException">Could not find a webhook with the supplied credentials.</exception> | <exception cref="T:System.InvalidOperationException">Could not find a webhook with the supplied credentials.</exception> | ||||
| </member> | </member> | ||||
| @@ -88,8 +88,8 @@ namespace Discord.Webhook | |||||
| /// <summary> Sends a message to the channel for this webhook. </summary> | /// <summary> Sends a message to the channel for this webhook. </summary> | ||||
| /// <returns> Returns the ID of the created message. </returns> | /// <returns> Returns the ID of the created message. </returns> | ||||
| public Task<ulong> SendMessageAsync(string text = null, bool isTTS = false, IEnumerable<Embed> embeds = null, | 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) | |||||
| => WebhookClientHelper.SendMessageAsync(this, text, isTTS, embeds, username, avatarUrl, allowedMentions, options); | |||||
| string username = null, string avatarUrl = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageComponent component = null) | |||||
| => WebhookClientHelper.SendMessageAsync(this, text, isTTS, embeds, username, avatarUrl, allowedMentions, options, component); | |||||
| /// <summary> | /// <summary> | ||||
| /// Modifies a message posted using this webhook. | /// Modifies a message posted using this webhook. | ||||
| @@ -22,5 +22,9 @@ namespace Discord.Webhook | |||||
| /// Gets or sets the allowed mentions of the message. | /// Gets or sets the allowed mentions of the message. | ||||
| /// </summary> | /// </summary> | ||||
| public Optional<AllowedMentions> AllowedMentions { get; set; } | public Optional<AllowedMentions> AllowedMentions { get; set; } | ||||
| /// <summary> | |||||
| /// Gets or sets the components that the message should display. | |||||
| /// </summary> | |||||
| public Optional<MessageComponent> Components { get; set; } | |||||
| } | } | ||||
| } | } | ||||
| @@ -17,6 +17,7 @@ namespace Discord.Webhook | |||||
| public string Name { get; private set; } | public string Name { get; private set; } | ||||
| public string AvatarId { get; private set; } | public string AvatarId { get; private set; } | ||||
| public ulong? GuildId { get; private set; } | public ulong? GuildId { get; private set; } | ||||
| public ulong? ApplicationId { get; private set; } | |||||
| public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); | public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); | ||||
| @@ -44,6 +45,8 @@ namespace Discord.Webhook | |||||
| GuildId = model.GuildId.Value; | GuildId = model.GuildId.Value; | ||||
| if (model.Name.IsSpecified) | if (model.Name.IsSpecified) | ||||
| Name = model.Name.Value; | Name = model.Name.Value; | ||||
| if (model.ApplicationId.IsSpecified) | |||||
| ApplicationId = model.ApplicationId.Value; | |||||
| } | } | ||||
| public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) | public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) | ||||
| @@ -21,7 +21,7 @@ namespace Discord.Webhook | |||||
| 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, AllowedMentions allowedMentions, RequestOptions options) | |||||
| string text, bool isTTS, IEnumerable<Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options, MessageComponent component) | |||||
| { | { | ||||
| var args = new CreateWebhookMessageParams | var args = new CreateWebhookMessageParams | ||||
| { | { | ||||
| @@ -37,6 +37,8 @@ namespace Discord.Webhook | |||||
| args.AvatarUrl = avatarUrl; | args.AvatarUrl = avatarUrl; | ||||
| if (allowedMentions != null) | if (allowedMentions != null) | ||||
| args.AllowedMentions = allowedMentions.ToModel(); | args.AllowedMentions = allowedMentions.ToModel(); | ||||
| if (component != null) | |||||
| args.Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray(); | |||||
| var model = await client.ApiClient.CreateWebhookMessageAsync(client.Webhook.Id, args, options: options).ConfigureAwait(false); | var model = await client.ApiClient.CreateWebhookMessageAsync(client.Webhook.Id, args, options: options).ConfigureAwait(false); | ||||
| return model.Id; | return model.Id; | ||||
| @@ -83,7 +85,8 @@ namespace Discord.Webhook | |||||
| : Optional.Create<API.Embed[]>(), | : Optional.Create<API.Embed[]>(), | ||||
| AllowedMentions = args.AllowedMentions.IsSpecified | AllowedMentions = args.AllowedMentions.IsSpecified | ||||
| ? args.AllowedMentions.Value.ToModel() | ? args.AllowedMentions.Value.ToModel() | ||||
| : Optional.Create<API.AllowedMentions>() | |||||
| : 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) | await client.ApiClient.ModifyWebhookMessageAsync(client.Webhook.Id, messageId, apiArgs, options) | ||||