mirror of
https://github.com/yawaflua/Py-SPW.git
synced 2025-12-10 04:19:31 +02:00
Upload v 1.3
- added method to get user minecraft UUID
This commit is contained in:
40
pyspw/api.py
40
pyspw/api.py
@@ -90,6 +90,23 @@ class sp_api_base:
|
|||||||
"""
|
"""
|
||||||
return False if self.get_user(discord_id) is None else True
|
return False if self.get_user(discord_id) is None else True
|
||||||
|
|
||||||
|
def get_user_uuid(self, discord_id: str) -> str | None:
|
||||||
|
username = self.get_user(discord_id)
|
||||||
|
if username is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
mojang_response = rq.get(f'https://api.mojang.com/users/profiles/minecraft/{username}')
|
||||||
|
if mojang_response.status_code != 200:
|
||||||
|
raise err.MojangApiError(f'HTTP status: {mojang_response.status_code}')
|
||||||
|
return mojang_response.json()['id']
|
||||||
|
|
||||||
|
except rq.exceptions.ConnectionError as error:
|
||||||
|
raise err.MojangApiError(error)
|
||||||
|
|
||||||
|
except rq.exceptions.JSONDecodeError:
|
||||||
|
return None
|
||||||
|
|
||||||
def get_user_skin_url(self, discord_id: str, body_part: str, image_size: int = 64) -> str | None:
|
def get_user_skin_url(self, discord_id: str, body_part: str, image_size: int = 64) -> str | None:
|
||||||
"""
|
"""
|
||||||
Получение изображения части скина.
|
Получение изображения части скина.
|
||||||
@@ -102,27 +119,12 @@ class sp_api_base:
|
|||||||
if body_part not in accessed_body_part:
|
if body_part not in accessed_body_part:
|
||||||
raise err.BadSkinPartName(f'"{body_part}" is not a part of the skin')
|
raise err.BadSkinPartName(f'"{body_part}" is not a part of the skin')
|
||||||
|
|
||||||
username = self.get_user(discord_id)
|
uuid = self.get_user_uuid(discord_id)
|
||||||
if username is not None:
|
if uuid is None:
|
||||||
# mojang
|
|
||||||
try:
|
|
||||||
mojang_response = rq.get(f'https://api.mojang.com/users/profiles/minecraft/{username}')
|
|
||||||
if mojang_response.status_code != 200:
|
|
||||||
raise err.MojangApiError(f'HTTP status: {mojang_response.status_code}')
|
|
||||||
uuid = mojang_response.json()['id']
|
|
||||||
|
|
||||||
except rq.exceptions.ConnectionError as error:
|
|
||||||
raise err.MojangApiError(error)
|
|
||||||
|
|
||||||
except rq.exceptions.JSONDecodeError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
# surgeplay
|
|
||||||
return f'https://visage.surgeplay.com/{body_part}/{image_size}/{uuid}'
|
|
||||||
|
|
||||||
else:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
return f'https://visage.surgeplay.com/{body_part}/{image_size}/{uuid}'
|
||||||
|
|
||||||
def get_user_skin(self, discord_id: str, body_part: str, image_size: int = 64) -> bytes | None:
|
def get_user_skin(self, discord_id: str, body_part: str, image_size: int = 64) -> bytes | None:
|
||||||
"""
|
"""
|
||||||
Получение изображения части скина.
|
Получение изображения части скина.
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -10,7 +10,7 @@ requires = ['requests==2.28.1']
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='Py-SPW',
|
name='Py-SPW',
|
||||||
version='1.2',
|
version='1.3',
|
||||||
packages=['pyspw'],
|
packages=['pyspw'],
|
||||||
url='https://github.com/teleport2/Py-SPW',
|
url='https://github.com/teleport2/Py-SPW',
|
||||||
license='MIT License',
|
license='MIT License',
|
||||||
|
|||||||
Reference in New Issue
Block a user