diff --git a/.gitignore b/.gitignore index 9bc880f..ca6b7de 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ key /venv/* /app/__pycache__/* /__pycache__/* +app/static/token.dat diff --git a/app/routes.py b/app/routes.py index 7ad4ab7..b1cc88e 100644 --- a/app/routes.py +++ b/app/routes.py @@ -18,6 +18,7 @@ import faker import json import pprint import os +import sys print = pprint.PrettyPrinter().pprint fake = faker.Faker() @@ -37,6 +38,23 @@ def modpacks(): def favicon(): return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico', mimetype='image/vnd.microsoft.icon') +@app.route('/avatar/') +@app.route('/avatar//') +@app.route('/avatar/') +def getAvatar(id=''): + # Constants + token = open(os.path.join(sys.path[0], 'app', 'static', 'token.dat'), 'r').read() + headers = {'Authorization' : f'Bot {token}'} + api = "https://discordapp.com/api/v6/users/{}" + cdn = "https://cdn.discordapp.com/avatars/{}/{}.png" + # Get User Data which contains Avatar Hash + response = requests.get(api.format(id), headers=headers) + if response.status_code != 200: + return response.text + user = json.loads(response.text) + url = cdn.format(id, user['avatar']) + return "".format(url) + @app.errorhandler(401) def unauthorized(e): return redirect(url_for('login'))