Handle default avatars

This commit is contained in:
Jeremy Zhang 2017-12-09 17:25:03 +00:00
parent 12f2acd0c8
commit cb05b44100
2 changed files with 8 additions and 3 deletions

View File

@ -44,7 +44,7 @@ def callback():
session['user_id'] = user['id']
session['username'] = user['username']
session['discriminator'] = user['discriminator']
session['avatar'] = generate_avatar_url(user['id'], user['avatar'])
session['avatar'] = generate_avatar_url(user['id'], user['avatar'], user['discriminator'])
session["tokens"] = get_titan_token(session["user_id"])
if session["tokens"] == -1:
session["tokens"] = 0

View File

@ -89,8 +89,13 @@ def check_user_permission(guild_id, id):
return user_has_permission(guild['permissions'], id) or guild['owner']
return False
def generate_avatar_url(id, av):
def generate_avatar_url(id, av, discrim="0000"):
if av:
return avatar_base_url + str(id) + '/' + str(av) + '.jpg'
else:
default_av = [0, 1, 2, 3, 4]
discrim = int(discrim)
return "https://cdn.discordapp.com/embed/avatars/{}.png".format(default_av[int(discrim) % len(default_av)])
def generate_guild_icon_url(id, hash):
return guild_icon_url + str(id) + "/" + str(hash) + ".jpg"