Skip to content

Commit c5eba40

Browse files
committed
support for datetime and bool in update_role_connections
1 parent 1835316 commit c5eba40

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

discordoauth2/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import requests
2+
from datetime import datetime
23

34
class PartialAccessToken():
45
def __init__(self, access_token, client) -> None:
@@ -76,11 +77,18 @@ def join_guild(self, guild_id, nick = None, role_ids = None, mute = False, deaf
7677
raise exceptions.HTTPException(f"Unexpected HTTP {response.status_code}")
7778

7879
def update_role_connections(self, platform_name=None, username=None, **metadata):
80+
def metadataTypeHook(item):
81+
print(item, type(item), type(type(item)))
82+
if type(item) == bool:
83+
return 1 if item else 0
84+
if type(item) == datetime:
85+
return item.isoformat()
86+
else: return item
7987
response = requests.put(f"https://discord.com/api/v10/users/@me/applications/{self.client.id}/role-connection", headers={
8088
"authorization": f"Bearer {self.token}"}, json={
8189
"platform_name": platform_name,
8290
"platform_username": username,
83-
"metadata": metadata
91+
"metadata": {key: metadataTypeHook(value) for key, value in metadata.items()}
8492
})
8593

8694
if response.ok:
7.64 KB
Binary file not shown.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
setup(
77
name='discord-oauth2.py',
88
description='Use Discord\'s OAuth2 effortlessly! Turns the auth code to a access token and the access token into scope infomation. ',
9-
version="1.0.0",
9+
version="1.1.0",
1010
long_description=long_description,
1111
long_description_content_type="text/markdown",
1212
license='MIT',

0 commit comments

Comments
 (0)