Skip to content

Commit 7a51709

Browse files
🧑‍💻添加更多实用开发配置项 (#555)
1 parent 068c508 commit 7a51709

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

nonebot_plugin_tetris_stats/config/config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from pathlib import Path
2+
13
from nonebot import get_driver, get_plugin_config
24
from nonebot_plugin_localstore import get_plugin_cache_dir, get_plugin_data_dir
35
from pydantic import BaseModel, Field
@@ -14,11 +16,17 @@ class Proxy(BaseModel):
1416
top: str | None = None
1517

1618

19+
class Dev(BaseModel):
20+
enabled: bool = False
21+
template_path: Path | None = None
22+
enable_template_check: bool = True
23+
24+
1725
class ScopedConfig(BaseModel):
1826
request_timeout: float = 30.0
1927
screenshot_quality: float = 2
2028
proxy: Proxy = Field(default_factory=Proxy)
21-
development: bool = False
29+
dev: Dev = Field(default_factory=Dev)
2230

2331

2432
class Config(BaseModel):

nonebot_plugin_tetris_stats/games/tetrio/rank/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ async def get_tetra_league_data() -> None:
137137
await session.commit()
138138

139139

140-
if not config.tetris.development:
140+
if not config.tetris.dev.enabled:
141141

142142
@driver.on_startup
143143
async def _() -> None:

nonebot_plugin_tetris_stats/utils/browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async def _start_browser(cls) -> Browser:
7878
"""启动浏览器实例"""
7979
playwright = await async_playwright().start()
8080
cls._browser = await playwright.firefox.launch(
81-
headless=not config.tetris.development,
81+
headless=not config.tetris.dev.enabled,
8282
firefox_user_prefs={
8383
'network.http.max-persistent-connections-per-server': 64,
8484
},

nonebot_plugin_tetris_stats/utils/host.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(self, page: str) -> None:
4545
async def __aenter__(self) -> str:
4646
return self.page_hash
4747

48-
if not config.tetris.development:
48+
if not config.tetris.dev.enabled:
4949

5050
async def __aexit__(self, exc_type, exc, tb) -> None: # noqa: ANN001
5151
self.pages.pop(self.page_hash, None)

nonebot_plugin_tetris_stats/utils/templates.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
driver = get_driver()
1919

20-
TEMPLATES_DIR = DATA_PATH / 'templates'
20+
TEMPLATES_DIR = config.tetris.dev.template_path or DATA_PATH / 'templates'
21+
2122

2223
alc = on_alconna(Alconna('更新模板', Option('--revision', Args['revision', str], alias={'-R'})), permission=SUPERUSER)
2324

@@ -111,16 +112,6 @@ async def check_tag(tag: str) -> bool:
111112
).status_code != HTTPStatus.NOT_FOUND
112113

113114

114-
@driver.on_startup
115-
async def _():
116-
if (path := (TEMPLATES_DIR / 'hash.sha256')).is_file() and await check_hash(path):
117-
logger.success('模板验证成功')
118-
return
119-
if not await init_templates('latest'):
120-
msg = '模板初始化失败'
121-
raise RuntimeError(msg)
122-
123-
124115
@alc.handle()
125116
async def _(revision: str | None = None):
126117
if revision is not None and not await check_tag(revision):
@@ -129,3 +120,17 @@ async def _(revision: str | None = None):
129120
if await init_templates(revision or 'latest'):
130121
await alc.finish('更新模板成功')
131122
await alc.finish('更新模板失败')
123+
124+
125+
if config.tetris.dev.enable_template_check:
126+
# !https://github.com/python/mypy/issues/19516
127+
# 只能放def后面了(
128+
129+
@driver.on_startup
130+
async def _():
131+
if (path := (TEMPLATES_DIR / 'hash.sha256')).is_file() and await check_hash(path):
132+
logger.success('模板验证成功')
133+
return
134+
if not await init_templates('latest'):
135+
msg = '模板初始化失败'
136+
raise RuntimeError(msg)

0 commit comments

Comments
 (0)