From c124b5442f863c5a401c43945b516651196a4003 Mon Sep 17 00:00:00 2001 From: WindowsSov8forUs Date: Mon, 13 May 2024 17:09:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E7=94=A8=E6=88=B7=20?= =?UTF-8?q?API=20=E5=93=8D=E5=BA=94=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.py | 2 +- tsugu_api/_typing.py | 10 +++++----- tsugu_api/_user.py | 29 ++++++++++++----------------- tsugu_api_async/_typing.py | 10 +++++----- tsugu_api_async/_user.py | 29 ++++++++++++----------------- 5 files changed, 35 insertions(+), 45 deletions(-) diff --git a/setup.py b/setup.py index d7ef4e7..e3b18d2 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='tsugu-api-python', - version='1.0.1', + version='1.0.2', author='WindowsSov8', author_email='qwertyuiop2333@hotmail.com', description='Tsugu BanGDream Bot 的功能 API 统合包', diff --git a/tsugu_api/_typing.py b/tsugu_api/_typing.py index 92e0f31..c95d901 100644 --- a/tsugu_api/_typing.py +++ b/tsugu_api/_typing.py @@ -51,7 +51,7 @@ class _Player(TypedDict): id: int server: _Server -_Status: TypeAlias = Literal['success', 'failure'] +_Status: TypeAlias = Literal['success', 'failed'] '''响应状态''' class _SubmitResponse(TypedDict): @@ -90,7 +90,7 @@ class _TsuguUser(TypedDict): car: bool server_list: list[_TsuguUserServer] -class _UserDataResponse(TypedDict): +class _GetUserDataResponse(TypedDict): '''`/user/getUserData` 响应结果''' status: _Status data: Union[str, _TsuguUser] @@ -104,7 +104,7 @@ class _Update(TypedDict): car: NotRequired[bool] server_list: NotRequired[list[_TsuguUserServer]] -class _UpdateResponse(TypedDict): +class _ChangeUserDataResponse(TypedDict): '''`/user/changeUserData` 响应结果''' status: _Status data: NotRequired[str] @@ -113,12 +113,12 @@ class _VerifyCode(TypedDict): '''验证码''' verifyCode: int -class _BindResponse(TypedDict): +class _BindPlayerRequestResponse(TypedDict): '''`/user/bindPlayerRequest` 绑定响应''' status: _Status data: Union[str, _VerifyCode] -class _VerificationResponse(TypedDict): +class _BindPlayerVerificationResponse(TypedDict): '''`/user/bindPlayerVerification` 响应结果''' status: _Status data: str diff --git a/tsugu_api/_user.py b/tsugu_api/_user.py index f887c8e..f449f04 100644 --- a/tsugu_api/_user.py +++ b/tsugu_api/_user.py @@ -4,15 +4,14 @@ from tsugu_api._network import Api from tsugu_api._typing import ( _Update, - _Response, _ServerId, - _BindResponse, - _UpdateResponse, - _UserDataResponse, - _VerificationResponse + _GetUserDataResponse, + _ChangeUserDataResponse, + _BindPlayerRequestResponse, + _BindPlayerVerificationResponse ) -def get_user_data(platform: str, user_id: str) -> Union[_Response, _UserDataResponse]: +def get_user_data(platform: str, user_id: str) -> _GetUserDataResponse: '''获取用户数据 参数: @@ -20,8 +19,7 @@ def get_user_data(platform: str, user_id: str) -> Union[_Response, _UserDataResp user_id (str): 用户 ID 返回: - _UserDataResult: 用户数据 - _Response: 当请求失败时返回的数据 + _GetUserDataResponse: API 返回响应 ''' # 构建 URL @@ -39,7 +37,7 @@ def get_user_data(platform: str, user_id: str) -> Union[_Response, _UserDataResp proxy=settings.userdata_backend_proxy ).post(data).json() -def change_user_data(platform: str, user_id: str, update: _Update) -> Union[_Response, _UpdateResponse]: +def change_user_data(platform: str, user_id: str, update: _Update) -> _ChangeUserDataResponse: '''修改用户数据 参数: @@ -48,8 +46,7 @@ def change_user_data(platform: str, user_id: str, update: _Update) -> Union[_Res update (_Update): 更新数据 返回: - _UpdateResult: 更新结果 - _Response: 当请求失败时返回的数据 + _ChangeUserDataResponse: API 返回响应 ''' # 构建 URL @@ -73,7 +70,7 @@ def bind_player_request( user_id: str, server: _ServerId, bind_type: bool -) -> Union[_Response, _BindResponse]: +) -> _BindPlayerRequestResponse: '''绑定玩家请求 参数: @@ -83,8 +80,7 @@ def bind_player_request( bind_type (bool): 绑定类型, `true` 为绑定, `false` 为解绑 返回: - _BindResponse: 请求返回数据 - _Response: 当请求失败时返回的数据 + _BindPlayerRequestResponse: 请求返回数据 ''' # 构建 URL @@ -110,7 +106,7 @@ def bind_player_verification( server: _ServerId, player_id: int, bind_type: bool -) -> Union[_Response, _VerificationResponse]: +) -> _BindPlayerVerificationResponse: '''绑定玩家验证 参数: @@ -121,8 +117,7 @@ def bind_player_verification( bind_type (bool): 绑定类型, `true` 为绑定, `false` 为解绑 返回: - _VerificationResponse: 验证返回数据 - _Response: 当请求失败时返回的数据 + _BindPlayerVerificationResponse: 验证返回数据 ''' # 构建 URL diff --git a/tsugu_api_async/_typing.py b/tsugu_api_async/_typing.py index 44a832b..603d59a 100644 --- a/tsugu_api_async/_typing.py +++ b/tsugu_api_async/_typing.py @@ -56,7 +56,7 @@ class _Player(TypedDict): id: int server: _Server -_Status: TypeAlias = Literal['success', 'failure'] +_Status: TypeAlias = Literal['success', 'failed'] '''响应状态''' class _SubmitResponse(TypedDict): @@ -95,7 +95,7 @@ class _TsuguUser(TypedDict): car: bool server_list: list[_TsuguUserServer] -class _UserDataResponse(TypedDict): +class _GetUserDataResponse(TypedDict): '''`/user/getUserData` 响应结果''' status: _Status data: Union[str, _TsuguUser] @@ -109,7 +109,7 @@ class _Update(TypedDict): car: NotRequired[bool] server_list: NotRequired[list[_TsuguUserServer]] -class _UpdateResponse(TypedDict): +class _ChangeUserDataResponse(TypedDict): '''`/user/changeUserData` 响应结果''' status: _Status data: NotRequired[str] @@ -118,12 +118,12 @@ class _VerifyCode(TypedDict): '''验证码''' verifyCode: int -class _BindResponse(TypedDict): +class _BindPlayerRequestResponse(TypedDict): '''`/user/bindPlayerRequest` 绑定响应''' status: _Status data: Union[str, _VerifyCode] -class _VerificationResponse(TypedDict): +class _BindPlayerVerificationResponse(TypedDict): '''`/user/bindPlayerVerification` 响应结果''' status: _Status data: str diff --git a/tsugu_api_async/_user.py b/tsugu_api_async/_user.py index ddc32ab..7727a36 100644 --- a/tsugu_api_async/_user.py +++ b/tsugu_api_async/_user.py @@ -6,15 +6,14 @@ from tsugu_api_async._network import Api from tsugu_api_async._typing import ( _Update, - _Response, _ServerId, - _BindResponse, - _UpdateResponse, - _UserDataResponse, - _VerificationResponse + _GetUserDataResponse, + _ChangeUserDataResponse, + _BindPlayerRequestResponse, + _BindPlayerVerificationResponse ) -async def get_user_data(platform: str, user_id: str) -> Union[_Response, _UserDataResponse]: +async def get_user_data(platform: str, user_id: str) -> _GetUserDataResponse: '''获取用户数据 参数: @@ -22,8 +21,7 @@ async def get_user_data(platform: str, user_id: str) -> Union[_Response, _UserDa user_id (str): 用户 ID 返回: - _UserDataResult: 用户数据 - _Response: 当请求失败时返回的数据 + _GetUserDataResponse: API 返回响应 ''' # 构建 URL @@ -43,7 +41,7 @@ async def get_user_data(platform: str, user_id: str) -> Union[_Response, _UserDa if isinstance(response, Response): return response.json() return await response.json() -async def change_user_data(platform: str, user_id: str, update: _Update) -> Union[_Response, _UpdateResponse]: +async def change_user_data(platform: str, user_id: str, update: _Update) -> _ChangeUserDataResponse: '''修改用户数据 参数: @@ -52,8 +50,7 @@ async def change_user_data(platform: str, user_id: str, update: _Update) -> Unio update (_Update): 更新数据 返回: - _UpdateResult: 更新结果 - _Response: 当请求失败时返回的数据 + _ChangeUserDataResponse: API 返回响应 ''' # 构建 URL @@ -79,7 +76,7 @@ async def bind_player_request( user_id: str, server: _ServerId, bind_type: bool -) -> Union[_Response, _BindResponse]: +) -> _BindPlayerRequestResponse: '''绑定玩家请求 参数: @@ -89,8 +86,7 @@ async def bind_player_request( bind_type (bool): 绑定类型, `true` 为绑定, `false` 为解绑 返回: - _BindResponse: 请求返回数据 - _Response: 当请求失败时返回的数据 + _BindPlayerRequestResponse: 请求返回数据 ''' # 构建 URL @@ -118,7 +114,7 @@ async def bind_player_verification( server: _ServerId, player_id: int, bind_type: bool -) -> Union[_Response, _VerificationResponse]: +) -> _BindPlayerVerificationResponse: '''绑定玩家验证 参数: @@ -129,8 +125,7 @@ async def bind_player_verification( bind_type (bool): 绑定类型, `true` 为绑定, `false` 为解绑 返回: - _VerificationResponse: 验证返回数据 - _Response: 当请求失败时返回的数据 + _BindPlayerVerificationResponse: 验证返回数据 ''' # 构建 URL