Skip to content

Commit 9e7e0ca

Browse files
committed
增加 timeout 配置
1 parent 840e964 commit 9e7e0ca

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
<a href="https://pypi.python.org/pypi/nonebot-plugin-osu-match-monitor">
1818
<img src="https://img.shields.io/pypi/v/nonebot-plugin-osu-match-monitor.svg" alt="pypi">
1919
</a>
20+
<a href="https://www.codefactor.io/repository/github/sevenyine/nonebot-plugin-osu-match-monitor">
21+
<img src="https://www.codefactor.io/repository/github/sevenyine/nonebot-plugin-osu-match-monitor/badge" alt="CodeFactor" /></a>
22+
23+
![GitHub Release](https://img.shields.io/github/v/release/Sevenyine/nonebot-plugin-osu-match-monitor)
2024
<img src="https://img.shields.io/badge/python-3.9+-blue.svg" alt="python">
2125

2226
</div>
@@ -64,6 +68,7 @@ Welcome to osu! <img src="https://github.com/ppy/osu/blob/master/assets/lazer.pn
6468
|:-----:|:----:|:----:|:----:|
6569
| osu_api_key || "" | str |
6670
| osu_refresh_interval || 2 | int |
71+
| osu_api_timeout || 5 | int |
6772

6873
### 如何获取 osu! API Key?
6974

nonebot_plugin_osu_match_monitor/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
plugin_config = get_plugin_config(Config)
2828
api_key = plugin_config.osu_api_key
2929
refresh_interval = plugin_config.osu_refresh_interval
30+
api_timeout = plugin_config.osu_api_timeout
3031
API_URL_MATCH = "https://osu.ppy.sh/api/get_match"
3132
API_URL_USER = "https://osu.ppy.sh/api/get_user"
3233
API_URL_BEATMAP = "https://osu.ppy.sh/api/get_beatmaps"
@@ -203,7 +204,7 @@ async def get_match_info(room_id: str) -> Dict:
203204
"mp": room_id
204205
}
205206
try:
206-
async with httpx.AsyncClient() as client:
207+
async with httpx.AsyncClient(timeout=api_timeout) as client:
207208
response = await client.get(API_URL_MATCH, params=params)
208209
logger.debug(f"请求房间 {room_id} 的比赛信息,状态码:{response.status_code}")
209210
if response.status_code == 200:
@@ -228,7 +229,7 @@ async def get_user_info(user_id: str) -> Dict:
228229
"type": "id"
229230
}
230231
try:
231-
async with httpx.AsyncClient() as client:
232+
async with httpx.AsyncClient(timeout=api_timeout) as client:
232233
response = await client.get(API_URL_USER, params=params)
233234
if response.status_code == 200:
234235
data = response.json()
@@ -251,7 +252,7 @@ async def get_beatmap_info(beatmap_id: str) -> Dict:
251252
"limit": 1
252253
}
253254
try:
254-
async with httpx.AsyncClient() as client:
255+
async with httpx.AsyncClient(timeout=api_timeout) as client:
255256
response = await client.get(API_URL_BEATMAP, params=params)
256257
if response.status_code == 200:
257258
data = response.json()

nonebot_plugin_osu_match_monitor/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
class Config(BaseModel):
44
osu_api_key: str = ""
55
osu_refresh_interval: int = 2
6+
osu_api_timeout: int = 5

0 commit comments

Comments
 (0)