You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.2 KiB

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).ConfigureAwait(false);
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;
}
}