Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Commit 4eaef04

Browse files
authored
Merge pull request #15 from LemmeCry/member-avatar
adding guild member avatar
2 parents 740dd60 + 438a1c5 commit 4eaef04

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

endpoints.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var (
3535
EndpointCDN string
3636
EndpointCDNAttachments string
3737
EndpointCDNAvatars string
38+
EndpointCDNGuilds string
3839
EndpointCDNIcons string
3940
EndpointCDNSplashes string
4041
EndpointCDNChannelIcons string
@@ -72,12 +73,14 @@ var (
7273
EndpointUserConnections = func(uID string) string { return "" }
7374
EndpointUserNotes = func(uID int64) string { return "" }
7475

75-
EndpointGuild = func(gID int64) string { return "" }
76-
EndpointGuildChannels = func(gID int64) string { return "" }
77-
EndpointGuildMembers = func(gID int64) string { return "" }
78-
EndpointGuildMember = func(gID int64, uID int64) string { return "" }
79-
EndpointGuildMemberMe = func(gID int64) string { return "" }
80-
EndpointGuildMemberRole = func(gID, uID, rID int64) string {
76+
EndpointGuild = func(gID int64) string { return "" }
77+
EndpointGuildChannels = func(gID int64) string { return "" }
78+
EndpointGuildMembers = func(gID int64) string { return "" }
79+
EndpointGuildMember = func(gID int64, uID int64) string { return "" }
80+
EndpointGuildMemberAvatar = func(gID, uID int64, aID string) string { return "" }
81+
EndpointGuildMemberAvatarAnimated = func(gID, uID int64, aID string) string { return "" }
82+
EndpointGuildMemberMe = func(gID int64) string { return "" }
83+
EndpointGuildMemberRole = func(gID, uID, rID int64) string {
8184
return ""
8285
}
8386
EndpointGuildBans = func(gID int64) string { return "" }
@@ -201,6 +204,7 @@ func CreateEndpoints(base string) {
201204
EndpointCDN = "https://cdn.discordapp.com/"
202205
EndpointCDNAttachments = EndpointCDN + "attachments/"
203206
EndpointCDNAvatars = EndpointCDN + "avatars/"
207+
EndpointCDNGuilds = EndpointCDN + "guilds/"
204208
EndpointCDNIcons = EndpointCDN + "icons/"
205209
EndpointCDNSplashes = EndpointCDN + "splashes/"
206210
EndpointCDNChannelIcons = EndpointCDN + "channel-icons/"
@@ -242,6 +246,12 @@ func CreateEndpoints(base string) {
242246
EndpointGuildChannels = func(gID int64) string { return EndpointGuilds + StrID(gID) + "/channels" }
243247
EndpointGuildMembers = func(gID int64) string { return EndpointGuilds + StrID(gID) + "/members" }
244248
EndpointGuildMember = func(gID int64, uID int64) string { return EndpointGuilds + StrID(gID) + "/members/" + StrID(uID) }
249+
EndpointGuildMemberAvatar = func(gID int64, uID int64, aID string) string {
250+
return EndpointCDNGuilds + StrID(gID) + "/users/" + StrID(uID) + "/avatars/" + aID + ".png"
251+
}
252+
EndpointGuildMemberAvatarAnimated = func(gID int64, uID int64, aID string) string {
253+
return EndpointCDNGuilds + StrID(gID) + "/users/" + StrID(uID) + "/avatars/" + aID + ".gif"
254+
}
245255
EndpointGuildMemberMe = func(gID int64) string { return EndpointGuilds + StrID(gID) + "/members/@me" }
246256
EndpointGuildMemberRole = func(gID, uID, rID int64) string {
247257
return EndpointGuilds + StrID(gID) + "/members/" + StrID(uID) + "/roles/" + StrID(rID)

structs.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"fmt"
1717
"net/http"
1818
"strconv"
19+
"strings"
1920
"sync"
2021
"time"
2122

@@ -749,6 +750,9 @@ type Member struct {
749750
// The nickname of the member, if they have one.
750751
Nick string `json:"nick"`
751752

753+
// The guild avatar hash of the member, if they have one.
754+
Avatar string `json:"avatar"`
755+
752756
// Whether the member is deafened at a guild level.
753757
Deaf bool `json:"deaf"`
754758

@@ -766,6 +770,24 @@ func (m *Member) GetGuildID() int64 {
766770
return m.GuildID
767771
}
768772

773+
func (m *Member) AvatarURL(size string) string {
774+
var URL string
775+
u := m.User
776+
777+
if m.Avatar == "" {
778+
return URL
779+
} else if strings.HasPrefix(m.Avatar, "a_") {
780+
URL = EndpointGuildMemberAvatarAnimated(m.GuildID, u.ID, m.Avatar)
781+
} else {
782+
URL = EndpointGuildMemberAvatar(m.GuildID, u.ID, m.Avatar)
783+
}
784+
785+
if size != "" {
786+
return URL + "?size=" + size
787+
}
788+
return URL
789+
}
790+
769791
// A Settings stores data for a specific users Discord client settings.
770792
type Settings struct {
771793
RenderEmbeds bool `json:"render_embeds"`

0 commit comments

Comments
 (0)