From e54bcc312af7818fda8373b091cd9564c9fe2a68 Mon Sep 17 00:00:00 2001 From: Luna Mendes Date: Tue, 13 Nov 2018 17:33:28 -0300 Subject: [PATCH] blueprints: add icons blueprint - Pipfile: add pillow --- Pipfile | 1 + Pipfile.lock | 38 ++++++++++++++++++++++++++++++++- litecord/blueprints/__init__.py | 3 ++- litecord/blueprints/icons.py | 35 ++++++++++++++++++++++++++++++ litecord/images.py | 6 ++++++ run.py | 12 +++++++---- 6 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 litecord/blueprints/icons.py create mode 100644 litecord/images.py diff --git a/Pipfile b/Pipfile index ef0a342..c55dcaf 100644 --- a/Pipfile +++ b/Pipfile @@ -12,6 +12,7 @@ Earl-ETF = "==2.1.2" logbook = "==1.4.0" Cerberus = "==1.2" quart = {editable = true, ref = "e23714d5", git = "https://gitlab.com/pgjones/quart"} +pillow = "*" [dev-packages] pytest = "==3.10.1" diff --git a/Pipfile.lock b/Pipfile.lock index e514f95..17f4f66 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "58f2b37ff181f4deadceb9cee85bff244bb9702b24bbca31c9f5471b7c959663" + "sha256": "277049fb25e5f182fc611cc27c1d07792cea31f137375bd48f654ddb94d2eb62" }, "pipfile-spec": 6, "requires": { @@ -282,6 +282,42 @@ ], "version": "==4.4.2" }, + "pillow": { + "hashes": [ + "sha256:00203f406818c3f45d47bb8fe7e67d3feddb8dcbbd45a289a1de7dd789226360", + "sha256:0616f800f348664e694dddb0b0c88d26761dd5e9f34e1ed7b7a7d2da14b40cb7", + "sha256:1f7908aab90c92ad85af9d2fec5fc79456a89b3adcc26314d2cde0e238bd789e", + "sha256:2ea3517cd5779843de8a759c2349a3cd8d3893e03ab47053b66d5ec6f8bc4f93", + "sha256:48a9f0538c91fc136b3a576bee0e7cd174773dc9920b310c21dcb5519722e82c", + "sha256:5280ebc42641a1283b7b1f2c20e5b936692198b9dd9995527c18b794850be1a8", + "sha256:5e34e4b5764af65551647f5cc67cf5198c1d05621781d5173b342e5e55bf023b", + "sha256:63b120421ab85cad909792583f83b6ca3584610c2fe70751e23f606a3c2e87f0", + "sha256:696b5e0109fe368d0057f484e2e91717b49a03f1e310f857f133a4acec9f91dd", + "sha256:870ed021a42b1b02b5fe4a739ea735f671a84128c0a666c705db2cb9abd528eb", + "sha256:916da1c19e4012d06a372127d7140dae894806fad67ef44330e5600d77833581", + "sha256:9303a289fa0811e1c6abd9ddebfc770556d7c3311cb2b32eff72164ddc49bc64", + "sha256:9577888ecc0ad7d06c3746afaba339c94d62b59da16f7a5d1cff9e491f23dace", + "sha256:987e1c94a33c93d9b209315bfda9faa54b8edfce6438a1e93ae866ba20de5956", + "sha256:99a3bbdbb844f4fb5d6dd59fac836a40749781c1fa63c563bc216c27aef63f60", + "sha256:99db8dc3097ceafbcff9cb2bff384b974795edeb11d167d391a02c7bfeeb6e16", + "sha256:a5a96cf49eb580756a44ecf12949e52f211e20bffbf5a95760ac14b1e499cd37", + "sha256:aa6ca3eb56704cdc0d876fc6047ffd5ee960caad52452fbee0f99908a141a0ae", + "sha256:aade5e66795c94e4a2b2624affeea8979648d1b0ae3fcee17e74e2c647fc4a8a", + "sha256:b78905860336c1d292409e3df6ad39cc1f1c7f0964e66844bbc2ebfca434d073", + "sha256:b92f521cdc4e4a3041cc343625b699f20b0b5f976793fb45681aac1efda565f8", + "sha256:bfde84bbd6ae5f782206d454b67b7ee8f7f818c29b99fd02bf022fd33bab14cb", + "sha256:c2b62d3df80e694c0e4a0ed47754c9480521e25642251b3ab1dff050a4e60409", + "sha256:c5e2be6c263b64f6f7656e23e18a4a9980cffc671442795682e8c4e4f815dd9f", + "sha256:c99aa3c63104e0818ec566f8ff3942fb7c7a8f35f9912cb63fd8e12318b214b2", + "sha256:dae06620d3978da346375ebf88b9e2dd7d151335ba668c995aea9ed07af7add4", + "sha256:db5499d0710823fa4fb88206050d46544e8f0e0136a9a5f5570b026584c8fd74", + "sha256:f36baafd82119c4a114b9518202f2a983819101dcc14b26e43fc12cbefdce00e", + "sha256:f52b79c8796d81391ab295b04e520bda6feed54d54931708872e8f9ae9db0ea1", + "sha256:ff8cff01582fa1a7e533cb97f628531c4014af4b5f38e33cdcfe5eec29b6d888" + ], + "index": "pypi", + "version": "==5.3.0" + }, "pycparser": { "hashes": [ "sha256:a988718abfad80b6b157acce7bf130a30876d27603738ac39f140993246b25b3" diff --git a/litecord/blueprints/__init__.py b/litecord/blueprints/__init__.py index e43269a..831e2fe 100644 --- a/litecord/blueprints/__init__.py +++ b/litecord/blueprints/__init__.py @@ -9,7 +9,8 @@ from .voice import bp as voice from .invites import bp as invites from .relationships import bp as relationships from .dms import bp as dms +from .icons import bp as icons __all__ = ['gateway', 'auth', 'users', 'guilds', 'channels', 'webhooks', 'science', 'voice', 'invites', 'relationships', - 'dms'] + 'dms', 'icons'] diff --git a/litecord/blueprints/icons.py b/litecord/blueprints/icons.py new file mode 100644 index 0000000..cd09540 --- /dev/null +++ b/litecord/blueprints/icons.py @@ -0,0 +1,35 @@ +from quart import Blueprint, current_app as app, send_file + +bp = Blueprint('images', __name__) + + +@bp.route('/emojis/.', methods=['GET']) +async def get_raw_emoji(emoji_id: int, ext: str): + # emoji = app.icons.get_emoji(emoji_id, ext=ext) + # just a test file for now + return await send_file('./LICENSE') + + +@bp.route('/icons//.', methods=['GET']) +async def get_guild_icon(guild_id: int, icon_hash: str, ext: str): + pass + + +@bp.route('/splashes//.', methods=['GET']) +async def get_guild_splash(guild_id: int, splash_hash: str, ext: str): + pass + + +@bp.route('/embed/avatars/.png') +async def get_default_user_avatar(discrim: int): + pass + + +@bp.route('/avatars//.') +async def get_user_avatar(user_id, avatar_hash, ext): + pass + + +# @bp.route('/app-icons//.') +async def get_app_icon(application_id, icon_hash, ext): + pass diff --git a/litecord/images.py b/litecord/images.py new file mode 100644 index 0000000..c4d0978 --- /dev/null +++ b/litecord/images.py @@ -0,0 +1,6 @@ + +MIMES = { + } + +class IconManager: + """Main icon manager.""" diff --git a/run.py b/run.py index d3034d4..8699cf4 100644 --- a/run.py +++ b/run.py @@ -14,7 +14,7 @@ import config from litecord.blueprints import ( gateway, auth, users, guilds, channels, webhooks, science, - voice, invites, relationships, dms + voice, invites, relationships, dms, icons ) # those blueprints are separated from the "main" ones @@ -85,12 +85,14 @@ def set_blueprints(app_): science: None, voice: '/voice', invites: None, - dms: '/users' + dms: '/users', + + icons: -1, } for bp, suffix in bps.items(): - suffix = suffix or '' - app_.register_blueprint(bp, url_prefix=f'/api/v6{suffix}') + url_prefix = f'/api/v6/{suffix or ""}' if suffix != -1 else '' + app_.register_blueprint(bp, url_prefix=url_prefix) app = make_app() @@ -99,6 +101,8 @@ set_blueprints(app) @app.before_request async def app_before_request(): + """Functions to call before the request actually + takes place.""" await ratelimit_handler()