Skip to content

Commit

Permalink
feat: 添加从车站获取车牌号 API
Browse files Browse the repository at this point in the history
  • Loading branch information
WindowsSov8forUs committed May 15, 2024
1 parent 1c4d2f0 commit f9e0af5
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='tsugu-api-python',
version='1.0.4',
version='1.1.0',
author='WindowsSov8',
author_email='[email protected]',
description='Tsugu BanGDream Bot 的功能 API 统合包',
Expand Down
27 changes: 23 additions & 4 deletions tsugu_api/_bandoristation.py
Original file line number Diff line number Diff line change
@@ -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): 上传用的车站令牌
'''

Expand All @@ -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()
24 changes: 24 additions & 0 deletions tsugu_api/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'''

from typing import (
Any,
Union,
Literal,
TypeAlias,
Expand Down Expand Up @@ -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
29 changes: 25 additions & 4 deletions tsugu_api_async/_bandoristation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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): 上传用的车站令牌
'''

Expand All @@ -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()
24 changes: 24 additions & 0 deletions tsugu_api_async/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'''

from typing import (
Any,
Union,
Literal,
TypeAlias,
Expand Down Expand Up @@ -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

0 comments on commit f9e0af5

Please sign in to comment.