From cf50e9f288870e2e1230204588dd3d8ba26e3db0 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Mon, 6 May 2024 19:12:46 +0800 Subject: [PATCH] :sparkles: rename bison_theme_use_browser -> bison_use_browser --- docker.env.prod | 2 +- docs/dev/README.md | 2 +- docs/usage/README.md | 2 +- nonebot_bison/plugin_config.py | 4 +++- nonebot_bison/theme/registry.py | 2 +- nonebot_bison/theme/types.py | 4 ++-- tests/conftest.py | 2 +- tests/post/test_generate.py | 2 +- tests/theme/test_themes.py | 4 ++-- 9 files changed, 13 insertions(+), 11 deletions(-) diff --git a/docker.env.prod b/docker.env.prod index 981be93..29cf43e 100644 --- a/docker.env.prod +++ b/docker.env.prod @@ -12,7 +12,7 @@ TZ=Asia/Shanghai BISON_CONFIG_PATH= BISON_USE_PIC=false ## 与默认配置不同,在容器中启用浏览器渲染 -BISON_THEME_USE_BROWSER=true +BISON_USE_BROWSER=true BISON_INIT_FILTER=true BISON_USE_QUEUE=true BISON_OUTER_URL= diff --git a/docs/dev/README.md b/docs/dev/README.md index e2f9088..b503364 100644 --- a/docs/dev/README.md +++ b/docs/dev/README.md @@ -300,7 +300,7 @@ RawPost 通过`Platform.parse`函数处理成 Post,然后通过`Theme.render` Bison 在启动时会尝试注册所有在`nonebot_bison/theme/themes`下的主题,如果你的主题在这个目录下,并指定了 `__theme_meta__`,那么它会被自动注册。 -若配置项`BISON_THEME_USE_BROWSER=false`,则在注册的主题需要浏览器渲染,即`need_browser`字段为`True`时,会发出注册警告 +若配置项`BISON_USE_BROWSER=false`,则在注册的主题需要浏览器渲染,即`need_browser`字段为`True`时,会发出注册警告 同时,你也可以手动调用`nonebot_bison.theme.theme_manager.register`来注册主题 diff --git a/docs/usage/README.md b/docs/usage/README.md index ceed1fc..4a877de 100644 --- a/docs/usage/README.md +++ b/docs/usage/README.md @@ -83,7 +83,7 @@ next: /usage/easy-use - `BISON_PROXY`: 使用的代理连接,形如`http://:`(可选) - `BISON_UA`: 使用的 User-Agent,默认为 Chrome - `BISON_SHOW_NETWORK_WARNING`: 是否在日志中输出网络异常,默认为`True` -- `BISON_THEME_USE_BROWSER`: 是否使用浏览器渲染主题,某些主题可能需要浏览器渲染 (htmlrender),默认为`False` +- `BISON_USE_BROWSER`: 环境中是否存在浏览器,某些主题或者平台需要浏览器,默认为`False` - `BISON_PLATFORM_THEME`: 为[平台](#平台)指定渲染用[主题](#主题),用于渲染推送消息,默认为`{}` ::: details BISON_PLATFORM_THEME 配置项示例 diff --git a/nonebot_bison/plugin_config.py b/nonebot_bison/plugin_config.py index a0734eb..2362123 100644 --- a/nonebot_bison/plugin_config.py +++ b/nonebot_bison/plugin_config.py @@ -14,7 +14,9 @@ class PlugConfig(BaseModel): default=False, description="发送消息时将所有文本转换为图片,防止风控,仅需要推送文转图可以为 platform 指定 theme", ) - bison_theme_use_browser: bool = Field(default=False, description="是否允许主题使用浏览器") + bison_use_browser: bool = Field( + default=False, description="是否使用环境中的浏览器", alias="bison_theme_use_browser" + ) bison_init_filter: bool = True bison_use_queue: bool = True bison_outer_url: str = "" diff --git a/nonebot_bison/theme/registry.py b/nonebot_bison/theme/registry.py index 009d432..7c8f76f 100644 --- a/nonebot_bison/theme/registry.py +++ b/nonebot_bison/theme/registry.py @@ -11,7 +11,7 @@ class ThemeManager: logger.trace(f"Registering theme: {theme}") if theme.name in self.__themes: raise ThemeRegistrationError(f"Theme {theme.name} duplicated registration") - if theme.need_browser and not plugin_config.bison_theme_use_browser: + if theme.need_browser and not plugin_config.bison_use_browser: logger.opt(colors=True).warning(f"Theme {theme.name} requires browser, but not allowed") self.__themes[theme.name] = theme logger.opt(colors=True).success(f"Theme {theme.name} registered") diff --git a/nonebot_bison/theme/types.py b/nonebot_bison/theme/types.py index 4b15727..3d4a312 100644 --- a/nonebot_bison/theme/types.py +++ b/nonebot_bison/theme/types.py @@ -23,8 +23,8 @@ class Theme(ABC, BaseModel): async def is_support_render(self, post: "AbstractPost") -> bool: """是否支持渲染该类型的Post""" - if self.need_browser and not plugin_config.bison_theme_use_browser: - logger.warning(f"Theme {self.name} need browser, but `bison_theme_use_browser` is False") + if self.need_browser and not plugin_config.bison_use_browser: + logger.warning(f"Theme {self.name} need browser, but `bison_use_browser` is False") return False return True diff --git a/tests/conftest.py b/tests/conftest.py index 8872a99..a65170d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -41,7 +41,7 @@ async def app(tmp_path: Path, request: pytest.FixtureRequest, mocker: MockerFixt plugin_config.bison_config_path = str(tmp_path / "legacy_config") plugin_config.bison_filter_log = False - plugin_config.bison_theme_use_browser = True + plugin_config.bison_use_browser = True datastore_config.datastore_config_dir = tmp_path / "config" datastore_config.datastore_cache_dir = tmp_path / "cache" diff --git a/tests/post/test_generate.py b/tests/post/test_generate.py index 7c985dc..0b00460 100644 --- a/tests/post/test_generate.py +++ b/tests/post/test_generate.py @@ -188,7 +188,7 @@ async def test_generate_msg(mock_platform): res1 = await post.generate() assert isinstance(res1[0], Image) - plugin_config.bison_theme_use_browser = False + plugin_config.bison_use_browser = False res3 = await post.generate() assert res3[0] diff --git a/tests/theme/test_themes.py b/tests/theme/test_themes.py index 3d35771..b12283b 100644 --- a/tests/theme/test_themes.py +++ b/tests/theme/test_themes.py @@ -122,7 +122,7 @@ async def test_theme_need_browser(app: App, mock_post): async def test_theme_no_enable_use_browser(app: App, mock_post): from nonebot_bison.plugin_config import plugin_config - plugin_config.bison_theme_use_browser = False + plugin_config.bison_use_browser = False from nonebot_bison.theme import Theme, ThemeRenderUnsupportError, theme_manager @@ -140,7 +140,7 @@ async def test_theme_no_enable_use_browser(app: App, mock_post): await theme.do_render(mock_post) theme_manager.unregister(theme.name) - plugin_config.bison_theme_use_browser = True + plugin_config.bison_use_browser = True @pytest.mark.asyncio