From 82661001554af02c4ed40579a0353d7f86572084 Mon Sep 17 00:00:00 2001 From: alyssa Date: Sun, 23 Feb 2025 11:02:55 +0000 Subject: [PATCH] fix(bot): clean up some error messages --- PluralKit.Bot/Commands/Message.cs | 6 +++ PluralKit.Bot/Proxy/ProxyService.cs | 44 +++++++++++-------- .../Services/WebhookExecutorService.cs | 3 ++ 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/PluralKit.Bot/Commands/Message.cs b/PluralKit.Bot/Commands/Message.cs index dbd986cf..692f75b1 100644 --- a/PluralKit.Bot/Commands/Message.cs +++ b/PluralKit.Bot/Commands/Message.cs @@ -241,6 +241,12 @@ public class ProxiedMessage { throw new PKError("Could not edit message."); } + catch (BadRequestException e) + { + if (e.Message == "Voice messages cannot be edited") + throw new PKError($"{e.Message}."); + throw; + } } private async Task<(PKMessage, SystemId)> GetMessageToEdit(Context ctx, Duration timeout, bool isReproxy) diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index 79cced26..ead5f1a6 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -238,25 +238,33 @@ public class ProxyService if (trigger.Flags.HasFlag(Message.MessageFlags.VoiceMessage)) flags |= Message.MessageFlags.VoiceMessage; - var proxyMessage = await _webhookExecutor.ExecuteWebhook(new ProxyRequest + try { - GuildId = trigger.GuildId!.Value, - ChannelId = rootChannel.Id, - ThreadId = threadId, - MessageId = trigger.Id, - Name = await FixSameName(messageChannel.Id, ctx, match.Member), - AvatarUrl = AvatarUtils.TryRewriteCdnUrl(match.Member.ProxyAvatar(ctx)), - Content = content, - Attachments = trigger.Attachments, - FileSizeLimit = guild.FileSizeLimit(), - Embeds = embeds.ToArray(), - Stickers = trigger.StickerItems, - AllowEveryone = allowEveryone, - Flags = flags, - Tts = tts, - Poll = trigger.Poll, - }); - await HandleProxyExecutedActions(ctx, autoproxySettings, trigger, proxyMessage, match); + var proxyMessage = await _webhookExecutor.ExecuteWebhook(new ProxyRequest + { + GuildId = trigger.GuildId!.Value, + ChannelId = rootChannel.Id, + ThreadId = threadId, + MessageId = trigger.Id, + Name = await FixSameName(messageChannel.Id, ctx, match.Member), + AvatarUrl = AvatarUtils.TryRewriteCdnUrl(match.Member.ProxyAvatar(ctx)), + Content = content, + Attachments = trigger.Attachments, + FileSizeLimit = guild.FileSizeLimit(), + Embeds = embeds.ToArray(), + Stickers = trigger.StickerItems, + AllowEveryone = allowEveryone, + Flags = flags, + Tts = tts, + Poll = trigger.Poll, + }); + await HandleProxyExecutedActions(ctx, autoproxySettings, trigger, proxyMessage, match); + } + catch (PKError) + { + if (ctx.ProxyErrorMessageEnabled) + throw; + } } public async Task ExecuteReproxy(Message trigger, PKMessage msg, List members, ProxyMember member, string prefix) diff --git a/PluralKit.Bot/Services/WebhookExecutorService.cs b/PluralKit.Bot/Services/WebhookExecutorService.cs index 999920d6..3bfcb3bf 100644 --- a/PluralKit.Bot/Services/WebhookExecutorService.cs +++ b/PluralKit.Bot/Services/WebhookExecutorService.cs @@ -191,6 +191,9 @@ public class WebhookExecutorService } catch (BadRequestException e) { + if (e.Message == "Cannot use one or more emoji included with this poll") + throw new PKError($"Discord rejected proxy message: {e.Message}"); + // explanation for hacky: I don't care if this code fails, it just means it wasn't a username error try {