mirror of
https://github.com/yawaflua/Flask-Discord.git
synced 2025-12-09 20:09:30 +02:00
✔ Perform the major refactoring
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# 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.
|
||||
|
||||
@@ -7,7 +7,7 @@ Discord OAuth2 extension for Quart.
|
||||
### Installation
|
||||
To install current latest release you can use following command:
|
||||
```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 = 'Quart-Discord'
|
||||
copyright = '2020, Philip Dowie'
|
||||
author = 'Philip Dowie'
|
||||
copyright = '2020, □ | The Cosmos'
|
||||
author = '□ | The Cosmos'
|
||||
|
||||
with open('../quart_discord/__init__.py') as f:
|
||||
ver = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE).group(1)
|
||||
|
||||
@@ -13,6 +13,7 @@ Discord's OAuth2 API easier.
|
||||
|
||||
**Features**
|
||||
|
||||
- Asynchronous wrapper.
|
||||
- Clean object-oriented design.
|
||||
- Covers most of the scopes provided by the API.
|
||||
- Supports various discord models and objects.
|
||||
|
||||
@@ -17,8 +17,8 @@ Requirements
|
||||
- **Quart**
|
||||
This is a Quart extension.
|
||||
|
||||
- **requests_oauthlib**
|
||||
It also requires requests_oauthlib to make OAuth2 sessions with discord.
|
||||
- **Async-OAuthlib**
|
||||
It also requires async_oauthlib to make OAuth2 sessions with discord.
|
||||
|
||||
- **cachetools**
|
||||
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
|
||||
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
|
||||
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
|
||||
|
||||
@@ -12,7 +12,7 @@ class RateLimited(HttpException):
|
||||
|
||||
Attributes
|
||||
----------
|
||||
response : requests.Response
|
||||
response : aiohttp.Response
|
||||
The actual response object received from Discord API.
|
||||
json : dict
|
||||
The actual JSON data received. Shorthand to ``response.json()``.
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
Quart
|
||||
pyjwt
|
||||
requests
|
||||
aiohttp
|
||||
oauthlib
|
||||
discord.py
|
||||
|
||||
5
setup.py
5
setup.py
@@ -22,7 +22,6 @@ requirements = [
|
||||
'oauthlib',
|
||||
'Async-OAuthlib',
|
||||
'cachetools',
|
||||
'requests',
|
||||
'discord.py',
|
||||
]
|
||||
|
||||
@@ -42,10 +41,10 @@ extra_requirements = {
|
||||
setup(
|
||||
name='Quart-Discord',
|
||||
version=__get_version(),
|
||||
url='https://github.com/jnawk/Quart-Discord',
|
||||
url='https://github.com/thec0sm0s/Flask-Discord/tree/quart',
|
||||
license='MIT',
|
||||
author='Philip Dowie',
|
||||
author_email='philip@jnawk.nz',
|
||||
author_email='deepakrajko14@gmail.com',
|
||||
description='Discord OAuth2 extension for Quart.',
|
||||
long_description=__doc__,
|
||||
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