mirror of
https://github.com/yawaflua/Py-SPW.git
synced 2025-12-10 04:19:31 +02:00
upload v 1.0
added method get_user_skin_url(return url to part of the skin or None) fix bug with raise incorrect error in get_skin_url shortened method code get_user_skin
This commit is contained in:
34
pyspw/api.py
34
pyspw/api.py
@@ -90,13 +90,13 @@ 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_skin(self, discord_id: str, body_part: str, image_size: int = 64) -> bytes | None:
|
def get_user_skin_url(self, discord_id: str, body_part: str, image_size: int = 64) -> str | None:
|
||||||
"""
|
"""
|
||||||
Получение изображения части скина.
|
Получение изображения части скина.
|
||||||
:param discord_id: ID пользователя дискорда.
|
:param discord_id: ID пользователя дискорда.
|
||||||
:param body_part: Часть тела для получения. Допустимые значения - https://visage.surgeplay.com/index.html
|
:param body_part: Часть тела для получения. Допустимые значения - https://visage.surgeplay.com/index.html
|
||||||
:param image_size: Размер получаемого изображения.
|
:param image_size: Размер получаемого изображения.
|
||||||
:return: Bytes если пользователь найден, None если пользователь не найден. В bytes содержиться изображение профиля
|
:return: Str если пользователь найден, None если пользователь не найден. В str содержится ссылка на изображение профиля
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if body_part not in accessed_body_part:
|
if body_part not in accessed_body_part:
|
||||||
@@ -118,18 +118,32 @@ class sp_api_base:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# surgeplay
|
# surgeplay
|
||||||
try:
|
return f'https://visage.surgeplay.com/{body_part}/{image_size}/{uuid}'
|
||||||
mojang_response = rq.get(f'https://visage.surgeplay.com/{body_part}/{image_size}/{uuid}')
|
|
||||||
if mojang_response.status_code != 200:
|
|
||||||
raise err.MojangApiError(f'HTTP status: {mojang_response.status_code}')
|
|
||||||
return mojang_response.content
|
|
||||||
|
|
||||||
except rq.exceptions.ConnectionError as error:
|
|
||||||
raise err.SurgeplayApiError(error)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_user_skin(self, discord_id: str, body_part: str, image_size: int = 64) -> bytes | None:
|
||||||
|
"""
|
||||||
|
Получение изображения части скина.
|
||||||
|
:param discord_id: ID пользователя дискорда.
|
||||||
|
:param body_part: Часть тела для получения. Допустимые значения - https://visage.surgeplay.com/index.html
|
||||||
|
:param image_size: Размер получаемого изображения.
|
||||||
|
:return: Bytes если пользователь найден, None если пользователь не найден. В bytes содержиться изображение профиля
|
||||||
|
"""
|
||||||
|
url = self.get_user_skin_url(discord_id, body_part, image_size)
|
||||||
|
if url is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
surgeplay_response = rq.get(url)
|
||||||
|
if surgeplay_response.status_code != 200:
|
||||||
|
raise err.SurgeplayApiError(f'HTTP status: {surgeplay_response.status_code}')
|
||||||
|
return surgeplay_response.content
|
||||||
|
|
||||||
|
except rq.exceptions.ConnectionError as error:
|
||||||
|
raise err.SurgeplayApiError(error)
|
||||||
|
|
||||||
def check_webhook(self, webhook_data: str, X_Body_Hash: str) -> bool:
|
def check_webhook(self, webhook_data: str, X_Body_Hash: str) -> bool:
|
||||||
"""
|
"""
|
||||||
Валидирует webhook
|
Валидирует webhook
|
||||||
|
|||||||
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.0.4',
|
version='1.1',
|
||||||
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