feature: Webhook support for threads (#2291)
* Added thread support to webhooks Added thread support to delete/send messages for webhooks * Revert "Added thread support to webhooks" This reverts commit c45ef389c5df6a924b6ea5d46d5507386904f965. * read added threads as im a dummy * fixed formating * Fixed modify EmbedMessage
This commit is contained in:
@@ -88,8 +88,8 @@ namespace Discord.Webhook
|
||||
/// <returns> Returns the ID of the created message. </returns>
|
||||
public Task<ulong> SendMessageAsync(string text = null, bool isTTS = false, IEnumerable<Embed> embeds = null,
|
||||
string username = null, string avatarUrl = null, RequestOptions options = null, AllowedMentions allowedMentions = null,
|
||||
MessageComponent components = null, MessageFlags flags = MessageFlags.None)
|
||||
=> WebhookClientHelper.SendMessageAsync(this, text, isTTS, embeds, username, avatarUrl, allowedMentions, options, components, flags);
|
||||
MessageComponent components = null, MessageFlags flags = MessageFlags.None, ulong? threadId = null)
|
||||
=> WebhookClientHelper.SendMessageAsync(this, text, isTTS, embeds, username, avatarUrl, allowedMentions, options, components, flags, threadId);
|
||||
|
||||
/// <summary>
|
||||
/// Modifies a message posted using this webhook.
|
||||
@@ -103,8 +103,8 @@ namespace Discord.Webhook
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous modification operation.
|
||||
/// </returns>
|
||||
public Task ModifyMessageAsync(ulong messageId, Action<WebhookMessageProperties> func, RequestOptions options = null)
|
||||
=> WebhookClientHelper.ModifyMessageAsync(this, messageId, func, options);
|
||||
public Task ModifyMessageAsync(ulong messageId, Action<WebhookMessageProperties> func, RequestOptions options = null, ulong? threadId = null)
|
||||
=> WebhookClientHelper.ModifyMessageAsync(this, messageId, func, options, threadId);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a message posted using this webhook.
|
||||
@@ -117,43 +117,43 @@ namespace Discord.Webhook
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous deletion operation.
|
||||
/// </returns>
|
||||
public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null)
|
||||
=> WebhookClientHelper.DeleteMessageAsync(this, messageId, options);
|
||||
public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null, ulong ? threadId = null)
|
||||
=> WebhookClientHelper.DeleteMessageAsync(this, messageId, options, threadId);
|
||||
|
||||
/// <summary> Sends a message to the channel for this webhook with an attachment. </summary>
|
||||
/// <returns> Returns the ID of the created message. </returns>
|
||||
public Task<ulong> SendFileAsync(string filePath, string text, bool isTTS = false,
|
||||
IEnumerable<Embed> embeds = null, string username = null, string avatarUrl = null,
|
||||
RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null,
|
||||
MessageComponent components = null, MessageFlags flags = MessageFlags.None)
|
||||
MessageComponent components = null, MessageFlags flags = MessageFlags.None, ulong? threadId = null)
|
||||
=> WebhookClientHelper.SendFileAsync(this, filePath, text, isTTS, embeds, username, avatarUrl,
|
||||
allowedMentions, options, isSpoiler, components, flags);
|
||||
allowedMentions, options, isSpoiler, components, flags, threadId);
|
||||
/// <summary> Sends a message to the channel for this webhook with an attachment. </summary>
|
||||
/// <returns> Returns the ID of the created message. </returns>
|
||||
public Task<ulong> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false,
|
||||
IEnumerable<Embed> embeds = null, string username = null, string avatarUrl = null,
|
||||
RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null,
|
||||
MessageComponent components = null, MessageFlags flags = MessageFlags.None)
|
||||
MessageComponent components = null, MessageFlags flags = MessageFlags.None, ulong? threadId = null)
|
||||
=> WebhookClientHelper.SendFileAsync(this, stream, filename, text, isTTS, embeds, username,
|
||||
avatarUrl, allowedMentions, options, isSpoiler, components, flags);
|
||||
avatarUrl, allowedMentions, options, isSpoiler, components, flags, threadId);
|
||||
|
||||
/// <summary> Sends a message to the channel for this webhook with an attachment. </summary>
|
||||
/// <returns> Returns the ID of the created message. </returns>
|
||||
public Task<ulong> SendFileAsync(FileAttachment attachment, string text, bool isTTS = false,
|
||||
IEnumerable<Embed> embeds = null, string username = null, string avatarUrl = null,
|
||||
RequestOptions options = null, AllowedMentions allowedMentions = null, MessageComponent components = null,
|
||||
MessageFlags flags = MessageFlags.None)
|
||||
MessageFlags flags = MessageFlags.None, ulong? threadId = null)
|
||||
=> WebhookClientHelper.SendFileAsync(this, attachment, text, isTTS, embeds, username,
|
||||
avatarUrl, allowedMentions, components, options, flags);
|
||||
avatarUrl, allowedMentions, components, options, flags, threadId);
|
||||
|
||||
/// <summary> Sends a message to the channel for this webhook with an attachment. </summary>
|
||||
/// <returns> Returns the ID of the created message. </returns>
|
||||
public Task<ulong> SendFilesAsync(IEnumerable<FileAttachment> attachments, string text, bool isTTS = false,
|
||||
IEnumerable<Embed> embeds = null, string username = null, string avatarUrl = null,
|
||||
RequestOptions options = null, AllowedMentions allowedMentions = null, MessageComponent components = null,
|
||||
MessageFlags flags = MessageFlags.None)
|
||||
MessageFlags flags = MessageFlags.None, ulong? threadId = null)
|
||||
=> WebhookClientHelper.SendFilesAsync(this, attachments, text, isTTS, embeds, username, avatarUrl,
|
||||
allowedMentions, components, options, flags);
|
||||
allowedMentions, components, options, flags, threadId);
|
||||
|
||||
|
||||
/// <summary> Modifies the properties of this webhook. </summary>
|
||||
|
||||
@@ -21,8 +21,8 @@ namespace Discord.Webhook
|
||||
return RestInternalWebhook.Create(client, model);
|
||||
}
|
||||
public static async Task<ulong> SendMessageAsync(DiscordWebhookClient client,
|
||||
string text, bool isTTS, IEnumerable<Embed> embeds, string username, string avatarUrl,
|
||||
AllowedMentions allowedMentions, RequestOptions options, MessageComponent components, MessageFlags flags)
|
||||
string text, bool isTTS, IEnumerable<Embed> embeds, string username, string avatarUrl,
|
||||
AllowedMentions allowedMentions, RequestOptions options, MessageComponent components, MessageFlags flags, ulong? threadId = null)
|
||||
{
|
||||
var args = new CreateWebhookMessageParams
|
||||
{
|
||||
@@ -44,12 +44,13 @@ namespace Discord.Webhook
|
||||
|
||||
if (flags is not MessageFlags.None and not MessageFlags.SuppressEmbeds)
|
||||
throw new ArgumentException("The only valid MessageFlags are SuppressEmbeds and none.", nameof(flags));
|
||||
|
||||
var model = await client.ApiClient.CreateWebhookMessageAsync(client.Webhook.Id, args, options: options).ConfigureAwait(false);
|
||||
|
||||
var model = await client.ApiClient.CreateWebhookMessageAsync(client.Webhook.Id, args, options: options, threadId: threadId).ConfigureAwait(false);
|
||||
return model.Id;
|
||||
}
|
||||
|
||||
public static async Task ModifyMessageAsync(DiscordWebhookClient client, ulong messageId,
|
||||
Action<WebhookMessageProperties> func, RequestOptions options)
|
||||
Action<WebhookMessageProperties> func, RequestOptions options, ulong? threadId)
|
||||
{
|
||||
var args = new WebhookMessageProperties();
|
||||
func(args);
|
||||
@@ -94,35 +95,35 @@ namespace Discord.Webhook
|
||||
Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified,
|
||||
};
|
||||
|
||||
await client.ApiClient.ModifyWebhookMessageAsync(client.Webhook.Id, messageId, apiArgs, options)
|
||||
await client.ApiClient.ModifyWebhookMessageAsync(client.Webhook.Id, messageId, apiArgs, options, threadId)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
public static async Task DeleteMessageAsync(DiscordWebhookClient client, ulong messageId, RequestOptions options)
|
||||
public static async Task DeleteMessageAsync(DiscordWebhookClient client, ulong messageId, RequestOptions options, ulong? threadId)
|
||||
{
|
||||
await client.ApiClient.DeleteWebhookMessageAsync(client.Webhook.Id, messageId, options).ConfigureAwait(false);
|
||||
await client.ApiClient.DeleteWebhookMessageAsync(client.Webhook.Id, messageId, options, threadId).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task<ulong> SendFileAsync(DiscordWebhookClient client, string filePath, string text, bool isTTS,
|
||||
IEnumerable<Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options,
|
||||
bool isSpoiler, MessageComponent components, MessageFlags flags = MessageFlags.None)
|
||||
bool isSpoiler, MessageComponent components, MessageFlags flags = MessageFlags.None, ulong? threadId = null)
|
||||
{
|
||||
string filename = Path.GetFileName(filePath);
|
||||
using (var file = File.OpenRead(filePath))
|
||||
return await SendFileAsync(client, file, filename, text, isTTS, embeds, username, avatarUrl, allowedMentions, options, isSpoiler, components, flags).ConfigureAwait(false);
|
||||
return await SendFileAsync(client, file, filename, text, isTTS, embeds, username, avatarUrl, allowedMentions, options, isSpoiler, components, flags, threadId).ConfigureAwait(false);
|
||||
}
|
||||
public static Task<ulong> SendFileAsync(DiscordWebhookClient client, Stream stream, string filename, string text, bool isTTS,
|
||||
IEnumerable<Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options, bool isSpoiler,
|
||||
MessageComponent components, MessageFlags flags)
|
||||
=> SendFileAsync(client, new FileAttachment(stream, filename, isSpoiler: isSpoiler), text, isTTS, embeds, username, avatarUrl, allowedMentions, components, options, flags);
|
||||
MessageComponent components, MessageFlags flags, ulong? threadId)
|
||||
=> SendFileAsync(client, new FileAttachment(stream, filename, isSpoiler: isSpoiler), text, isTTS, embeds, username, avatarUrl, allowedMentions, components, options, flags, threadId);
|
||||
|
||||
public static Task<ulong> SendFileAsync(DiscordWebhookClient client, FileAttachment attachment, string text, bool isTTS,
|
||||
IEnumerable<Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions,
|
||||
MessageComponent components, RequestOptions options, MessageFlags flags)
|
||||
=> SendFilesAsync(client, new FileAttachment[] { attachment }, text, isTTS, embeds, username, avatarUrl, allowedMentions, components, options, flags);
|
||||
MessageComponent components, RequestOptions options, MessageFlags flags, ulong? threadId)
|
||||
=> SendFilesAsync(client, new FileAttachment[] { attachment }, text, isTTS, embeds, username, avatarUrl, allowedMentions, components, options, flags, threadId);
|
||||
|
||||
public static async Task<ulong> SendFilesAsync(DiscordWebhookClient client,
|
||||
IEnumerable<FileAttachment> attachments, string text, bool isTTS, IEnumerable<Embed> embeds, string username,
|
||||
string avatarUrl, AllowedMentions allowedMentions, MessageComponent components, RequestOptions options,
|
||||
MessageFlags flags)
|
||||
MessageFlags flags, ulong? threadId)
|
||||
{
|
||||
embeds ??= Array.Empty<Embed>();
|
||||
|
||||
@@ -164,7 +165,7 @@ namespace Discord.Webhook
|
||||
MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
|
||||
Flags = flags
|
||||
};
|
||||
var msg = await client.ApiClient.UploadWebhookFileAsync(client.Webhook.Id, args, options).ConfigureAwait(false);
|
||||
var msg = await client.ApiClient.UploadWebhookFileAsync(client.Webhook.Id, args, options, threadId).ConfigureAwait(false);
|
||||
return msg.Id;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user