fix: 修复 damo_balance 引号语法错误及 chatai bleach 缺失依赖

- damo_balance/__init__.py: 将外层字符串改为单引号,消除内嵌双引号引起的 SyntaxError
- chatai/screenshot.py: bleach 改为 try/except 可选导入,无 bleach 时降级跳过 HTML 净化
- requirements.txt: 补充 openai>=1.0.0 与 pyppeteer>=1.0.2 依赖声明
This commit is contained in:
2026-05-11 22:43:27 +08:00
parent 3db17fc08b
commit 1b484d7fda
3 changed files with 12 additions and 3 deletions

View File

@@ -2,7 +2,11 @@ import asyncio
import re
import html as html_module
import markdown
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']}
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:

View File

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

View File

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