diff --git a/setup.py b/setup.py index 08b813a..8d0f6f1 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='tsugu-api-python', - version='1.0.4', + version='1.1.0', author='WindowsSov8', author_email='qwertyuiop2333@hotmail.com', description='Tsugu BanGDream Bot 的功能 API 统合包', diff --git a/tsugu_api/_bandoristation.py b/tsugu_api/_bandoristation.py index 513e4ee..a24679a 100644 --- a/tsugu_api/_bandoristation.py +++ b/tsugu_api/_bandoristation.py @@ -1,17 +1,18 @@ from tsugu_api import settings from tsugu_api._network import Api +from tsugu_api._typing import _StationRoom from tsugu_api.exception import RoomSubmitFailure BANDORI_STATION_URL = 'https://api.bandoristation.com/index.php' def submit_room_number(number: int, user_id: str, raw_message: str, source: str, token: str) -> None: - '''上传车牌号 + '''上传房间号 参数: - number (int): 车牌号 + number (int): 房间号 user_id (str): 用户 ID - raw_message (str): 原始消息,用作车牌号注释 - source (str): 车牌来源,即令牌名称 + raw_message (str): 原始消息,用作房间号注释 + source (str): 房间来源,即令牌名称 token (str): 上传用的车站令牌 ''' @@ -32,3 +33,21 @@ def submit_room_number(number: int, user_id: str, raw_message: str, source: str, ).get(params).json() if response['status'] == 'failure': raise RoomSubmitFailure(response['response']) + +def query_room_number() -> list[_StationRoom]: + '''获取房间号 + + 返回: + list[_StationRoom]: 房间信息列表 + ''' + + # 构建参数 + params = { + 'function': 'query_room_number' + } + + # 发送请求 + return Api( + BANDORI_STATION_URL, + proxy=settings.backend_proxy + ).get(params).json() diff --git a/tsugu_api/_typing.py b/tsugu_api/_typing.py index c95d901..4c4aa5d 100644 --- a/tsugu_api/_typing.py +++ b/tsugu_api/_typing.py @@ -5,6 +5,7 @@ ''' from typing import ( + Any, Union, Literal, TypeAlias, @@ -122,3 +123,26 @@ class _BindPlayerVerificationResponse(TypedDict): '''`/user/bindPlayerVerification` 响应结果''' status: _Status data: str + +class _SourceInfo(TypedDict): + '''来源信息''' + name: str + type: str + +class _UserInfo(TypedDict): + '''用户信息''' + avatar: str + bandori_player_brief_info: Any + role: int + type: str + user_id: int + username: str + +class _StationRoom(TypedDict): + '''车站房间数据''' + number: int + raw_message: str + source_info: _SourceInfo + time: int + type: str + user_info: _UserInfo diff --git a/tsugu_api_async/_bandoristation.py b/tsugu_api_async/_bandoristation.py index 15de3dd..f99bf55 100644 --- a/tsugu_api_async/_bandoristation.py +++ b/tsugu_api_async/_bandoristation.py @@ -2,18 +2,19 @@ from tsugu_api_async import settings from tsugu_api_async._network import Api +from tsugu_api_async._typing import _StationRoom from tsugu_api_async.exception import RoomSubmitFailure BANDORI_STATION_URL = 'https://api.bandoristation.com/index.php' async def submit_room_number(number: int, user_id: str, raw_message: str, source: str, token: str) -> None: - '''上传车牌号 + '''上传房间号 参数: - number (int): 车牌号 + number (int): 房间号 user_id (str): 用户 ID - raw_message (str): 原始消息,用作车牌号注释 - source (str): 车牌来源,即令牌名称 + raw_message (str): 原始消息,用作房间号注释 + source (str): 房间来源,即令牌名称 token (str): 上传用的车站令牌 ''' @@ -36,3 +37,23 @@ async def submit_room_number(number: int, user_id: str, raw_message: str, source else: response = await response.json() if response['status'] == 'failure': raise RoomSubmitFailure(response['response']) + +async def query_room_number() -> list[_StationRoom]: + '''获取房间号 + + 返回: + list[_StationRoom]: 房间信息列表 + ''' + + # 构建参数 + params = { + 'function': 'query_room_number' + } + + # 发送请求 + response = await Api( + BANDORI_STATION_URL, + proxy=settings.backend_proxy + ).get(params) + if isinstance(response, Response): return response.json() + else: return await response.json() diff --git a/tsugu_api_async/_typing.py b/tsugu_api_async/_typing.py index 603d59a..6ddce6e 100644 --- a/tsugu_api_async/_typing.py +++ b/tsugu_api_async/_typing.py @@ -5,6 +5,7 @@ ''' from typing import ( + Any, Union, Literal, TypeAlias, @@ -127,3 +128,26 @@ class _BindPlayerVerificationResponse(TypedDict): '''`/user/bindPlayerVerification` 响应结果''' status: _Status data: str + +class _SourceInfo(TypedDict): + '''来源信息''' + name: str + type: str + +class _UserInfo(TypedDict): + '''用户信息''' + avatar: str + bandori_player_brief_info: Any + role: int + type: str + user_id: int + username: str + +class _StationRoom(TypedDict): + '''车站房间数据''' + number: int + raw_message: str + source_info: _SourceInfo + time: int + type: str + user_info: _UserInfo