Esempio n. 1
0
        /// <summary>
        /// 检查头像是否存在
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="size"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public bool AvatarCheck(int uid, AvatarSize size = AvatarSize.Middle, AvatarType type = AvatarType.Virtual)
        {
            var args = new Dictionary <string, string>
            {
                { "uid", uid.ToString() },
                { "size", size.ToString().ToLower() },
                { "type", type.ToString().ToLower() },
                { "check_file_exists", "1" }
            };

            return(toBool(SendGet(UcConfig.UcApi + "avatar.php", args)));
        }
Esempio n. 2
0
        /// <summary>获取用户头像URL,根据AvatarStatic配置可能是动态或者静态</summary>
        /// <param name="uid"></param>
        /// <param name="avatarSize"></param>
        /// <returns></returns>
        public static String GetAvatarUrl(int uid, AvatarSize avatarSize = AvatarSize.Medium)
        {
            var config = GeneralConfigInfo.Current;

            if (config.AvatarStatic)
            {
                return(GetStaticUrl(uid.ToString(), avatarSize));
            }

            var root = Utils.GetRootUrl(BaseConfigs.GetForumPath);

            if (!config.ImageServer.IsNullOrEmpty())
            {
                root = config.ImageServer.EnsureEnd("/");
            }

            return(String.Format("{0}tools/avatar.aspx?uid={1}&size={2}", root, uid, avatarSize.ToString().ToLower()));
        }
Esempio n. 3
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
            string s = size.ToString().Trim('x');

            return("https://" + CdnEndpoint + endpoint + GetAvatarExtension(format) + "?size=" + s);
        }
Esempio n. 4
0
 /// <summary>
 /// 获取头像物理路径
 /// </summary>
 /// <param name="uid"></param>
 /// <param name="size"></param>
 /// <returns></returns>
 public static string GetPhysicsAvatarPath(string uid, AvatarSize size)
 {
     return Utils.GetMapPath(forumPath + "avatars/" +
         string.Format(AVATAR_URL, uid.Substring(0, 3), uid.Substring(3, 2), uid.Substring(5, 2), uid.Substring(7, 2), size.ToString().ToLower()));
 }
Esempio n. 5
0
 /// <summary>
 /// 获取默认头像
 /// </summary>
 /// <param name="avatarSize"></param>
 /// <returns></returns>
 public static string GetDefaultAvatarUrl(AvatarSize avatarSize)
 {
     return Utils.GetRootUrl(forumPath) + "images/common/noavatar_" + avatarSize.ToString().ToLower() + ".gif";
 }
Esempio n. 6
0
 /// <summary>
 /// 获取默认头像
 /// </summary>
 /// <param name="avatarSize"></param>
 /// <returns></returns>
 public static string GetDefaultAvatarUrl(AvatarSize avatarSize)
 {
     return(Utils.GetRootUrl(forumPath) + "images/common/noavatar_" + avatarSize.ToString().ToLower() + ".gif");
 }
Esempio n. 7
0
 /// <summary>
 /// 获取头像物理路径
 /// </summary>
 /// <param name="uid"></param>
 /// <param name="size"></param>
 /// <returns></returns>
 public static string GetPhysicsAvatarPath(string uid, AvatarSize size)
 {
     return(Utils.GetMapPath(forumPath + "avatars/" +
                             string.Format(AVATAR_URL, uid.Substring(0, 3), uid.Substring(3, 2), uid.Substring(5, 2), uid.Substring(7, 2), size.ToString().ToLower())));
 }
Esempio n. 8
0
 /// <summary>
 /// 得到头像地址
 /// </summary>
 /// <param name="uid">Uid</param>
 /// <param name="size">大小</param>
 /// <param name="type">类型</param>
 /// <returns></returns>
 public string AvatarUrl(int uid, AvatarSize size, AvatarType type = AvatarType.Virtual)
 {
     return(string.Format("{0}avatar.php?uid={1}&type={2}&size={3}", UcConfig.UcApi, uid,
                          type.ToString().ToLower(), size.ToString().ToLower()));
 }
Esempio n. 9
0
 /// <summary>
 /// 检查头像是否存在
 /// </summary>
 /// <param name="uid"></param>
 /// <param name="size"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public bool AvatarCheck(decimal uid, AvatarSize size = AvatarSize.Middle, AvatarType type = AvatarType.Virtual)
 {
     var args = new Dictionary<string, string>
                    {
                        {"uid", uid.ToString()},
                        {"size", size.ToString().ToLower()},
                        {"type", type.ToString().ToLower()},
                        {"check_file_exists", "1"}
                    };
     return toBool(SendGet(UcConfig.UcApi + "avatar.php", args));
 }
Esempio n. 10
0
 /// <summary>
 /// 得到头像地址
 /// </summary>
 /// <param name="uid">Uid</param>
 /// <param name="size">大小</param>
 /// <param name="type">类型</param>
 /// <returns></returns>
 public string AvatarUrl(decimal uid, AvatarSize size, AvatarType type = AvatarType.Virtual)
 {
     return string.Format("{0}avatar.php?uid={1}&type={2}&size={3}", UcConfig.UcApi, uid,
                          type.ToString().ToLower(), size.ToString().ToLower());
 }
Esempio n. 11
0
 static String GetDefault(AvatarSize avatarSize = AvatarSize.Medium)
 {
     return(Utils.GetMapPath(forumPath.CombinePath("avatars/avatar_" + avatarSize.ToString().ToLower() + ".jpg")));
 }
Esempio n. 12
0
 public static String GetPhysicsAvatarPath(String uid, AvatarSize size)
 {
     return(Utils.GetMapPath(forumPath + FormatPathPrefix(uid) + size.ToString().ToLower() + ".jpg"));
 }