Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Methods to obtain a user's avatar URL #388

Merged
merged 3 commits into from
May 30, 2017
Merged

Methods to obtain a user's avatar URL #388

merged 3 commits into from
May 30, 2017

Conversation

Necroforger
Copy link
Contributor

Makes obtaining the avatar URL of a user easier.

user.go Outdated
if strings.HasPrefix(avatarID, "a_") {
extension = ".gif"
}
return EndpointCDNAvatars + userID + "/" + avatarID + extension + "?size=" + size
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I would prefer:

func (u *User) AvatarURL(size string) string {
  var url string
  if strings.HasPrefix(avatarID, "a_) {
    url = EndpointUserAvatarAnimated(userID, avatarID)
  } else {
    url = EndpointUserAvatar(userID, avatarID)
  }
  return url + "?size=" + size
}

We already support EndpointUserAvatar, adding an animated one seems reasonable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the EndpointUserAvatar function requests a png image. Does the file format change to a png when you request it as one?

Copy link
Contributor Author

@Necroforger Necroforger May 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code with the things you suggested, apparently it does return a PNG file.

@iopred iopred merged commit a71f5e3 into bwmarrin:develop May 30, 2017
@bwmarrin bwmarrin added this to the v0.17.0 milestone May 30, 2017
ErikMcClure pushed a commit to ErikMcClure/discordgo that referenced this pull request Aug 4, 2020
* Methods to obtain a user's avatar URL

* Created EndpointUserAvatarAnimated and updated AvatarURL

* Fixed the size parameter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants