/// <summary> /// Returns the file extension of the specified format. /// </summary> /// <param name="format">The format to get the extention off</param> /// <returns>Returns a period prefixed file extension.</returns> public string GetAvatarExtension(AvatarFormat format) { return("." + format.ToString().ToLowerInvariant()); }
/// <summary> /// Gets a URL that can be used to download the user's avatar. If the user has not yet set their avatar, it will return the default one that discord is using. The default avatar only supports the <see cref="AvatarFormat.PNG"/> format. /// </summary> /// <param name="format">The format of the target avatar</param> /// <param name="size">The optional size of the avatar you wish for. Defaults to x128.</param> /// <returns></returns> public string GetAvatarURL(AvatarFormat format, AvatarSize size = AvatarSize.x128) { //Prepare the endpoint string endpoint = "/avatars/" + ID + "/" + Avatar; //The user has no avatar, so we better replace it with the default if (string.IsNullOrEmpty(Avatar)) { //Make sure we are only using PNG if (format != AvatarFormat.PNG) { throw new BadImageFormatException("The user has no avatar and the requested format " + format.ToString() + " is not supported. (Only supports PNG)."); } //Get the endpoint int descrim = Discriminator % 5; endpoint = "/embed/avatars/" + descrim; } //Finish of the endpoint return(string.Format("https://{0}{1}{2}?size={3}", this.CdnEndpoint, endpoint, GetAvatarExtension(format), (int)size)); }