diff --git a/Myriad/Rest/DiscordApiClient.cs b/Myriad/Rest/DiscordApiClient.cs index 3b37fc79..3faa202f 100644 --- a/Myriad/Rest/DiscordApiClient.cs +++ b/Myriad/Rest/DiscordApiClient.cs @@ -127,9 +127,14 @@ namespace Myriad.Rest } public Task EditWebhookMessage(ulong webhookId, string webhookToken, ulong messageId, - WebhookMessageEditRequest request) => - _client.Patch($"/webhooks/{webhookId}/{webhookToken}/messages/{messageId}", - ("EditWebhookMessage", webhookId), request)!; + WebhookMessageEditRequest request, ulong? threadId = null) + { + var url = $"/webhooks/{webhookId}/{webhookToken}/messages/{messageId}"; + if (threadId != null) + url += $"?thread_id={threadId}"; + + return _client.Patch(url, ("EditWebhookMessage", webhookId), request)!; + } public Task CreateDm(ulong recipientId) => _client.Post($"/users/@me/channels", ("CreateDM", default), new CreateDmRequest(recipientId))!; diff --git a/PluralKit.Bot/Commands/Message.cs b/PluralKit.Bot/Commands/Message.cs index 3e4f22da..1dfbcf59 100644 --- a/PluralKit.Bot/Commands/Message.cs +++ b/PluralKit.Bot/Commands/Message.cs @@ -49,9 +49,6 @@ namespace PluralKit.Bot if (ctx.System.Id != msg.System.Id) throw new PKError("Can't edit a message sent by a different system."); - if (_cache.GetRootChannel(msg.Message.Channel).Id != msg.Message.Channel) - throw new PKError("PluralKit cannot edit messages in threads."); - var newContent = ctx.RemainderOrNull().NormalizeLineEndSpacing(); var originalMsg = await _rest.GetMessage(msg.Message.Channel, msg.Message.Mid); diff --git a/PluralKit.Bot/Services/WebhookExecutorService.cs b/PluralKit.Bot/Services/WebhookExecutorService.cs index c19fc5f8..d66be6c4 100644 --- a/PluralKit.Bot/Services/WebhookExecutorService.cs +++ b/PluralKit.Bot/Services/WebhookExecutorService.cs @@ -81,15 +81,22 @@ namespace PluralKit.Bot public async Task EditWebhookMessage(ulong channelId, ulong messageId, string newContent) { - var webhook = await _webhookCache.GetWebhook(channelId); var allowedMentions = newContent.ParseMentions() with { Roles = Array.Empty(), Parse = Array.Empty() }; + ulong? threadId = null; + var root = _cache.GetRootChannel(channelId); + if (root.Id != channelId) + threadId = channelId; + + var webhook = await _webhookCache.GetWebhook(root.Id); + return await _rest.EditWebhookMessage(webhook.Id, webhook.Token, messageId, - new WebhookMessageEditRequest { Content = newContent, AllowedMentions = allowedMentions }); + new WebhookMessageEditRequest { Content = newContent, AllowedMentions = allowedMentions }, + threadId); } private async Task ExecuteWebhookInner(Webhook webhook, ProxyRequest req, bool hasRetried = false)