mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
feat(bot): add -clear-attachments flag to pk;edit (#700)
This commit is contained in:
parent
1c9b7fae99
commit
83d1a08aaf
4 changed files with 13 additions and 5 deletions
|
|
@ -15,4 +15,7 @@ public record WebhookMessageEditRequest
|
||||||
|
|
||||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||||
public Optional<Embed[]?> Embeds { get; init; }
|
public Optional<Embed[]?> Embeds { get; init; }
|
||||||
|
|
||||||
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||||
|
public Optional<Message.Attachment[]?> Attachments { get; init; }
|
||||||
}
|
}
|
||||||
|
|
@ -118,7 +118,8 @@ public class ProxiedMessage
|
||||||
|
|
||||||
// Should we clear embeds?
|
// Should we clear embeds?
|
||||||
var clearEmbeds = ctx.MatchFlag("clear-embed", "ce");
|
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!;
|
newContent = originalMsg.Content!;
|
||||||
|
|
||||||
if (newContent == null)
|
if (newContent == null)
|
||||||
|
|
@ -218,7 +219,7 @@ public class ProxiedMessage
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var editedMsg =
|
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)
|
if (ctx.Guild == null)
|
||||||
await _rest.CreateReaction(ctx.Channel.Id, ctx.Message.Id, new Emoji { Name = Emojis.Success });
|
await _rest.CreateReaction(ctx.Channel.Id, ctx.Message.Id, new Emoji { Name = Emojis.Success });
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
using PluralKit.Core;
|
|
||||||
using Myriad.Utils;
|
using Myriad.Utils;
|
||||||
|
|
||||||
namespace PluralKit.Bot;
|
namespace PluralKit.Bot;
|
||||||
|
|
@ -87,7 +86,8 @@ public class WebhookExecutorService
|
||||||
return webhookMessage;
|
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
|
var allowedMentions = newContent.ParseMentions() with
|
||||||
{
|
{
|
||||||
|
|
@ -108,7 +108,10 @@ public class WebhookExecutorService
|
||||||
{
|
{
|
||||||
Content = newContent,
|
Content = newContent,
|
||||||
AllowedMentions = allowedMentions,
|
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);
|
return await _rest.EditWebhookMessage(webhook.Id, webhook.Token, messageId, editReq, threadId);
|
||||||
|
|
|
||||||
|
|
@ -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|-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|-nospace|-ns|Append/prepend without adding a space|
|
||||||
|pk;edit|-clear-embed|-ce|Remove embeds from a message|
|
|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;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|-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|
|
|pk;switch edit and pk;switch add|-prepend|-p|Prepend members to the current switch or make a new switch with members prepended|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue