mirror of
https://github.com/yawaflua/Flask-Discord.git
synced 2026-02-04 10:14:15 +02:00
Merge remote-tracking branch 'quart-discord/master' into quart-discord
# Conflicts: # README.md # docs/introduction.rst # quart_discord/__init__.py # quart_discord/_http.py
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import os
|
||||
|
||||
from flask import Flask, redirect, url_for
|
||||
from flask_discord import DiscordOAuth2Session, requires_authorization
|
||||
from quart import Quart, redirect, url_for
|
||||
from quart_discord import DiscordOAuth2Session, requires_authorization
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
app = Quart(__name__)
|
||||
|
||||
app.secret_key = b"%\xe0'\x01\xdeH\x8e\x85m|\xb3\xffCN\xc9g"
|
||||
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "true" # !! Only in development environment.
|
||||
@@ -21,8 +21,8 @@ HYPERLINK = '<a href="{}">{}</a>'
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
if not discord.authorized:
|
||||
async def index():
|
||||
if not await discord.authorized():
|
||||
return f"""
|
||||
{HYPERLINK.format(url_for(".login"), "Login")} <br />
|
||||
{HYPERLINK.format(url_for(".login_with_data"), "Login with custom data")} <br />
|
||||
@@ -39,35 +39,37 @@ def index():
|
||||
|
||||
|
||||
@app.route("/login/")
|
||||
def login():
|
||||
return discord.create_session()
|
||||
async def login():
|
||||
return await 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))
|
||||
async def login_with_data():
|
||||
return await 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)
|
||||
async def invite_bot():
|
||||
return await 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)
|
||||
async def invite_oauth():
|
||||
return await discord.create_session(scope=["bot", "identify"], permissions=8)
|
||||
|
||||
|
||||
@app.route("/callback/")
|
||||
def callback():
|
||||
data = discord.callback()
|
||||
async def callback():
|
||||
data = await discord.callback()
|
||||
redirect_to = data.get("redirect", "/")
|
||||
return redirect(redirect_to)
|
||||
|
||||
|
||||
@app.route("/me/")
|
||||
def me():
|
||||
user = discord.fetch_user()
|
||||
async def me():
|
||||
user = await discord.fetch_user()
|
||||
return f"""
|
||||
<html>
|
||||
<head>
|
||||
@@ -84,21 +86,21 @@ def me():
|
||||
|
||||
|
||||
@app.route("/me/guilds/")
|
||||
def user_guilds():
|
||||
guilds = discord.fetch_guilds()
|
||||
async def user_guilds():
|
||||
guilds = await 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)
|
||||
async def add_to_guild(guild_id):
|
||||
user = await discord.fetch_user()
|
||||
return await user.add_to_guild(guild_id)
|
||||
|
||||
|
||||
@app.route("/me/connections/")
|
||||
def my_connections():
|
||||
user = discord.fetch_user()
|
||||
connections = discord.fetch_connections()
|
||||
async def my_connections():
|
||||
user = await discord.fetch_user()
|
||||
connections = await discord.fetch_connections()
|
||||
return f"""
|
||||
<html>
|
||||
<head>
|
||||
@@ -113,14 +115,14 @@ def my_connections():
|
||||
|
||||
|
||||
@app.route("/logout/")
|
||||
def logout():
|
||||
async def logout():
|
||||
discord.revoke()
|
||||
return redirect(url_for(".index"))
|
||||
|
||||
|
||||
@app.route("/secret/")
|
||||
@requires_authorization
|
||||
def secret():
|
||||
async def secret():
|
||||
return os.urandom(16)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user