diff --git a/Myriad/Rest/Types/Requests/WebhookMessageEditRequest.cs b/Myriad/Rest/Types/Requests/WebhookMessageEditRequest.cs index e1765a6f..512464d3 100644 --- a/Myriad/Rest/Types/Requests/WebhookMessageEditRequest.cs +++ b/Myriad/Rest/Types/Requests/WebhookMessageEditRequest.cs @@ -15,4 +15,7 @@ public record WebhookMessageEditRequest [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public Optional Embeds { get; init; } + + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public Optional Attachments { get; init; } } \ No newline at end of file diff --git a/PluralKit.Bot/Commands/Message.cs b/PluralKit.Bot/Commands/Message.cs index 6fc271a1..9a3b31fb 100644 --- a/PluralKit.Bot/Commands/Message.cs +++ b/PluralKit.Bot/Commands/Message.cs @@ -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 }); diff --git a/PluralKit.Bot/Services/WebhookExecutorService.cs b/PluralKit.Bot/Services/WebhookExecutorService.cs index fc23388c..999920d6 100644 --- a/PluralKit.Bot/Services/WebhookExecutorService.cs +++ b/PluralKit.Bot/Services/WebhookExecutorService.cs @@ -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 EditWebhookMessage(ulong guildId, ulong channelId, ulong messageId, string newContent, bool clearEmbeds = false) + public async Task 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.Some(new Embed[] { }) : Optional.None()), + Embeds = (clearEmbeds ? Optional.Some(new Embed[] { }) : Optional.None()), + Attachments = (clearAttachments + ? Optional.Some(new Message.Attachment[] { }) + : Optional.None()) }; return await _rest.EditWebhookMessage(webhook.Id, webhook.Token, messageId, editReq, threadId); diff --git a/docs/content/tips-and-tricks.md b/docs/content/tips-and-tricks.md index 2385ab70..7acba69a 100644 --- a/docs/content/tips-and-tricks.md +++ b/docs/content/tips-and-tricks.md @@ -82,6 +82,7 @@ You cannot look up private members or groups of another system. |pk;edit|-prepend|-p|Prepend the new content to the old message instead of overwriting it| |pk;edit|-nospace|-ns|Append/prepend without adding a space| |pk;edit|-clear-embed|-ce|Remove embeds from a message| +|pk;edit|-clear-attachments|-ca|Remove attachments from a message| |pk;edit|-regex|-x|Edit using a C# Regex formatted like s\|X\|Y or s\|X\|Y\|F, where \| is any character, X is a Regex, Y is a substitution string, and F is a set of Regex flags| |pk;switch edit and pk;switch add|-append|-a|Append members to the current switch or make a new switch with members appended| |pk;switch edit and pk;switch add|-prepend|-p|Prepend members to the current switch or make a new switch with members prepended|