Skip to content

Commit

Permalink
fix oauth2 scopes, stop using bulk endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
breqdev committed Apr 28, 2022
1 parent 14ce8f4 commit 1ae2b96
Showing 1 changed file with 20 additions and 26 deletions.
46 changes: 20 additions & 26 deletions flask_discord_interactions/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def fetch_token(self, app=None):
if app.config["DONT_REGISTER_WITH_DISCORD"]:
app.discord_token = {
"token_type": "Bearer",
"scope": "applications.commands.update",
"scope": "applications.commands.update applications.commands.permissions.update",
"expires_in": 604800,
"access_token": "DONT_REGISTER_WITH_DISCORD",
}
Expand All @@ -309,7 +309,7 @@ def fetch_token(self, app=None):
app.config["DISCORD_BASE_URL"] + "/oauth2/token",
data={
"grant_type": "client_credentials",
"scope": "applications.commands.update",
"scope": "applications.commands.update applications.commands.permissions.update",
},
headers={"Content-Type": "application/x-www-form-urlencoded"},
auth=(app.config["DISCORD_CLIENT_ID"], app.config["DISCORD_CLIENT_SECRET"]),
Expand Down Expand Up @@ -393,30 +393,22 @@ def update_commands(self, app=None, guild_id=None):
for command in app.discord_commands.values():
command.id = command.name

url += "/permissions"

permissions_data = [
{"id": command.id, "permissions": command.dump_permissions()}
for command in app.discord_commands.values()
if command.permissions
]

if not permissions_data:
return

if not app.config["DONT_REGISTER_WITH_DISCORD"]:
response = requests.put(
url, json=permissions_data, headers=self.auth_headers(app)
)
self.throttle(response)

try:
response.raise_for_status()
except requests.exceptions.HTTPError:
raise ValueError(
f"Unable to register permissions:"
f"{response.status_code} {response.text}"
for command in app.discord_commands.values():
if not app.config["DONT_REGISTER_WITH_DISCORD"]:
response = requests.put(
url + "/" + command.id + "/permissions",
json={"permissions": command.dump_permissions()},
headers=self.auth_headers(app),
)
self.throttle(response)

try:
response.raise_for_status()
except requests.exceptions.HTTPError:
raise ValueError(
f"Unable to register permissions for {command.id}:"
f"{response.status_code} {response.text}"
)

def update_slash_commands(self, *args, **kwargs):
"""
Expand Down Expand Up @@ -603,7 +595,9 @@ def interactions():
return jsonify(self.run_autocomplete(request.json).dump())

elif interaction_type == InteractionType.MODAL_SUBMIT:
return jsonify(self.run_handler(request.json, allow_modal=False).dump_handler())
return jsonify(
self.run_handler(request.json, allow_modal=False).dump_handler()
)

else:
raise RuntimeWarning(
Expand Down

0 comments on commit 1ae2b96

Please sign in to comment.