fix: check HasNext after matching message in EditMessage, use PKSyntaxError instead of PKError

This commit is contained in:
spiral 2022-01-21 17:10:00 -05:00
parent 4a739c2d61
commit 31a129dabf
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31

View File

@ -46,14 +46,14 @@ public class ProxiedMessage
public async Task EditMessage(Context ctx) public async Task EditMessage(Context ctx)
{ {
if (!ctx.HasNext())
throw new PKSyntaxError("You need to include the message to edit in.");
var msg = await GetMessageToEdit(ctx); var msg = await GetMessageToEdit(ctx);
if (ctx.System.Id != msg.System?.Id) if (ctx.System.Id != msg.System?.Id)
throw new PKError("Can't edit a message sent by a different system."); throw new PKError("Can't edit a message sent by a different system.");
if (!ctx.HasNext())
throw new PKSyntaxError("You need to include the message to edit in.");
var newContent = ctx.RemainderOrNull().NormalizeLineEndSpacing(); var newContent = ctx.RemainderOrNull().NormalizeLineEndSpacing();
var originalMsg = await _rest.GetMessageOrNull(msg.Message.Channel, msg.Message.Mid); var originalMsg = await _rest.GetMessageOrNull(msg.Message.Channel, msg.Message.Mid);
@ -96,15 +96,15 @@ public class ProxiedMessage
if (msg == null) if (msg == null)
{ {
if (ctx.Guild == null) if (ctx.Guild == null)
throw new PKError("You must use a message link to edit messages in DMs."); throw new PKSyntaxError("You must use a message link to edit messages in DMs.");
var recent = await FindRecentMessage(ctx); var recent = await FindRecentMessage(ctx);
if (recent == null) if (recent == null)
throw new PKError("Could not find a recent message to edit."); throw new PKSyntaxError("Could not find a recent message to edit.");
msg = await _repo.GetMessage(conn, recent.Mid); msg = await _repo.GetMessage(conn, recent.Mid);
if (msg == null) if (msg == null)
throw new PKError("Could not find a recent message to edit."); throw new PKSyntaxError("Could not find a recent message to edit.");
} }
if (msg.Message.Channel != ctx.Channel.Id) if (msg.Message.Channel != ctx.Channel.Id)