Skip to content

Commit

Permalink
bannerz W (#2987)
Browse files Browse the repository at this point in the history
  • Loading branch information
Misha-133 authored Aug 28, 2024
1 parent bc84b94 commit 57eb906
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Discord.Net.Core/CDN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public static string GetGuildUserAvatarUrl(ulong userId, ulong guildId, string a
return $"{DiscordConfig.CDNUrl}guilds/{guildId}/users/{userId}/avatars/{avatarId}.{extension}?size={size}";
}

public static string GetGuildUserBannerUrl(ulong userId, ulong guildId, string bannerId, ushort size, ImageFormat format)
{
if (bannerId == null)
return null;
var extension = FormatToExtension(format, bannerId);
return $"{DiscordConfig.CDNUrl}guilds/{guildId}/users/{userId}/banners/{bannerId}.{extension}?size={size}";
}

/// <summary>
/// Returns a user banner URL.
/// </summary>
Expand Down
21 changes: 21 additions & 0 deletions src/Discord.Net.Core/Entities/Users/IGuildUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,23 @@ public interface IGuildUser : IUser, IVoiceState
/// 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"/>.
/// </returns>
string GuildAvatarId { get; }

/// <summary>
/// Gets the guild specific banner for this user.
/// </summary>
/// <returns>
/// The user's guild banner hash if they have one; otherwise <see langword="null"/>.
/// </returns>
string GuildBannerHash { get; }

/// <summary>
/// Gets the guild-level permissions for this user.
/// </summary>
Expand Down Expand Up @@ -147,6 +157,17 @@ public interface IGuildUser : IUser, IVoiceState
/// A string representing the user's guild-specific avatar URL; <see langword="null"/> if the user has no guild avatar set.
/// </returns>
string GetGuildAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128);

/// <summary>
/// Gets the guild-specific banner URL for this user, if it is set.
/// </summary>
/// <param name="format">The format of the image.</param>
/// <param name="size">The size of the image that matches any power of two, ranging from 16 to 2048.</param>
/// <returns>
/// A string representing the user's guild-specific banner URL; <see langword="null"/> if the user has no guild banner set.
/// </returns>
string GetGuildBannerUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128);

/// <summary>
/// Kicks this user from this guild.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Discord.Net.Rest/API/Common/GuildMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ internal class GuildMember

[JsonProperty("flags")]
public GuildUserFlags Flags { get; set; }

[JsonProperty("banner")]
public Optional<string> Banner { get; set; }
}
}
10 changes: 10 additions & 0 deletions src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public class RestGuildUser : RestUser, IGuildUser
public string DisplayAvatarId => GuildAvatarId ?? AvatarId;
/// <inheritdoc/>
public string GuildAvatarId { get; private set; }

/// <inheritdoc/>
public string GuildBannerHash { get; private set; }

internal IGuild Guild { get; private set; }
/// <inheritdoc />
public bool IsDeafened { get; private set; }
Expand Down Expand Up @@ -122,6 +126,8 @@ internal void Update(Model model)
_timedOutTicks = model.TimedOutUntil.Value?.UtcTicks;
if (model.Pending.IsSpecified)
IsPending = model.Pending.Value;
if (model.Banner.IsSpecified)
GuildBannerHash = model.Banner.Value;
Flags = model.Flags;
}
private void UpdateRoles(ulong[] roleIds)
Expand Down Expand Up @@ -200,6 +206,10 @@ public ChannelPermissions GetPermissions(IGuildChannel channel)
public string GetGuildAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> CDN.GetGuildUserAvatarUrl(Id, GuildId, GuildAvatarId, size, format);

/// <inheritdoc />
public string GetGuildBannerUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> CDN.GetGuildUserBannerUrl(Id, GuildId, GuildBannerHash, size, format);

/// <inheritdoc />
public override string GetDisplayAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> GetGuildAvatarUrl(format, size) ?? base.GetDisplayAvatarUrl(format, size);
Expand Down
4 changes: 4 additions & 0 deletions src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ IGuild IGuildUser.Guild
/// <inheritdoc />
string IGuildUser.GuildAvatarId => null;
/// <inheritdoc />
string IGuildUser.GuildBannerHash => null;
/// <inheritdoc />
string IGuildUser.GetGuildAvatarUrl(ImageFormat format, ushort size) => null;
/// <inheritdoc />
string IGuildUser.GetGuildBannerUrl(ImageFormat format, ushort size) => null;
/// <inheritdoc />
bool? IGuildUser.IsPending => null;
/// <inheritdoc />
int IGuildUser.Hierarchy => 0;
Expand Down
9 changes: 9 additions & 0 deletions src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class SocketGuildUser : SocketUser, IGuildUser
/// <inheritdoc />
public override string GlobalName { get { return GlobalUser.GlobalName; } internal set { GlobalUser.GlobalName = value; } }

/// <inheritdoc/>
public string GuildBannerHash { get; private set; }

/// <inheritdoc />
public GuildPermissions GuildPermissions => new GuildPermissions(Permissions.ResolveGuild(Guild, this));
internal override SocketPresence Presence { get; set; }
Expand Down Expand Up @@ -185,6 +188,8 @@ internal void Update(ClientState state, MemberModel model)
_timedOutTicks = model.TimedOutUntil.Value?.UtcTicks;
if (model.Pending.IsSpecified)
IsPending = model.Pending.Value;
if (model.Banner.IsSpecified)
GuildBannerHash = model.Banner.Value;

Flags = model.Flags;
}
Expand Down Expand Up @@ -263,6 +268,10 @@ public ChannelPermissions GetPermissions(IGuildChannel channel)
public string GetGuildAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> CDN.GetGuildUserAvatarUrl(Id, Guild.Id, GuildAvatarId, size, format);

/// <inheritdoc />
public string GetGuildBannerUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> CDN.GetGuildUserBannerUrl(Id, Guild.Id, GuildBannerHash, size, format);

/// <inheritdoc />
public override string GetDisplayAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> GetGuildAvatarUrl(format, size) ?? base.GetDisplayAvatarUrl(format, size);
Expand Down
7 changes: 7 additions & 0 deletions src/Discord.Net.WebSocket/Entities/Users/SocketThreadUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public override string GlobalName
public string GuildAvatarId
=> GuildUser.GuildAvatarId;

/// <inheritdoc/>
public string GuildBannerHash
=> GuildUser.GuildBannerHash;

/// <inheritdoc/>
public override ushort DiscriminatorValue
{
Expand Down Expand Up @@ -240,6 +244,9 @@ internal void Update(Model model)
/// <inheritdoc />
string IGuildUser.GetGuildAvatarUrl(ImageFormat format, ushort size) => GuildUser.GetGuildAvatarUrl(format, size);

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

/// <inheritdoc />
public override string GetDisplayAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> GuildUser.GetGuildAvatarUrl() ?? base.GetDisplayAvatarUrl(format, size);
Expand Down
4 changes: 4 additions & 0 deletions src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ internal static SocketWebhookUser Create(SocketGuild guild, ClientState state, M
/// <inheritdoc />
string IGuildUser.GuildAvatarId => null;
/// <inheritdoc />
string IGuildUser.GuildBannerHash => null;
/// <inheritdoc />
string IGuildUser.GetGuildAvatarUrl(ImageFormat format, ushort size) => null;
/// <inheritdoc />
string IGuildUser.GetGuildBannerUrl(ImageFormat format, ushort size) => null;
/// <inheritdoc />
DateTimeOffset? IGuildUser.PremiumSince => null;
/// <inheritdoc />
DateTimeOffset? IGuildUser.TimedOutUntil => null;
Expand Down

0 comments on commit 57eb906

Please sign in to comment.