Skip to content

Commit

Permalink
Add Banner to Member (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebm253 authored Jul 20, 2024
1 parent 47c540e commit e70ebbc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions discord/cdn_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
ChannelIcon = NewCDN("/channel-icons/{channel.id}/{channel.icon.hash}", FileFormatPNG, FileFormatJPEG, FileFormatWebP)

MemberAvatar = NewCDN("/guilds/{guild.id}/users/{user.id}/avatars/{member.avatar.hash}", FileFormatPNG, FileFormatJPEG, FileFormatWebP, FileFormatGIF)
MemberBanner = NewCDN("/guilds/{guild.id}/users/{user.id}/banners/{member.avatar.hash}", FileFormatPNG, FileFormatJPEG, FileFormatWebP, FileFormatGIF)

AvatarDecoration = NewCDN("/avatar-decoration-presets/{user.avatar.decoration.hash}", FileFormatPNG)

Expand Down
26 changes: 22 additions & 4 deletions discord/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Member struct {
User User `json:"user"`
Nick *string `json:"nick"`
Avatar *string `json:"avatar"`
Banner *string `json:"banner"`
RoleIDs []snowflake.ID `json:"roles,omitempty"`
JoinedAt time.Time `json:"joined_at"`
PremiumSince *time.Time `json:"premium_since,omitempty"`
Expand Down Expand Up @@ -53,10 +54,7 @@ func (m Member) EffectiveAvatarURL(opts ...CDNOpt) string {
if m.Avatar == nil {
return m.User.EffectiveAvatarURL(opts...)
}
if avatar := m.AvatarURL(opts...); avatar != nil {
return *avatar
}
return ""
return formatAssetURL(MemberAvatar, opts, m.GuildID, m.User.ID, *m.Avatar)
}

// AvatarURL returns the guild-specific avatar URL of the user if set or nil
Expand All @@ -68,6 +66,26 @@ func (m Member) AvatarURL(opts ...CDNOpt) *string {
return &url
}

// EffectiveBannerURL returns the guild-specific banner URL of the user if set, falling back to the banner URL of the user
func (m Member) EffectiveBannerURL(opts ...CDNOpt) string {
if m.Banner == nil {
if banner := m.User.BannerURL(opts...); banner != nil {
return *banner
}
return ""
}
return formatAssetURL(MemberBanner, opts, m.GuildID, m.User.ID, *m.Banner)
}

// BannerURL returns the guild-specific banner URL of the user if set or nil
func (m Member) BannerURL(opts ...CDNOpt) *string {
if m.Banner == nil {
return nil
}
url := formatAssetURL(MemberBanner, opts, m.GuildID, m.User.ID, *m.Banner)
return &url
}

// AvatarDecorationURL returns the avatar decoration URL if set or nil
func (m Member) AvatarDecorationURL(opts ...CDNOpt) *string {
if m.AvatarDecorationData == nil {
Expand Down
5 changes: 1 addition & 4 deletions discord/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ func (u User) EffectiveAvatarURL(opts ...CDNOpt) string {
if u.Avatar == nil {
return u.DefaultAvatarURL(opts...)
}
if avatar := u.AvatarURL(opts...); avatar != nil {
return *avatar
}
return ""
return formatAssetURL(UserAvatar, opts, u.ID, *u.Avatar)
}

// AvatarURL returns the avatar URL of the user if set or nil
Expand Down

0 comments on commit e70ebbc

Please sign in to comment.