Handle null avatar URLs

This commit is contained in:
Ske 2021-08-02 12:20:53 +02:00
parent 1290594211
commit eb142a81fa

View File

@ -55,7 +55,9 @@ namespace PluralKit.Bot {
// which in turn makes it more likely to be underneath the size limit! // which in turn makes it more likely to be underneath the size limit!
private static readonly Regex DiscordCdnUrl = new Regex(@"^https?://(?:cdn\.discordapp\.com|media\.discordapp\.net)/attachments/(\d{17,19})/(\d{17,19})/([^/\\&\?]+)\.(png|jpg|jpeg|webp)(\?.*)?$"); private static readonly Regex DiscordCdnUrl = new Regex(@"^https?://(?:cdn\.discordapp\.com|media\.discordapp\.net)/attachments/(\d{17,19})/(\d{17,19})/([^/\\&\?]+)\.(png|jpg|jpeg|webp)(\?.*)?$");
private static readonly string DiscordMediaUrlReplacement = "https://media.discordapp.net/attachments/$1/$2/$3.$4?width=256&height=256"; private static readonly string DiscordMediaUrlReplacement = "https://media.discordapp.net/attachments/$1/$2/$3.$4?width=256&height=256";
public static string TryRewriteCdnUrl(string url) => public static string? TryRewriteCdnUrl(string? url)
DiscordCdnUrl.Replace(url, DiscordMediaUrlReplacement); {
return url == null ? null : DiscordCdnUrl.Replace(url, DiscordMediaUrlReplacement);
}
} }
} }