From 138e18cb7a2511701c8c2b5a47bba729eebc5b0f Mon Sep 17 00:00:00 2001 From: Mihail Gribkov <61027276+Misha-133@users.noreply.github.com> Date: Thu, 11 Jan 2024 22:29:07 +0300 Subject: [PATCH] [Fix] `GetEventCoverImageUrl` throwing NRE in case event cover image is null (#2818) * return null instead of throwing NRE * fix xmldoc --- src/Discord.Net.Core/CDN.cs | 6 ++++-- src/Discord.Net.Rest/Entities/Guilds/RestGuildEvent.cs | 2 +- .../Entities/Guilds/SocketGuildEvent.cs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net.Core/CDN.cs b/src/Discord.Net.Core/CDN.cs index ecce668f..a41eda35 100644 --- a/src/Discord.Net.Core/CDN.cs +++ b/src/Discord.Net.Core/CDN.cs @@ -223,7 +223,7 @@ namespace Discord => $"{DiscordConfig.CDNUrl}stickers/{stickerId}.{FormatToExtension(format)}"; /// - /// Returns an events cover image url. + /// Returns an events cover image url. if the assetId . /// /// The guild id that the event is in. /// The id of the event. @@ -232,7 +232,9 @@ namespace Discord /// The size of the image. /// public static string GetEventCoverImageUrl(ulong guildId, ulong eventId, string assetId, ImageFormat format = ImageFormat.Auto, ushort size = 1024) - => $"{DiscordConfig.CDNUrl}guild-events/{eventId}/{assetId}.{FormatToExtension(format, assetId)}?size={size}"; + => string.IsNullOrEmpty(assetId) + ? null + : $"{DiscordConfig.CDNUrl}guild-events/{eventId}/{assetId}.{FormatToExtension(format, assetId)}?size={size}"; private static string FormatToExtension(StickerFormatType format) { diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuildEvent.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuildEvent.cs index ee1b14d7..59791984 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuildEvent.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuildEvent.cs @@ -110,7 +110,7 @@ namespace Discord.Rest /// public string GetCoverImageUrl(ImageFormat format = ImageFormat.Auto, ushort size = 1024) - => CDN.GetEventCoverImageUrl(Guild.Id, Id, CoverImageId, format, size); + => CDN.GetEventCoverImageUrl(GuildId, Id, CoverImageId, format, size); /// public Task StartAsync(RequestOptions options = null) diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuildEvent.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuildEvent.cs index cb0ef05d..07ec839c 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuildEvent.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuildEvent.cs @@ -121,7 +121,7 @@ namespace Discord.WebSocket /// public string GetCoverImageUrl(ImageFormat format = ImageFormat.Auto, ushort size = 1024) - => CDN.GetEventCoverImageUrl(Guild.Id, Id, CoverImageId, format, size); + => CDN.GetEventCoverImageUrl(GuildId, Id, CoverImageId, format, size); /// public Task DeleteAsync(RequestOptions options = null)