mirror of
https://github.com/yawaflua/Flask-Discord.git
synced 2025-12-10 12:29:30 +02:00
Try adding user to guild method [broken]
This commit is contained in:
@@ -33,8 +33,17 @@ class DiscordOAuth2HttpClient(abc.ABC):
|
|||||||
self.client_id = app.config["DISCORD_CLIENT_ID"]
|
self.client_id = app.config["DISCORD_CLIENT_ID"]
|
||||||
self.client_secret = app.config["DISCORD_CLIENT_SECRET"]
|
self.client_secret = app.config["DISCORD_CLIENT_SECRET"]
|
||||||
self.redirect_uri = app.config["DISCORD_REDIRECT_URI"]
|
self.redirect_uri = app.config["DISCORD_REDIRECT_URI"]
|
||||||
|
self.bot_token = app.config.get("DISCORD_BOT_TOKEN", str())
|
||||||
if "http://" in self.redirect_uri:
|
if "http://" in self.redirect_uri:
|
||||||
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "true"
|
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "true"
|
||||||
|
app.discord = self
|
||||||
|
|
||||||
|
@property
|
||||||
|
def bot_authorization_header(self):
|
||||||
|
return {
|
||||||
|
"Authorization": f"Bot {self.bot_token}",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _token_updater(token):
|
def _token_updater(token):
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ from .base import DiscordModelsBase
|
|||||||
|
|
||||||
from .. import configs
|
from .. import configs
|
||||||
|
|
||||||
|
from flask import current_app
|
||||||
|
|
||||||
|
|
||||||
class User(DiscordModelsBase):
|
class User(DiscordModelsBase):
|
||||||
"""Class representing Discord User.
|
"""Class representing Discord User.
|
||||||
@@ -70,6 +72,11 @@ class User(DiscordModelsBase):
|
|||||||
"""A boolean representing if avatar of user is animated. Meaning user has GIF avatar."""
|
"""A boolean representing if avatar of user is animated. Meaning user has GIF avatar."""
|
||||||
return self.avatar_hash.startswith("a_")
|
return self.avatar_hash.startswith("a_")
|
||||||
|
|
||||||
|
def add_to_guild(self, guild_id):
|
||||||
|
discord = current_app.discord
|
||||||
|
return discord.request(
|
||||||
|
f"/guilds/{guild_id}/members/{self.id}", method="PUT", headers=discord.bot_authorization_header)
|
||||||
|
|
||||||
|
|
||||||
class Bot(User):
|
class Bot(User):
|
||||||
"""Class representing the client user itself."""
|
"""Class representing the client user itself."""
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ app.secret_key = b"%\xe0'\x01\xdeH\x8e\x85m|\xb3\xffCN\xc9g"
|
|||||||
|
|
||||||
app.config["DISCORD_CLIENT_ID"] = 490732332240863233
|
app.config["DISCORD_CLIENT_ID"] = 490732332240863233
|
||||||
app.config["DISCORD_CLIENT_SECRET"] = os.getenv("DISCORD_CLIENT_SECRET")
|
app.config["DISCORD_CLIENT_SECRET"] = os.getenv("DISCORD_CLIENT_SECRET")
|
||||||
|
app.config["DISCORD_BOT_TOKEN"] = os.getenv("DISCORD_BOT_TOKEN")
|
||||||
app.config["DISCORD_REDIRECT_URI"] = "http://127.0.0.1:5000/callback"
|
app.config["DISCORD_REDIRECT_URI"] = "http://127.0.0.1:5000/callback"
|
||||||
|
|
||||||
discord = DiscordOAuth2Session(app)
|
discord = DiscordOAuth2Session(app)
|
||||||
@@ -17,7 +18,7 @@ discord = DiscordOAuth2Session(app)
|
|||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
return discord.create_session(["guilds", "connections"])
|
return discord.create_session()
|
||||||
|
|
||||||
|
|
||||||
@app.route("/callback/")
|
@app.route("/callback/")
|
||||||
@@ -36,6 +37,8 @@ def me():
|
|||||||
</head>
|
</head>
|
||||||
<body><img src='{user.avatar_url}' />
|
<body><img src='{user.avatar_url}' />
|
||||||
<a href={url_for("my_connections")}>Connections</a>
|
<a href={url_for("my_connections")}>Connections</a>
|
||||||
|
<br />
|
||||||
|
<a href={user.add_to_guild(475549041741135881)}>Add me to square server!</a>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user