Add missing REST Webhook implemenation (#843)

* Add Webhook API models, REST implementation, and Socket bridges.

* Remove token overrides from REST.

Leaving that as a Webhook package only feature.

* Add Webhook API models, REST implementation, and Socket bridges.

* Remove token overrides from REST.

Leaving that as a Webhook package only feature.

* Webhook core implementation.

* Webhook REST implementation.

* Webhook client implementation.

* Add channel bucket id.
This commit is contained in:
Alex Gravely
2017-12-23 15:17:20 -05:00
committed by Christopher F
parent a19ff188e9
commit 7b2ddd027c
27 changed files with 680 additions and 41 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace Discord
@@ -19,5 +20,12 @@ namespace Discord
/// <summary> Modifies this text channel. </summary>
Task ModifyAsync(Action<TextChannelProperties> func, RequestOptions options = null);
/// <summary> Creates a webhook in this text channel. </summary>
Task<IWebhook> CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null);
/// <summary> Gets the webhook in this text channel with the provided id, or null if not found. </summary>
Task<IWebhook> GetWebhookAsync(ulong id, RequestOptions options = null);
/// <summary> Gets the webhooks for this text channel. </summary>
Task<IReadOnlyCollection<IWebhook>> GetWebhooksAsync(RequestOptions options = null);
}
}

View File

@@ -118,6 +118,11 @@ namespace Discord
/// <summary> Removes all users from this guild if they have not logged on in a provided number of days or, if simulate is true, returns the number of users that would be removed. </summary>
Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null);
/// <summary> Gets the webhook in this guild with the provided id, or null if not found. </summary>
Task<IWebhook> GetWebhookAsync(ulong id, RequestOptions options = null);
/// <summary> Gets a collection of all webhooks for this guild. </summary>
Task<IReadOnlyCollection<IWebhook>> GetWebhooksAsync(RequestOptions options = null);
/// <summary> Gets a specific emote from this guild. </summary>
Task<GuildEmote> GetEmoteAsync(ulong id, RequestOptions options = null);
/// <summary> Creates a new emote in this guild. </summary>

View File

@@ -1,6 +1,5 @@
namespace Discord
{
//TODO: Add webhook endpoints
public interface IWebhookUser : IGuildUser
{
ulong WebhookId { get; }

View File

@@ -0,0 +1,34 @@
using System;
using System.Threading.Tasks;
namespace Discord
{
public interface IWebhook : IDeletable, ISnowflakeEntity
{
/// <summary> Gets the token of this webhook. </summary>
string Token { get; }
/// <summary> Gets the default name of this webhook. </summary>
string Name { get; }
/// <summary> Gets the id of this webhook's default avatar. </summary>
string AvatarId { get; }
/// <summary> Gets the url to this webhook's default avatar. </summary>
string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128);
/// <summary> Gets the channel for this webhook. </summary>
ITextChannel Channel { get; }
/// <summary> Gets the id of the channel for this webhook. </summary>
ulong ChannelId { get; }
/// <summary> Gets the guild owning this webhook. </summary>
IGuild Guild { get; }
/// <summary> Gets the id of the guild owning this webhook. </summary>
ulong? GuildId { get; }
/// <summary> Gets the user that created this webhook. </summary>
IUser Creator { get; }
/// <summary> Modifies this webhook. </summary>
Task ModifyAsync(Action<WebhookProperties> func, RequestOptions options = null);
}
}

View File

@@ -0,0 +1,41 @@
namespace Discord
{
/// <summary>
/// Modify an <see cref="IWebhook"/> with the specified parameters.
/// </summary>
/// <example>
/// <code language="c#">
/// await webhook.ModifyAsync(x =>
/// {
/// x.Name = "Bob";
/// x.Avatar = new Image("avatar.jpg");
/// });
/// </code>
/// </example>
/// <seealso cref="IWebhook"/>
public class WebhookProperties
{
/// <summary>
/// The default name of the webhook.
/// </summary>
public Optional<string> Name { get; set; }
/// <summary>
/// The default avatar of the webhook.
/// </summary>
public Optional<Image?> Image { get; set; }
/// <summary>
/// The channel for this webhook.
/// </summary>
/// <remarks>
/// This field is not used when authenticated with <see cref="TokenType.Webhook"/>.
/// </remarks>
public Optional<ITextChannel> Channel { get; set; }
/// <summary>
/// The channel id for this webhook.
/// </summary>
/// <remarks>
/// This field is not used when authenticated with <see cref="TokenType.Webhook"/>.
/// </remarks>
public Optional<ulong> ChannelId { get; set; }
}
}

View File

@@ -34,5 +34,7 @@ namespace Discord
Task<IReadOnlyCollection<IVoiceRegion>> GetVoiceRegionsAsync(RequestOptions options = null);
Task<IVoiceRegion> GetVoiceRegionAsync(string id, RequestOptions options = null);
Task<IWebhook> GetWebhookAsync(ulong id, RequestOptions options = null);
}
}