feat(bot): add -clear-attachments flag to pk;edit (#700)

This commit is contained in:
sam 2024-11-16 22:01:57 +01:00 committed by GitHub
parent 1c9b7fae99
commit 83d1a08aaf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 5 deletions

View file

@ -118,7 +118,8 @@ public class ProxiedMessage
// Should we clear embeds?
var clearEmbeds = ctx.MatchFlag("clear-embed", "ce");
if (clearEmbeds && newContent == null)
var clearAttachments = ctx.MatchFlag("clear-attachments", "ca");
if ((clearEmbeds || clearAttachments) && newContent == null)
newContent = originalMsg.Content!;
if (newContent == null)
@ -218,7 +219,7 @@ public class ProxiedMessage
try
{
var editedMsg =
await _webhookExecutor.EditWebhookMessage(msg.Guild ?? 0, msg.Channel, msg.Mid, newContent, clearEmbeds);
await _webhookExecutor.EditWebhookMessage(msg.Guild ?? 0, msg.Channel, msg.Mid, newContent, clearEmbeds, clearAttachments);
if (ctx.Guild == null)
await _rest.CreateReaction(ctx.Channel.Id, ctx.Message.Id, new Emoji { Name = Emojis.Success });

View file

@ -19,7 +19,6 @@ using Newtonsoft.Json.Linq;
using Serilog;
using PluralKit.Core;
using Myriad.Utils;
namespace PluralKit.Bot;
@ -87,7 +86,8 @@ public class WebhookExecutorService
return webhookMessage;
}
public async Task<Message> EditWebhookMessage(ulong guildId, ulong channelId, ulong messageId, string newContent, bool clearEmbeds = false)
public async Task<Message> EditWebhookMessage(ulong guildId, ulong channelId, ulong messageId, string newContent,
bool clearEmbeds = false, bool clearAttachments = false)
{
var allowedMentions = newContent.ParseMentions() with
{
@ -108,7 +108,10 @@ public class WebhookExecutorService
{
Content = newContent,
AllowedMentions = allowedMentions,
Embeds = (clearEmbeds == true ? Optional<Embed[]>.Some(new Embed[] { }) : Optional<Embed[]>.None()),
Embeds = (clearEmbeds ? Optional<Embed[]>.Some(new Embed[] { }) : Optional<Embed[]>.None()),
Attachments = (clearAttachments
? Optional<Message.Attachment[]>.Some(new Message.Attachment[] { })
: Optional<Message.Attachment[]>.None())
};
return await _rest.EditWebhookMessage(webhook.Id, webhook.Token, messageId, editReq, threadId);