fix(bot): correct permission check on delete message command

This commit is contained in:
Petal Ladenson 2024-11-05 21:29:57 -07:00 committed by GitHub
parent eff4120ce1
commit caf2b75f68
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 3 deletions

View file

@ -12,7 +12,7 @@ public partial class ApplicationCommandTree
else if (ctx.Event.Data!.Name == ProxiedMessageDelete.Name)
return ctx.Execute<ApplicationCommandProxiedMessage>(ProxiedMessageDelete, m => m.DeleteMessage(ctx));
else if (ctx.Event.Data!.Name == ProxiedMessagePing.Name)
return ctx.Execute<ApplicationCommandProxiedMessage>(ProxiedMessageDelete, m => m.PingMessageAuthor(ctx));
return ctx.Execute<ApplicationCommandProxiedMessage>(ProxiedMessagePing, m => m.PingMessageAuthor(ctx));
return null;
}

View file

@ -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);

View file

@ -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);