mirror of
https://github.com/yawaflua/Flask-Discord.git
synced 2026-02-04 10:14:15 +02:00
✔ Perform the major refactoring
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# Quart-Discord
|
# Quart-Discord
|
||||||
[](https://pypi.org/project/Quart-Discord/) [](https://quart-discord.readthedocs.io/en/latest/)
|
[](https://pypi.org/project/Flask-Discord/) [](https://flask-discord.readthedocs.io/en/latest/) [](https://discord.gg/7CrQEyP)
|
||||||
|
|
||||||
Discord OAuth2 extension for Quart.
|
Discord OAuth2 extension for Quart.
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ Discord OAuth2 extension for Quart.
|
|||||||
### Installation
|
### Installation
|
||||||
To install current latest release you can use following command:
|
To install current latest release you can use following command:
|
||||||
```sh
|
```sh
|
||||||
python3 -m pip install Quart-Discord
|
python3 -m pip install https://github.com/thec0sm0s/Flask-Discord.git@quart
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ sys.path.append('../quart_discord/')
|
|||||||
# -- Project information -----------------------------------------------------
|
# -- Project information -----------------------------------------------------
|
||||||
|
|
||||||
project = 'Quart-Discord'
|
project = 'Quart-Discord'
|
||||||
copyright = '2020, Philip Dowie'
|
copyright = '2020, □ | The Cosmos'
|
||||||
author = 'Philip Dowie'
|
author = '□ | The Cosmos'
|
||||||
|
|
||||||
with open('../quart_discord/__init__.py') as f:
|
with open('../quart_discord/__init__.py') as f:
|
||||||
ver = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE).group(1)
|
ver = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE).group(1)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ Discord's OAuth2 API easier.
|
|||||||
|
|
||||||
**Features**
|
**Features**
|
||||||
|
|
||||||
|
- Asynchronous wrapper.
|
||||||
- Clean object-oriented design.
|
- Clean object-oriented design.
|
||||||
- Covers most of the scopes provided by the API.
|
- Covers most of the scopes provided by the API.
|
||||||
- Supports various discord models and objects.
|
- Supports various discord models and objects.
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ Requirements
|
|||||||
- **Quart**
|
- **Quart**
|
||||||
This is a Quart extension.
|
This is a Quart extension.
|
||||||
|
|
||||||
- **requests_oauthlib**
|
- **Async-OAuthlib**
|
||||||
It also requires requests_oauthlib to make OAuth2 sessions with discord.
|
It also requires async_oauthlib to make OAuth2 sessions with discord.
|
||||||
|
|
||||||
- **cachetools**
|
- **cachetools**
|
||||||
Quart Discord supports caching discord objects to boost the performance when page loads.
|
Quart Discord supports caching discord objects to boost the performance when page loads.
|
||||||
@@ -32,12 +32,12 @@ Installing
|
|||||||
You can install Quart-Discord directly from PyPI using PIP and following command
|
You can install Quart-Discord directly from PyPI using PIP and following command
|
||||||
in shell or command prompt: ::
|
in shell or command prompt: ::
|
||||||
|
|
||||||
python3 -m pip install -U Quart-Discord
|
python3 -m pip install -U https://github.com/thec0sm0s/Flask-Discord.git@quart
|
||||||
|
|
||||||
You can also install the latest development version (**maybe unstable/broken**) by
|
You can also install the latest development version (**maybe unstable/broken**) by
|
||||||
using following command: ::
|
using following command: ::
|
||||||
|
|
||||||
python3 -m pip install -U git+https://github.com/jnawk/Quart-Discord.git@dev
|
python3 -m pip install -U https://github.com/thec0sm0s/Flask-Discord.git@quart
|
||||||
|
|
||||||
|
|
||||||
Basic Usage
|
Basic Usage
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class RateLimited(HttpException):
|
|||||||
|
|
||||||
Attributes
|
Attributes
|
||||||
----------
|
----------
|
||||||
response : requests.Response
|
response : aiohttp.Response
|
||||||
The actual response object received from Discord API.
|
The actual response object received from Discord API.
|
||||||
json : dict
|
json : dict
|
||||||
The actual JSON data received. Shorthand to ``response.json()``.
|
The actual JSON data received. Shorthand to ``response.json()``.
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
Quart
|
Quart
|
||||||
pyjwt
|
pyjwt
|
||||||
requests
|
|
||||||
aiohttp
|
aiohttp
|
||||||
oauthlib
|
oauthlib
|
||||||
discord.py
|
discord.py
|
||||||
|
|||||||
5
setup.py
5
setup.py
@@ -22,7 +22,6 @@ requirements = [
|
|||||||
'oauthlib',
|
'oauthlib',
|
||||||
'Async-OAuthlib',
|
'Async-OAuthlib',
|
||||||
'cachetools',
|
'cachetools',
|
||||||
'requests',
|
|
||||||
'discord.py',
|
'discord.py',
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -42,10 +41,10 @@ extra_requirements = {
|
|||||||
setup(
|
setup(
|
||||||
name='Quart-Discord',
|
name='Quart-Discord',
|
||||||
version=__get_version(),
|
version=__get_version(),
|
||||||
url='https://github.com/jnawk/Quart-Discord',
|
url='https://github.com/thec0sm0s/Flask-Discord/tree/quart',
|
||||||
license='MIT',
|
license='MIT',
|
||||||
author='Philip Dowie',
|
author='Philip Dowie',
|
||||||
author_email='philip@jnawk.nz',
|
author_email='deepakrajko14@gmail.com',
|
||||||
description='Discord OAuth2 extension for Quart.',
|
description='Discord OAuth2 extension for Quart.',
|
||||||
long_description=__doc__,
|
long_description=__doc__,
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
|
|||||||
@@ -1,118 +0,0 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
from tests import get_app, discord
|
|
||||||
from flask import redirect, url_for
|
|
||||||
from flask_discord import requires_authorization
|
|
||||||
|
|
||||||
|
|
||||||
app = get_app()
|
|
||||||
|
|
||||||
HYPERLINK = '<a href="{}">{}</a>'
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
|
||||||
def index():
|
|
||||||
if not discord.authorized:
|
|
||||||
return f"""
|
|
||||||
{HYPERLINK.format(url_for(".login"), "Login")} <br />
|
|
||||||
{HYPERLINK.format(url_for(".login_with_data"), "Login with custom data")} <br />
|
|
||||||
{HYPERLINK.format(url_for(".invite_bot"), "Invite Bot with permissions 8")} <br />
|
|
||||||
{HYPERLINK.format(url_for(".invite_oauth"), "Authorize with oauth and bot invite")}
|
|
||||||
"""
|
|
||||||
|
|
||||||
return f"""
|
|
||||||
{HYPERLINK.format(url_for(".me"), "@ME")}<br />
|
|
||||||
{HYPERLINK.format(url_for(".logout"), "Logout")}<br />
|
|
||||||
{HYPERLINK.format(url_for(".user_guilds"), "My Servers")}<br />
|
|
||||||
{HYPERLINK.format(url_for(".add_to_guild", guild_id=475549041741135881), "Add me to 475549041741135881.")}
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/login/")
|
|
||||||
def login():
|
|
||||||
return discord.create_session()
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/login-data/")
|
|
||||||
def login_with_data():
|
|
||||||
return discord.create_session(data=dict(redirect="/me/", coupon="15off", number=15, zero=0, status=False))
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/invite-bot/")
|
|
||||||
def invite_bot():
|
|
||||||
return discord.create_session(scope=["bot"], permissions=8, guild_id=464488012328468480, disable_guild_select=True)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/invite-oauth/")
|
|
||||||
def invite_oauth():
|
|
||||||
return discord.create_session(scope=["bot", "identify"], permissions=8)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/callback/")
|
|
||||||
def callback():
|
|
||||||
data = discord.callback()
|
|
||||||
redirect_to = data.get("redirect", "/")
|
|
||||||
return redirect(redirect_to)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/me/")
|
|
||||||
def me():
|
|
||||||
user = discord.fetch_user()
|
|
||||||
return f"""
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>{user.name}</title>
|
|
||||||
</head>
|
|
||||||
<body><img src='{user.avatar_url or user.default_avatar_url}' />
|
|
||||||
<p>Is avatar animated: {str(user.is_avatar_animated)}</p>
|
|
||||||
<a href={url_for("my_connections")}>Connections</a>
|
|
||||||
<br />
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/me/guilds/")
|
|
||||||
def user_guilds():
|
|
||||||
guilds = discord.fetch_guilds()
|
|
||||||
return "<br />".join([f"[ADMIN] {g.name}" if g.permissions.administrator else g.name for g in guilds])
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/add_to/<int:guild_id>/")
|
|
||||||
def add_to_guild(guild_id):
|
|
||||||
user = discord.fetch_user()
|
|
||||||
return user.add_to_guild(guild_id)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/me/connections/")
|
|
||||||
def my_connections():
|
|
||||||
user = discord.fetch_user()
|
|
||||||
connections = discord.fetch_connections()
|
|
||||||
return f"""
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>{user.name}</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
{str([f"{connection.name} - {connection.type}" for connection in connections])}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/logout/")
|
|
||||||
def logout():
|
|
||||||
discord.revoke()
|
|
||||||
return redirect(url_for(".index"))
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/secret/")
|
|
||||||
@requires_authorization
|
|
||||||
def secret():
|
|
||||||
return os.urandom(16)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
app.run(debug=True)
|
|
||||||
Reference in New Issue
Block a user