|
|
@@ -473,13 +473,11 @@ namespace Discord.API |
|
|
|
var ids = new BucketIds(channelId: channelId); |
|
|
|
return await SendJsonAsync<Message>("POST", () => $"channels/{channelId}/messages", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); |
|
|
|
} |
|
|
|
public async Task<Message> CreateWebhookMessageAsync(ulong webhookId, CreateWebhookMessageParams args, string webhookToken = null, RequestOptions options = null) |
|
|
|
public async Task<Message> CreateWebhookMessageAsync(ulong webhookId, CreateWebhookMessageParams args, RequestOptions options = null) |
|
|
|
{ |
|
|
|
if (AuthTokenType != TokenType.Webhook && string.IsNullOrWhiteSpace(webhookToken)) |
|
|
|
if (AuthTokenType != TokenType.Webhook) |
|
|
|
throw new InvalidOperationException($"This operation may only be called with a {nameof(TokenType.Webhook)} token."); |
|
|
|
|
|
|
|
webhookToken = webhookToken ?? AuthToken; |
|
|
|
|
|
|
|
Preconditions.NotNull(args, nameof(args)); |
|
|
|
Preconditions.NotEqual(webhookId, 0, nameof(webhookId)); |
|
|
|
if (!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) |
|
|
@@ -490,9 +488,9 @@ namespace Discord.API |
|
|
|
options = RequestOptions.CreateOrClone(options); |
|
|
|
|
|
|
|
if (args.ReturnCreatedMessage) |
|
|
|
return await SendJsonAsync<Message>("POST", () => $"webhooks/{webhookId}/{webhookToken}", args, new BucketIds(), clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); |
|
|
|
return await SendJsonAsync<Message>("POST", () => $"webhooks/{webhookId}/{AuthToken}", args, new BucketIds(), clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); |
|
|
|
|
|
|
|
await SendJsonAsync("POST", () => $"webhooks/{webhookId}/{webhookToken}", args, new BucketIds(), clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); |
|
|
|
await SendJsonAsync("POST", () => $"webhooks/{webhookId}/{AuthToken}", args, new BucketIds(), clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); |
|
|
|
return null; |
|
|
|
} |
|
|
|
public async Task<Message> UploadFileAsync(ulong channelId, UploadFileParams args, RequestOptions options = null) |
|
|
@@ -1170,51 +1168,41 @@ namespace Discord.API |
|
|
|
|
|
|
|
return await SendJsonAsync<Webhook>("POST", () => $"channels/{channelId}/webhooks", args, new BucketIds(), options: options); |
|
|
|
} |
|
|
|
public async Task<Webhook> GetWebhookAsync(ulong webhookId, string webhookToken = null, RequestOptions options = null) |
|
|
|
public async Task<Webhook> GetWebhookAsync(ulong webhookId, RequestOptions options = null) |
|
|
|
{ |
|
|
|
Preconditions.NotEqual(webhookId, 0, nameof(webhookId)); |
|
|
|
options = RequestOptions.CreateOrClone(options); |
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(webhookToken)) |
|
|
|
{ |
|
|
|
webhookToken = "/" + webhookToken; |
|
|
|
options.IgnoreState = true; |
|
|
|
} |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
return await SendAsync<Webhook>("GET", () => $"webhooks/{webhookId}{webhookToken}", new BucketIds(), options: options).ConfigureAwait(false); |
|
|
|
if (AuthTokenType == TokenType.Webhook) |
|
|
|
return await SendAsync<Webhook>("GET", () => $"webhooks/{webhookId}/{AuthToken}", new BucketIds(), options: options).ConfigureAwait(false); |
|
|
|
else |
|
|
|
return await SendAsync<Webhook>("GET", () => $"webhooks/{webhookId}", new BucketIds(), options: options).ConfigureAwait(false); |
|
|
|
} |
|
|
|
catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } |
|
|
|
} |
|
|
|
public async Task<Webhook> ModifyWebhookAsync(ulong webhookId, ModifyWebhookParams args, string webhookToken = null, RequestOptions options = null) |
|
|
|
public async Task<Webhook> ModifyWebhookAsync(ulong webhookId, ModifyWebhookParams args, RequestOptions options = null) |
|
|
|
{ |
|
|
|
Preconditions.NotEqual(webhookId, 0, nameof(webhookId)); |
|
|
|
Preconditions.NotNull(args, nameof(args)); |
|
|
|
Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); |
|
|
|
options = RequestOptions.CreateOrClone(options); |
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(webhookToken)) |
|
|
|
{ |
|
|
|
webhookToken = "/" + webhookToken; |
|
|
|
options.IgnoreState = true; |
|
|
|
} |
|
|
|
|
|
|
|
return await SendJsonAsync<Webhook>("PATCH", () => $"webhooks/{webhookId}{webhookToken}", args, new BucketIds(), options: options).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (AuthTokenType == TokenType.Webhook) |
|
|
|
return await SendJsonAsync<Webhook>("PATCH", () => $"webhooks/{webhookId}/{AuthToken}", args, new BucketIds(), options: options).ConfigureAwait(false); |
|
|
|
else |
|
|
|
return await SendJsonAsync<Webhook>("PATCH", () => $"webhooks/{webhookId}", args, new BucketIds(), options: options).ConfigureAwait(false); |
|
|
|
} |
|
|
|
public async Task DeleteWebhookAsync(ulong webhookId, string webhookToken = null, RequestOptions options = null) |
|
|
|
public async Task DeleteWebhookAsync(ulong webhookId, RequestOptions options = null) |
|
|
|
{ |
|
|
|
Preconditions.NotEqual(webhookId, 0, nameof(webhookId)); |
|
|
|
options = RequestOptions.CreateOrClone(options); |
|
|
|
options.IgnoreState = true; |
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(webhookToken)) |
|
|
|
{ |
|
|
|
webhookToken = "/" + webhookToken; |
|
|
|
options.IgnoreState = true; |
|
|
|
} |
|
|
|
|
|
|
|
await SendAsync("DELETE", () => $"webhooks/{webhookId}{webhookToken}", new BucketIds(), options: options).ConfigureAwait(false); |
|
|
|
if (AuthTokenType == TokenType.Webhook) |
|
|
|
await SendAsync("DELETE", () => $"webhooks/{webhookId}/{AuthToken}", new BucketIds(), options: options).ConfigureAwait(false); |
|
|
|
else |
|
|
|
await SendAsync("DELETE", () => $"webhooks/{webhookId}", new BucketIds(), options: options).ConfigureAwait(false); |
|
|
|
} |
|
|
|
public async Task<IReadOnlyCollection<Webhook>> GetGuildWebhooksAsync(ulong guildId, RequestOptions options = null) |
|
|
|
{ |
|
|
|