mirror of
https://github.com/yawaflua/Flask-Discord.git
synced 2026-02-04 18:24:15 +02:00
Improve the stuffs
This commit is contained in:
@@ -30,7 +30,7 @@ discord = DiscordOAuth2Session(app)
|
|||||||
|
|
||||||
@app.route("/login/")
|
@app.route("/login/")
|
||||||
async def login():
|
async def login():
|
||||||
return discord.create_session()
|
return await discord.create_session()
|
||||||
|
|
||||||
|
|
||||||
@app.route("/callback/")
|
@app.route("/callback/")
|
||||||
@@ -47,7 +47,7 @@ async def redirect_unauthorized(e):
|
|||||||
@app.route("/me/")
|
@app.route("/me/")
|
||||||
@requires_authorization
|
@requires_authorization
|
||||||
async def me():
|
async def me():
|
||||||
user = discord.fetch_user()
|
user = await discord.fetch_user()
|
||||||
return f"""
|
return f"""
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
@@ -68,7 +68,7 @@ For an example to the working application, check [`test_app.py`](tests/test_app.
|
|||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
* Quart
|
* Quart
|
||||||
* requests_oauthlib
|
* Async-OAuthlib
|
||||||
* cachetools
|
* cachetools
|
||||||
* discord.py
|
* discord.py
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ intersphinx_mapping = {
|
|||||||
'discord': ('https://discordpy.readthedocs.io/en/latest/', None),
|
'discord': ('https://discordpy.readthedocs.io/en/latest/', None),
|
||||||
'quart': ('https://pgjones.gitlab.io/quart/', None),
|
'quart': ('https://pgjones.gitlab.io/quart/', None),
|
||||||
'cachetools': ('https://cachetools.readthedocs.io/en/stable/', None),
|
'cachetools': ('https://cachetools.readthedocs.io/en/stable/', None),
|
||||||
'requests_oauthlib': ('https://requests-oauthlib.readthedocs.io/en/latest/', None)
|
'async_oauthlib': ('https://async-oauthlib.readthedocs.io/en/latest/', None)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add any paths that contain templates here, relative to this directory.
|
# Add any paths that contain templates here, relative to this directory.
|
||||||
|
|||||||
@@ -65,25 +65,25 @@ in exchange for fetching user's details and display them on web page.
|
|||||||
|
|
||||||
|
|
||||||
@app.route("/login/")
|
@app.route("/login/")
|
||||||
def login():
|
async def login():
|
||||||
return discord.create_session()
|
return await discord.create_session()
|
||||||
|
|
||||||
|
|
||||||
@app.route("/callback/")
|
@app.route("/callback/")
|
||||||
def callback():
|
async def callback():
|
||||||
discord.callback()
|
await discord.callback()
|
||||||
return redirect(url_for(".me"))
|
return redirect(url_for(".me"))
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(Unauthorized)
|
@app.errorhandler(Unauthorized)
|
||||||
def redirect_unauthorized(e):
|
async def redirect_unauthorized(e):
|
||||||
return redirect(url_for("login"))
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
|
|
||||||
@app.route("/me/")
|
@app.route("/me/")
|
||||||
@requires_authorization
|
@requires_authorization
|
||||||
def me():
|
async def me():
|
||||||
user = discord.fetch_user()
|
user = await discord.fetch_user()
|
||||||
return f"""
|
return f"""
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from . import exceptions
|
|||||||
|
|
||||||
from quart import session, request
|
from quart import session, request
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
from requests_oauthlib import OAuth2Session
|
from async_oauthlib import OAuth2Session
|
||||||
|
|
||||||
|
|
||||||
class DiscordOAuth2HttpClient(abc.ABC):
|
class DiscordOAuth2HttpClient(abc.ABC):
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ oauthlib
|
|||||||
discord.py
|
discord.py
|
||||||
cachetools
|
cachetools
|
||||||
setuptools
|
setuptools
|
||||||
git+https://github.com/thec0sm0s/requests-oauthlib.git@async
|
Async-OAuthlib
|
||||||
|
|||||||
Reference in New Issue
Block a user