feat: edit messages in threads

This commit is contained in:
spiral 2021-09-24 19:03:40 -04:00
parent c472a7f6df
commit db5fae0fb4
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31
3 changed files with 17 additions and 8 deletions

View File

@ -127,9 +127,14 @@ namespace Myriad.Rest
}
public Task<Message> EditWebhookMessage(ulong webhookId, string webhookToken, ulong messageId,
WebhookMessageEditRequest request) =>
_client.Patch<Message>($"/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<Message>(url, ("EditWebhookMessage", webhookId), request)!;
}
public Task<Channel> CreateDm(ulong recipientId) =>
_client.Post<Channel>($"/users/@me/channels", ("CreateDM", default), new CreateDmRequest(recipientId))!;

View File

@ -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);

View File

@ -81,15 +81,22 @@ namespace PluralKit.Bot
public async Task<Message> EditWebhookMessage(ulong channelId, ulong messageId, string newContent)
{
var webhook = await _webhookCache.GetWebhook(channelId);
var allowedMentions = newContent.ParseMentions() with
{
Roles = Array.Empty<ulong>(),
Parse = Array.Empty<AllowedMentions.ParseType>()
};
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<Message> ExecuteWebhookInner(Webhook webhook, ProxyRequest req, bool hasRetried = false)