feat: edit messages in threads
This commit is contained in:
parent
c472a7f6df
commit
db5fae0fb4
@ -127,9 +127,14 @@ namespace Myriad.Rest
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Task<Message> EditWebhookMessage(ulong webhookId, string webhookToken, ulong messageId,
|
public Task<Message> EditWebhookMessage(ulong webhookId, string webhookToken, ulong messageId,
|
||||||
WebhookMessageEditRequest request) =>
|
WebhookMessageEditRequest request, ulong? threadId = null)
|
||||||
_client.Patch<Message>($"/webhooks/{webhookId}/{webhookToken}/messages/{messageId}",
|
{
|
||||||
("EditWebhookMessage", webhookId), request)!;
|
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) =>
|
public Task<Channel> CreateDm(ulong recipientId) =>
|
||||||
_client.Post<Channel>($"/users/@me/channels", ("CreateDM", default), new CreateDmRequest(recipientId))!;
|
_client.Post<Channel>($"/users/@me/channels", ("CreateDM", default), new CreateDmRequest(recipientId))!;
|
||||||
|
@ -49,9 +49,6 @@ namespace PluralKit.Bot
|
|||||||
if (ctx.System.Id != msg.System.Id)
|
if (ctx.System.Id != msg.System.Id)
|
||||||
throw new PKError("Can't edit a message sent by a different system.");
|
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 newContent = ctx.RemainderOrNull().NormalizeLineEndSpacing();
|
||||||
|
|
||||||
var originalMsg = await _rest.GetMessage(msg.Message.Channel, msg.Message.Mid);
|
var originalMsg = await _rest.GetMessage(msg.Message.Channel, msg.Message.Mid);
|
||||||
|
@ -81,15 +81,22 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
public async Task<Message> EditWebhookMessage(ulong channelId, ulong messageId, string newContent)
|
public async Task<Message> EditWebhookMessage(ulong channelId, ulong messageId, string newContent)
|
||||||
{
|
{
|
||||||
var webhook = await _webhookCache.GetWebhook(channelId);
|
|
||||||
var allowedMentions = newContent.ParseMentions() with
|
var allowedMentions = newContent.ParseMentions() with
|
||||||
{
|
{
|
||||||
Roles = Array.Empty<ulong>(),
|
Roles = Array.Empty<ulong>(),
|
||||||
Parse = Array.Empty<AllowedMentions.ParseType>()
|
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,
|
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)
|
private async Task<Message> ExecuteWebhookInner(Webhook webhook, ProxyRequest req, bool hasRetried = false)
|
||||||
|
Loading…
Reference in New Issue
Block a user