Skip to content

Commit

Permalink
fix: Fixes #479
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Aug 27, 2024
1 parent 15a1a36 commit 3c7280c
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions DisCatSharp/Entities/Guild/DiscordGuildPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Globalization;

using DisCatSharp.Attributes;
using DisCatSharp.Enums;
using DisCatSharp.Net;
using DisCatSharp.Net.Serialization;
Expand All @@ -16,11 +17,17 @@ namespace DisCatSharp.Entities;
/// </summary>
public class DiscordGuildPreview : SnowflakeObject
{
/// <summary>
/// Gets the emojis.
/// </summary>
[JsonProperty("emojis", NullValueHandling = NullValueHandling.Ignore), JsonConverter(typeof(SnowflakeArrayAsDictionaryJsonConverter))]
internal ConcurrentDictionary<ulong, DiscordEmoji> EmojisInternal;
internal ConcurrentDictionary<ulong, DiscordEmoji> EmojisInternal = [];

/// <summary>
/// Gets the stickers.
/// </summary>
[JsonProperty("stickers", NullValueHandling = NullValueHandling.Ignore), JsonConverter(typeof(SnowflakeArrayAsDictionaryJsonConverter))]
internal ConcurrentDictionary<ulong, DiscordSticker> StickersInternal;
internal ConcurrentDictionary<ulong, DiscordSticker> StickersInternal = [];

/// <summary>
/// Initializes a new instance of the <see cref="DiscordGuildPreview" /> class.
Expand All @@ -38,41 +45,54 @@ internal DiscordGuildPreview()
/// Gets the guild icon's hash.
/// </summary>
[JsonProperty("icon", NullValueHandling = NullValueHandling.Ignore)]
public string IconHash { get; internal set; }
public string? IconHash { get; internal set; }

/// <summary>
/// Gets the guild icon's url.
/// </summary>
[JsonIgnore]
public string IconUrl
public string? IconUrl
=> !string.IsNullOrWhiteSpace(this.IconHash) ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.ICONS}/{this.Id.ToString(CultureInfo.InvariantCulture)}/{this.IconHash}.{(this.IconHash.StartsWith("a_", StringComparison.Ordinal) ? "gif" : "png")}?size=1024" : null;

/// <summary>
/// Gets the guild splash's hash.
/// </summary>
[JsonProperty("splash", NullValueHandling = NullValueHandling.Ignore)]
public string SplashHash { get; internal set; }
public string? SplashHash { get; internal set; }

/// <summary>
/// Gets the guild splash's url.
/// </summary>
[JsonIgnore]
public string SplashUrl
public string? SplashUrl
=> !string.IsNullOrWhiteSpace(this.SplashHash) ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.SPLASHES}/{this.Id.ToString(CultureInfo.InvariantCulture)}/{this.SplashHash}.png?size=1024" : null;

/// <summary>
/// Gets the guild discovery splash's hash.
/// </summary>
[JsonProperty("discovery_splash", NullValueHandling = NullValueHandling.Ignore)]
public string DiscoverySplashHash { get; internal set; }
public string? DiscoverySplashHash { get; internal set; }

/// <summary>
/// Gets the guild discovery splash's url.
/// </summary>
[JsonIgnore]
public string DiscoverySplashUrl
public string? DiscoverySplashUrl
=> !string.IsNullOrWhiteSpace(this.DiscoverySplashHash) ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.GUILD_DISCOVERY_SPLASHES}/{this.Id.ToString(CultureInfo.InvariantCulture)}/{this.DiscoverySplashHash}.png?size=1024" : null;

/// <summary>
/// Gets the guild home header's hash.
/// </summary>
[JsonProperty("home_header", NullValueHandling = NullValueHandling.Ignore)]
public string? HomeHeaderHash { get; internal set; }

/// <summary>
/// Gets the guild home header's url.
/// </summary>
[JsonIgnore, RequiresFeature(Attributes.Features.Onboarding, "Requires to have guide enabled.")]
public string? HomeHeaderUrl
=> !string.IsNullOrWhiteSpace(this.HomeHeaderHash) ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.GUILD_HOME_HEADERS}/{this.Id.ToString(CultureInfo.InvariantCulture)}/{this.HomeHeaderHash}.jpg?size=1280" : null;

/// <summary>
/// Gets a collection of this guild's emojis.
/// </summary>
Expand All @@ -89,7 +109,7 @@ public string DiscoverySplashUrl
/// Gets a collection of this guild's features.
/// </summary>
[JsonProperty("features", NullValueHandling = NullValueHandling.Ignore)]
public IReadOnlyList<string> Features { get; internal set; }
public IReadOnlyList<string> Features { get; internal set; } = [];

/// <summary>
/// Gets the approximate member count.
Expand All @@ -107,7 +127,7 @@ public string DiscoverySplashUrl
/// Gets the description for the guild, if the guild is discoverable.
/// </summary>
[JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)]
public string Description { get; internal set; }
public string? Description { get; internal set; }

/// <summary>
/// Gets the system channel flags for the guild.
Expand Down

0 comments on commit 3c7280c

Please sign in to comment.