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:
committed by
Christopher F
parent
a19ff188e9
commit
7b2ddd027c
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Model = Discord.API.Webhook;
|
||||
|
||||
namespace Discord.Webhook
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
internal class RestInternalWebhook : IWebhook
|
||||
{
|
||||
private DiscordWebhookClient _client;
|
||||
|
||||
public ulong Id { get; }
|
||||
public ulong ChannelId { get; }
|
||||
public string Token { get; }
|
||||
|
||||
public string Name { get; private set; }
|
||||
public string AvatarId { get; private set; }
|
||||
public ulong? GuildId { get; private set; }
|
||||
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
|
||||
internal RestInternalWebhook(DiscordWebhookClient apiClient, Model model)
|
||||
{
|
||||
_client = apiClient;
|
||||
Id = model.Id;
|
||||
ChannelId = model.Id;
|
||||
Token = model.Token;
|
||||
}
|
||||
internal static RestInternalWebhook Create(DiscordWebhookClient client, Model model)
|
||||
{
|
||||
var entity = new RestInternalWebhook(client, model);
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
|
||||
internal void Update(Model model)
|
||||
{
|
||||
if (model.Avatar.IsSpecified)
|
||||
AvatarId = model.Avatar.Value;
|
||||
if (model.GuildId.IsSpecified)
|
||||
GuildId = model.GuildId.Value;
|
||||
if (model.Name.IsSpecified)
|
||||
Name = model.Name.Value;
|
||||
}
|
||||
|
||||
public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
|
||||
=> CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
||||
|
||||
public async Task ModifyAsync(Action<WebhookProperties> func, RequestOptions options = null)
|
||||
{
|
||||
var model = await WebhookClientHelper.ModifyAsync(_client, func, options);
|
||||
Update(model);
|
||||
}
|
||||
|
||||
public Task DeleteAsync(RequestOptions options = null)
|
||||
=> WebhookClientHelper.DeleteAsync(_client, options);
|
||||
|
||||
public override string ToString() => $"Webhook: {Name}:{Id}";
|
||||
private string DebuggerDisplay => $"Webhook: {Name} ({Id})";
|
||||
|
||||
IUser IWebhook.Creator => null;
|
||||
ITextChannel IWebhook.Channel => null;
|
||||
IGuild IWebhook.Guild => null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user