From 892601110f64cc925e813d4565e893160aacbbc5 Mon Sep 17 00:00:00 2001 From: Ske Date: Tue, 5 May 2020 19:09:18 +0200 Subject: [PATCH] Temporary workaround for https://github.com/DSharpPlus/DSharpPlus/issues/565 --- PluralKit.Bot/Bot.cs | 3 +++ PluralKit.Bot/Services/EmbedService.cs | 9 +++++---- PluralKit.Bot/Utils/DiscordUtils.cs | 6 ++++++ PluralKit.Bot/Utils/MiscUtils.cs | 7 +++++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/PluralKit.Bot/Bot.cs b/PluralKit.Bot/Bot.cs index bf0462cc..ad41ac5e 100644 --- a/PluralKit.Bot/Bot.cs +++ b/PluralKit.Bot/Bot.cs @@ -11,6 +11,7 @@ using Autofac; using DSharpPlus; using DSharpPlus.Entities; using DSharpPlus.EventArgs; +using DSharpPlus.Exceptions; using NodaTime; @@ -122,6 +123,8 @@ namespace PluralKit.Bot { // Make this beforehand so we can access the event ID for logging var sentryEvent = new SentryEvent(exc); + if (exc is BadRequestException bre) + sentryEvent.SetExtra("errors", MiscUtils.ExtractError(bre)); _logger.Error(exc, "Exception in bot event handler (Sentry ID: {SentryEventId})", sentryEvent.EventId); diff --git a/PluralKit.Bot/Services/EmbedService.cs b/PluralKit.Bot/Services/EmbedService.cs index ebea1696..a3f6f2ce 100644 --- a/PluralKit.Bot/Services/EmbedService.cs +++ b/PluralKit.Bot/Services/EmbedService.cs @@ -33,7 +33,7 @@ namespace PluralKit.Bot { var eb = new DiscordEmbedBuilder() .WithColor(DiscordUtils.Gray) .WithTitle(system.Name ?? null) - .WithThumbnailUrl(system.AvatarUrl ?? null) + .WithThumbnailUrl(system.AvatarUrl) .WithFooter($"System ID: {system.Hid} | Created on {DateTimeFormats.ZonedDateTimeFormat.Format(system.Created.InZone(system.Zone))}"); var latestSwitch = await _data.GetLatestSwitch(system); @@ -66,7 +66,8 @@ namespace PluralKit.Bot { // TODO: pronouns in ?-reacted response using this card var timestamp = DiscordUtils.SnowflakeToInstant(messageId); return new DiscordEmbedBuilder() - .WithAuthor($"#{channel.Name}: {member.Name}", iconUrl: member.AvatarUrl) + .WithAuthor($"#{channel.Name}: {member.Name}", iconUrl: DiscordUtils.WorkaroundForUrlBug(member.AvatarUrl)) + .WithThumbnailUrl(member.AvatarUrl) .WithDescription(content?.NormalizeLineEndSpacing()) .WithFooter($"System ID: {system.Hid} | Member ID: {member.Hid} | Sender: {sender.Username}#{sender.Discriminator} ({sender.Id}) | Message ID: {messageId} | Original Message ID: {originalMsgId}") .WithTimestamp(timestamp.ToDateTimeOffset()) @@ -101,7 +102,7 @@ namespace PluralKit.Bot { var eb = new DiscordEmbedBuilder() // TODO: add URL of website when that's up - .WithAuthor(name, avatar) + .WithAuthor(name, iconUrl: DiscordUtils.WorkaroundForUrlBug(avatar)) .WithColor(member.MemberPrivacy.CanAccess(ctx) ? color : DiscordUtils.Gray) .WithFooter($"System ID: {system.Hid} | Member ID: {member.Hid} | Created on {DateTimeFormats.ZonedDateTimeFormat.Format(member.Created.InZone(system.Zone))}"); @@ -167,7 +168,7 @@ namespace PluralKit.Bot { } var eb = new DiscordEmbedBuilder() - .WithAuthor(msg.Member.Name, msg.Member.AvatarUrl) + .WithAuthor(msg.Member.Name, iconUrl: DiscordUtils.WorkaroundForUrlBug(msg.Member.AvatarUrl)) .WithDescription(serverMsg?.Content?.NormalizeLineEndSpacing() ?? "*(message contents deleted or inaccessible)*") .WithImageUrl(serverMsg?.Attachments?.FirstOrDefault()?.Url) .AddField("System", diff --git a/PluralKit.Bot/Utils/DiscordUtils.cs b/PluralKit.Bot/Utils/DiscordUtils.cs index 20fad07d..613d40a3 100644 --- a/PluralKit.Bot/Utils/DiscordUtils.cs +++ b/PluralKit.Bot/Utils/DiscordUtils.cs @@ -84,5 +84,11 @@ namespace PluralKit.Bot await msg.CreateReactionAsync(DiscordEmoji.FromUnicode(reaction)); } } + + public static string WorkaroundForUrlBug(string input) + { + // Workaround for https://github.com/DSharpPlus/DSharpPlus/issues/565 + return input.Replace("%20", "+"); + } } } \ No newline at end of file diff --git a/PluralKit.Bot/Utils/MiscUtils.cs b/PluralKit.Bot/Utils/MiscUtils.cs index d3165f3e..940a68d1 100644 --- a/PluralKit.Bot/Utils/MiscUtils.cs +++ b/PluralKit.Bot/Utils/MiscUtils.cs @@ -3,6 +3,8 @@ using System.Linq; using System.Net.Sockets; using System.Threading.Tasks; +using DSharpPlus.Exceptions; + using Npgsql; using PluralKit.Core; @@ -40,5 +42,10 @@ namespace PluralKit.Bot // This may expanded at some point. return true; } + + public static string ExtractError(BadRequestException e) + { + return e.WebResponse.Response; + } } } \ No newline at end of file