mirror of
https://github.com/yawaflua/Flask-Discord.git
synced 2025-12-09 20:09:30 +02:00
119 lines
2.8 KiB
Python
119 lines
2.8 KiB
Python
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)
|