-
-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
27 changed files
with
679 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Discord.Net.Core/Entities/Webhooks/WebhookProperties.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma warning disable CS1591 | ||
using Newtonsoft.Json; | ||
|
||
namespace Discord.API | ||
{ | ||
internal class Webhook | ||
{ | ||
[JsonProperty("id")] | ||
public ulong Id { get; set; } | ||
[JsonProperty("channel_id")] | ||
public ulong ChannelId { get; set; } | ||
[JsonProperty("token")] | ||
public string Token { get; set; } | ||
|
||
[JsonProperty("name")] | ||
public Optional<string> Name { get; set; } | ||
[JsonProperty("avatar")] | ||
public Optional<string> Avatar { get; set; } | ||
[JsonProperty("guild_id")] | ||
public Optional<ulong> GuildId { get; set; } | ||
|
||
[JsonProperty("user")] | ||
public Optional<User> Creator { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma warning disable CS1591 | ||
using Newtonsoft.Json; | ||
|
||
namespace Discord.API.Rest | ||
{ | ||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)] | ||
internal class CreateWebhookParams | ||
{ | ||
[JsonProperty("name")] | ||
public string Name { get; set; } | ||
[JsonProperty("avatar")] | ||
public Optional<Image?> Avatar { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma warning disable CS1591 | ||
using Newtonsoft.Json; | ||
|
||
namespace Discord.API.Rest | ||
{ | ||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)] | ||
internal class ModifyWebhookParams | ||
{ | ||
[JsonProperty("name")] | ||
public Optional<string> Name { get; set; } | ||
[JsonProperty("avatar")] | ||
public Optional<Image?> Avatar { get; set; } | ||
[JsonProperty("channel_id")] | ||
public Optional<ulong> ChannelId { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.