diff --git a/webapp/titanembeds/blueprints/user/user.py b/webapp/titanembeds/blueprints/user/user.py index 89df165..66eaee4 100644 --- a/webapp/titanembeds/blueprints/user/user.py +++ b/webapp/titanembeds/blueprints/user/user.py @@ -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 diff --git a/webapp/titanembeds/oauth.py b/webapp/titanembeds/oauth.py index de5d58f..a3c3d19 100644 --- a/webapp/titanembeds/oauth.py +++ b/webapp/titanembeds/oauth.py @@ -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): - return avatar_base_url + str(id) + '/' + str(av) + '.jpg' +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"