rename bison_theme_use_browser -> bison_use_browser

This commit is contained in:
felinae98 2024-05-06 19:12:46 +08:00
parent d8f48fc490
commit cf50e9f288
9 changed files with 13 additions and 11 deletions

View File

@ -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=

View File

@ -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`来注册主题

View File

@ -83,7 +83,7 @@ next: /usage/easy-use
- `BISON_PROXY`: 使用的代理连接,形如`http://<ip>:<port>`(可选)
- `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 配置项示例

View File

@ -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 = ""

View File

@ -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 <b><u>{theme.name}</u></b> requires browser, but not allowed")
self.__themes[theme.name] = theme
logger.opt(colors=True).success(f"Theme <b><u>{theme.name}</u></b> registered")

View File

@ -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

View File

@ -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"

View File

@ -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]

View File

@ -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