From caf2b75f68dd5a5ce1f179e49f1332d0193ad3ca Mon Sep 17 00:00:00 2001 From: Petal Ladenson Date: Tue, 5 Nov 2024 21:29:57 -0700 Subject: [PATCH] fix(bot): correct permission check on delete message command --- PluralKit.Bot/ApplicationCommandMeta/ApplicationCommandTree.cs | 2 +- PluralKit.Bot/ApplicationCommands/Message.cs | 3 ++- PluralKit.Bot/Commands/Message.cs | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/PluralKit.Bot/ApplicationCommandMeta/ApplicationCommandTree.cs b/PluralKit.Bot/ApplicationCommandMeta/ApplicationCommandTree.cs index 04292a88..7f3600ae 100644 --- a/PluralKit.Bot/ApplicationCommandMeta/ApplicationCommandTree.cs +++ b/PluralKit.Bot/ApplicationCommandMeta/ApplicationCommandTree.cs @@ -12,7 +12,7 @@ public partial class ApplicationCommandTree else if (ctx.Event.Data!.Name == ProxiedMessageDelete.Name) return ctx.Execute(ProxiedMessageDelete, m => m.DeleteMessage(ctx)); else if (ctx.Event.Data!.Name == ProxiedMessagePing.Name) - return ctx.Execute(ProxiedMessageDelete, m => m.PingMessageAuthor(ctx)); + return ctx.Execute(ProxiedMessagePing, m => m.PingMessageAuthor(ctx)); return null; } diff --git a/PluralKit.Bot/ApplicationCommands/Message.cs b/PluralKit.Bot/ApplicationCommands/Message.cs index f0f239b9..a425b31c 100644 --- a/PluralKit.Bot/ApplicationCommands/Message.cs +++ b/PluralKit.Bot/ApplicationCommands/Message.cs @@ -78,7 +78,8 @@ public class ApplicationCommandProxiedMessage var message = await ctx.Repository.GetFullMessage(messageId); if (message != null) { - if (message.Message.Sender != ctx.User.Id && (ctx.System != null && message.System?.Id != ctx.System.Id)) + // if user has has a system and their system sent the message, or if user sent the message, do not error + if (!((ctx.System != null && message.System?.Id == ctx.System.Id) || message.Message.Sender == ctx.User.Id)) throw new PKError("You can only delete your own messages."); await DeleteMessageInner(ctx, message.Message.Guild ?? 0, message.Message.Channel, message.Message.Mid, false); diff --git a/PluralKit.Bot/Commands/Message.cs b/PluralKit.Bot/Commands/Message.cs index e92ff1f5..4f5257ec 100644 --- a/PluralKit.Bot/Commands/Message.cs +++ b/PluralKit.Bot/Commands/Message.cs @@ -400,7 +400,8 @@ public class ProxiedMessage if (!showContent) throw new PKError(noShowContentError); - if (message.Message.Sender != ctx.Author.Id && (ctx.System != null && message.System?.Id != ctx.System.Id)) + // if user has has a system and their system sent the message, or if user sent the message, do not error + if (!((ctx.System != null && message.System?.Id == ctx.System.Id) || message.Message.Sender == ctx.Author.Id)) throw new PKError("You can only delete your own messages."); await ctx.Rest.DeleteMessage(message.Message.Channel, message.Message.Mid);