From 1b484d7fdab0770082fa87ddb36eeef812ce917f Mon Sep 17 00:00:00 2001 From: "Mr.Xia" <1424473282@qq.com> Date: Mon, 11 May 2026 22:43:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20damo=5Fbalance=20?= =?UTF-8?q?=E5=BC=95=E5=8F=B7=E8=AF=AD=E6=B3=95=E9=94=99=E8=AF=AF=E5=8F=8A?= =?UTF-8?q?=20chatai=20bleach=20=E7=BC=BA=E5=A4=B1=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - damo_balance/__init__.py: 将外层字符串改为单引号,消除内嵌双引号引起的 SyntaxError - chatai/screenshot.py: bleach 改为 try/except 可选导入,无 bleach 时降级跳过 HTML 净化 - requirements.txt: 补充 openai>=1.0.0 与 pyppeteer>=1.0.2 依赖声明 --- danding_bot/plugins/chatai/screenshot.py | 11 +++++++++-- danding_bot/plugins/damo_balance/__init__.py | 2 +- requirements.txt | 2 ++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/danding_bot/plugins/chatai/screenshot.py b/danding_bot/plugins/chatai/screenshot.py index 2e965f6..b4b8d33 100644 --- a/danding_bot/plugins/chatai/screenshot.py +++ b/danding_bot/plugins/chatai/screenshot.py @@ -2,7 +2,11 @@ import asyncio import re import html as html_module import markdown -import bleach +try: + import bleach + _HAS_BLEACH = True +except ImportError: + _HAS_BLEACH = False from nonebot import logger async def markdown_to_image(markdown_text: str, output_path: str, browser=None): @@ -21,7 +25,10 @@ async def markdown_to_image(markdown_text: str, output_path: str, browser=None): 'strong', 'em', 'b', 'i', 'u', 'a', 'img', 'div', ] allowed_attrs = {'a': ['href', 'title'], 'img': ['src', 'alt', 'title']} - html_content = bleach.clean(html_content, tags=allowed_tags, attributes=allowed_attrs) + if _HAS_BLEACH: + html_content = bleach.clean(html_content, tags=allowed_tags, attributes=allowed_attrs) + else: + logger.warning("[chatai] bleach 未安装,跳过 HTML 净化(请运行 pip install bleach)") # 使用传入的浏览器实例或创建新的 if browser is None: diff --git a/danding_bot/plugins/damo_balance/__init__.py b/danding_bot/plugins/damo_balance/__init__.py index a395079..a254a04 100644 --- a/danding_bot/plugins/damo_balance/__init__.py +++ b/danding_bot/plugins/damo_balance/__init__.py @@ -69,7 +69,7 @@ async def handle_captcha(event: MessageEvent, state: T_State, captcha: str = Arg spider = state.get("spider") if not spider: - await check_balance.finish("会话异常,请重新发送"大漠余额"") + await check_balance.finish('会话异常,请重新发送"大漠余额"') try: if spider.login(USERNAME, PASSWORD, captcha): diff --git a/requirements.txt b/requirements.txt index 51ce5cb..1b1fe79 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,6 +8,8 @@ arclet-alconna==1.8.35 arclet-alconna-tools==0.7.10 argcomplete==3.5.2 async-timeout==5.0.1 +openai>=1.0.0 +pyppeteer>=1.0.2 beautifulsoup4==4.12.3 bleach==6.2.0 bs4==0.0.2