fix(bot): remove query params from image attachment URLs for now

Discord is adding authentication parameters to CDN URLs - these being
present in stored URLs breaks when they expire, but CDN URLs still work
without those parameters until November/December 2023
This commit is contained in:
Iris System 2023-10-02 10:48:13 +13:00
parent 1777070694
commit 8cf50a7d97

View file

@ -33,8 +33,11 @@ public static class ContextAvatarExt
// If we have an attachment, use that
if (ctx.Message.Attachments.FirstOrDefault() is { } attachment)
{
var url = attachment.ProxyUrl;
return new ParsedImage { Url = url, Source = AvatarSource.Attachment };
// XXX: strip query params from attachment URLs because of new Discord CDN shenanigans
var uriBuilder = new UriBuilder(attachment.ProxyUrl);
uriBuilder.Query = "";
return new ParsedImage { Url = uriBuilder.Uri.AbsoluteUri, Source = AvatarSource.Attachment };
}
// We should only get here if there are no arguments (which would get parsed as URL + throw if error)