|
1 | 1 | import aiohttp |
2 | | -import brawlstats |
3 | 2 |
|
4 | 3 | from core.utils import Oauth2 |
5 | | -from sanic import Blueprint |
| 4 | +from sanic import Blueprint, Sanic |
6 | 5 |
|
7 | 6 | listeners = Blueprint('listeners') |
8 | 7 |
|
9 | 8 | @listeners.listener('before_server_start') |
10 | | -async def init(app, loop): |
11 | | - app.session = aiohttp.ClientSession(loop=loop) |
12 | | - app.brawl_client = brawlstats.Client( |
13 | | - token=app.config.BRAWLSTATS_TOKEN, |
14 | | - session=app.session, |
15 | | - is_async=True |
16 | | - ) |
17 | | - app.oauth = Oauth2( |
18 | | - app.config.DISCORD_CLIENT_ID, |
19 | | - app.config.DISCORD_CLIENT_SECRET, |
| 9 | +async def init(app: Sanic, loop): |
| 10 | + app.ctx.aiohttp = aiohttp.ClientSession(loop=loop) |
| 11 | + app.ctx.oauth = Oauth2( |
| 12 | + client_id=app.config.DISCORD_CLIENT_ID, |
| 13 | + client_secret=app.config.DISCORD_CLIENT_SECRET, |
20 | 14 | scope='identify', |
21 | 15 | redirect_uri=f"http{'s' if not app.config.DEV else ''}://{app.config.DOMAIN}/callback", |
22 | | - session=app.session |
| 16 | + session=app.ctx.aiohttp |
23 | 17 | ) |
24 | 18 |
|
25 | 19 | @listeners.listener('after_server_stop') |
26 | | -async def close_session(app, loop): |
27 | | - await app.session.close() |
| 20 | +async def close_session(app: Sanic, loop): |
| 21 | + await app.ctx.aiohttp.close() |
0 commit comments