Browse Source

Add DisplayAvatar to IGuildUser (#2115)

tags/3.3.2
Armano den Boef GitHub 3 years ago
parent
commit
1ffe9eeca9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 3 deletions
  1. +24
    -3
      src/Discord.Net.Core/Entities/Users/IGuildUser.cs
  2. +9
    -0
      src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs
  3. +4
    -0
      src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs
  4. +10
    -0
      src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs
  5. +7
    -0
      src/Discord.Net.WebSocket/Entities/Users/SocketThreadUser.cs
  6. +4
    -0
      src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs

+ 24
- 3
src/Discord.Net.Core/Entities/Users/IGuildUser.cs View File

@@ -32,7 +32,15 @@ namespace Discord
/// </returns>
string Nickname { get; }
/// <summary>
/// Gets the guild specific avatar for this users.
/// Gets the displayed avatar for this user.
/// </summary>
/// <returns>
/// The users displayed avatar hash. If the user does not have a guild avatar, this will be the regular avatar.
/// If the user also does not have a regular avatar, this will be <see langword="null"/>.
/// </returns>
string DisplayAvatarId { get; }
/// <summary>
/// Gets the guild specific avatar for this user.
/// </summary>
/// <returns>
/// The users guild avatar hash if they have one; otherwise <see langword="null"/>.
@@ -126,16 +134,29 @@ namespace Discord
/// </summary>
/// <remarks>
/// This property retrieves a URL for this guild user's guild specific avatar. In event that the user does not have a valid guild avatar
/// (i.e. their avatar identifier is not set), this method will return <c>null</c>.
/// (i.e. their avatar identifier is not set), this method will return <see langword="null"/>.
/// </remarks>
/// <param name="format">The format to return.</param>
/// <param name="size">The size of the image to return in. This can be any power of two between 16 and 2048.
/// </param>
/// <returns>
/// A string representing the user's avatar URL; <c>null</c> if the user does not have an avatar in place.
/// A string representing the user's avatar URL; <see langword="null"/> if the user does not have an avatar in place.
/// </returns>
string GetGuildAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128);
/// <summary>
/// Gets the display avatar URL for this user.
/// </summary>
/// <remarks>
/// This property retrieves an URL for this guild user's displayed avatar.
/// If the user does not have a guild avatar, this will be the user's regular avatar.
/// </remarks>
/// <param name="format">The format to return.</param>
/// <param name="size">The size of the image to return in. This can be any power of two between 16 and 2048.
/// <returns>
/// A string representing the URL of the displayed avatar for this user. <see langword="null"/> if the user does not have an avatar in place.
/// </returns>
string GetDisplayAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128);
/// <summary>
/// Kicks this user from this guild.
/// </summary>
/// <param name="reason">The reason for the kick which will be recorded in the audit log.</param>


+ 9
- 0
src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs View File

@@ -24,6 +24,8 @@ namespace Discord.Rest
/// <inheritdoc />
public string Nickname { get; private set; }
/// <inheritdoc/>
public string DisplayAvatarId => GuildAvatarId ?? AvatarId;
/// <inheritdoc/>
public string GuildAvatarId { get; private set; }
internal IGuild Guild { get; private set; }
/// <inheritdoc />
@@ -183,6 +185,13 @@ namespace Discord.Rest
return new ChannelPermissions(Permissions.ResolveChannel(Guild, this, channel, guildPerms.RawValue));
}

/// <inheritdoc />
public string GetDisplayAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> GuildAvatarId is not null
? GetGuildAvatarUrl(format, size)
: GetAvatarUrl(format, size);

/// <inheritdoc />
public string GetGuildAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> CDN.GetGuildUserAvatarUrl(Id, GuildId, GuildAvatarId, size, format);
#endregion


+ 4
- 0
src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs View File

@@ -55,9 +55,13 @@ namespace Discord.Rest
string IGuildUser.DisplayName => null;
/// <inheritdoc />
string IGuildUser.Nickname => null;
/// <inheritdoc/>
string IGuildUser.DisplayAvatarId => null;
/// <inheritdoc />
string IGuildUser.GuildAvatarId => null;
/// <inheritdoc />
string IGuildUser.GetDisplayAvatarUrl(ImageFormat format, ushort size) => null;
/// <inheritdoc />
string IGuildUser.GetGuildAvatarUrl(ImageFormat format, ushort size) => null;
/// <inheritdoc />
bool? IGuildUser.IsPending => null;


+ 10
- 0
src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs View File

@@ -34,6 +34,8 @@ namespace Discord.WebSocket
/// <inheritdoc />
public string Nickname { get; private set; }
/// <inheritdoc/>
public string DisplayAvatarId => GuildAvatarId ?? AvatarId;
/// <inheritdoc/>
public string GuildAvatarId { get; private set; }
/// <inheritdoc />
public override bool IsBot { get { return GlobalUser.IsBot; } internal set { GlobalUser.IsBot = value; } }
@@ -246,6 +248,14 @@ namespace Discord.WebSocket
/// <inheritdoc />
public ChannelPermissions GetPermissions(IGuildChannel channel)
=> new ChannelPermissions(Permissions.ResolveChannel(Guild, this, channel, GuildPermissions.RawValue));

/// <inheritdoc />
public string GetDisplayAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> GuildAvatarId is not null
? GetGuildAvatarUrl(format, size)
: GetAvatarUrl(format, size);

/// <inheritdoc />
public string GetGuildAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> CDN.GetGuildUserAvatarUrl(Id, Guild.Id, GuildAvatarId, size, format);



+ 7
- 0
src/Discord.Net.WebSocket/Entities/Users/SocketThreadUser.cs View File

@@ -58,6 +58,9 @@ namespace Discord.WebSocket
get => GuildUser.AvatarId;
internal set => GuildUser.AvatarId = value;
}
/// <inheritdoc/>
public string DisplayAvatarId => GuildAvatarId ?? AvatarId;

/// <inheritdoc/>
public string GuildAvatarId
=> GuildUser.GuildAvatarId;
@@ -201,6 +204,10 @@ namespace Discord.WebSocket
/// <inheritdoc/>
IReadOnlyCollection<ulong> IGuildUser.RoleIds => GuildUser.Roles.Select(x => x.Id).ToImmutableArray();

/// <inheritdoc />
string IGuildUser.GetDisplayAvatarUrl(ImageFormat format, ushort size) => GuildUser.GetDisplayAvatarUrl(format, size);

/// <inheritdoc />
string IGuildUser.GetGuildAvatarUrl(ImageFormat format, ushort size) => GuildUser.GetGuildAvatarUrl(format, size);

internal override SocketGlobalUser GlobalUser { get => GuildUser.GlobalUser; set => GuildUser.GlobalUser = value; }


+ 4
- 0
src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs View File

@@ -67,8 +67,12 @@ namespace Discord.WebSocket
/// <inheritdoc />
string IGuildUser.Nickname => null;
/// <inheritdoc />
string IGuildUser.DisplayAvatarId => null;
/// <inheritdoc />
string IGuildUser.GuildAvatarId => null;
/// <inheritdoc />
string IGuildUser.GetDisplayAvatarUrl(ImageFormat format, ushort size) => null;
/// <inheritdoc />
string IGuildUser.GetGuildAvatarUrl(ImageFormat format, ushort size) => null;
/// <inheritdoc />
DateTimeOffset? IGuildUser.PremiumSince => null;


Loading…
Cancel
Save