Ejemplo n.º 1
0
        /// <summary>
        /// return the avatar Image of the player
        /// by the format.
        /// if the format was not described, this
        /// method will return null,
        /// so be carefull.
        /// </summary>
        /// <param name="format">
        /// The format of the image of this avatar.
        /// <code>---------------------</code>
        /// NOTICE: by Avatar format, I don't mean
        /// Image format(Like png or jpg or ...),
        /// I mean the format of the avatar itself that you want to
        /// get the image of it,
        /// for example <see cref="AvatarFormat.Format01"/>
        /// should be used in <see cref="GameControls.ThroneLabel"/>
        /// for getting the Avatar of the royal memebers.
        /// </param>
        /// <returns></returns>
        public Image GetImage(AvatarFormat format, AvatarFrame frame = null)
        {
            Image myImage = null;

            switch (format)
            {
            case AvatarFormat.Format01:
            case AvatarFormat.Format02:
            case AvatarFormat.Format03:
                myImage = Image.FromFile(ThereIsConstants.Path.Datas_Path +
                                         ThereIsConstants.Path.DoubleSlash +
                                         MyRes.GetString(AvatarFullName));
                break;

            default:
                // ?:|
                break;
            }
            return(myImage);
        }
Ejemplo n.º 2
0
        /// <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));
        }
Ejemplo n.º 3
0
 /// <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());
 }