From 97a053a809f428c1073f2dc5e2167e2db3777da9 Mon Sep 17 00:00:00 2001 From: KoishiMoe <68314080+KoishiMoe@users.noreply.github.com> Date: Sun, 19 Feb 2023 01:57:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 32 ++++++++++++++++++++++++++++ nonebot_plugin_mediawiki/__init__.py | 2 +- nonebot_plugin_mediawiki/worker.py | 20 ++++++++++------- pyproject.toml | 2 +- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f38a7f2..86f0b11 100644 --- a/README.md +++ b/README.md @@ -220,3 +220,35 @@ bot管理员可以设置全局的wiki,全局wiki的设计意图在于回落, 根据我个人在一些wiki项目的QQ群观摩 ~~(潜伏)~~ 的经验来说,群bot的wiki功能被调用的频率并不会很高,因此除非你将bot同时置于多个群, 并且都连接到同一个wiki,或者有人恶意利用bot(事实上由于bot不响应私聊的查询请求,要达到这种效果只能在群聊中刷屏),不然碰上调用频率限制的可能性还是很低的 + +#### 截图功能 + +本插件支持截图功能,但是需要额外安装依赖。如果你不需要截图功能,可以跳过这一节。 + +```shell +# 激活虚拟环境 +# linux, venv +source venv/bin/activate +# windows, venv +venv\Scripts\activate.bat +# 安装playwright(本插件将playwright列为了可选依赖,因此需要手动安装) +pip install playwright +# 安装chromium +playwright install chromium +# 对于无头linux服务器,建议安装完整的chromium以补全缺失的依赖 +# Ubuntu +sudo apt install chromium-browser +# CentOS +sudo yum install chromium +# Arch +sudo pacman -S chromium +``` + +需要注意的是,当前版本的插件硬编码使用chromium。如果您确实需要使用其他浏览器,可以自行修改`worker.py`中的相关语句。 + +当前该功能**仍处于测试阶段**,不建议在生产环境中使用。以下是一些您可能需要注意的问题: +* chromium会占用大量服务器资源,如果您的服务器配置较低,可能会导致bot无法正常运行。如果您的服务器配置较低,建议不要使用截图功能。 +* 本插件对输出的内容没有过滤,您可能需要考虑安全性问题(例如,如果您的bot在公开群中使用,可能会被恶意利用来发送一些不适合在某些地区显示的内容)。 +* 某些wiki有奇怪的弹窗、广告等,也有些wiki的防火墙比较严格,或者有人机验证等,可能会导致无头浏览器无法正常获取页面。 ~~(e.g.某萌百几条都占了)~~ +* 恶意的群成员可能会利用一些wiki的特殊页面来获取bot的服务器ip等敏感信息 +* 攻击者可能会利用浏览器漏洞来入侵服务器 diff --git a/nonebot_plugin_mediawiki/__init__.py b/nonebot_plugin_mediawiki/__init__.py index 2790c16..b2a4d80 100644 --- a/nonebot_plugin_mediawiki/__init__.py +++ b/nonebot_plugin_mediawiki/__init__.py @@ -17,6 +17,6 @@ '注意:私聊状态下该插件仅会响应超管的命令,且仅能管理全局wiki\n' \ '完整文档请前往 https://github.com/KoishiMoe/nonebot-plugin-mediawiki 查看' -__help_version__ = '1.1.0-alpha' +__help_version__ = '1.1.0-alpha.2' __help_plugin_name__ = 'Wiki推送' diff --git a/nonebot_plugin_mediawiki/worker.py b/nonebot_plugin_mediawiki/worker.py index f99c370..ab7b382 100644 --- a/nonebot_plugin_mediawiki/worker.py +++ b/nonebot_plugin_mediawiki/worker.py @@ -72,25 +72,29 @@ async def wiki_preprocess(bot: Bot, event: GroupMessageEvent, state: T_State, ma title = [title] elif mode == "shot": global playwright, browser, playwright_launch_error, playwright_not_installed + if playwright_not_installed: + await matcher.finish("Playwright未安装") + if playwright_launch_error: + await matcher.finish("Playwright启动失败,如果您已安装Chromium,请重启Bot") if not playwright: - if playwright_not_installed: - await matcher.finish("Playwright未安装") - if playwright_launch_error: - await matcher.finish("Playwright启动失败,如果您已安装Chromium,请重启Bot") try: from playwright.async_api import async_playwright, Error playwright = await async_playwright().start() if not browser: try: browser = await playwright.chromium.launch() - except Error: - await matcher.finish("Playwright启动失败,请检查是否安装了Chromium") + except Error as e: + playwright_launch_error = True logger.warning("Playwright启动失败,请检查是否安装了Chromium\n" "安装方法:在bot的虚拟环境中执行:playwright install chromium") - playwright_launch_error = True + logger.warning("注意:对于无头服务器,您可能需要使用系统的包管理器安装完整版的Chromium以保证系统中有可用的依赖\n" + "例如:在Ubuntu 20.04中,您可以使用apt安装:sudo apt install chromium-browser\n" + "在Archlinux中,您可以使用pacman安装:sudo pacman -S chromium") + logger.warning(f"下面是Playwright的错误信息,可能对您有帮助:\n{e}") + await matcher.finish("Playwright启动失败,请检查是否安装了Chromium") except ImportError: - await matcher.finish("Playwright未安装") playwright_not_installed = True + await matcher.finish("Playwright未安装") title = message[9:].lstrip() if not title: diff --git a/pyproject.toml b/pyproject.toml index 77585a5..35d1433 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nonebot-plugin-mediawiki" -version = "1.1.0-alpha.1" +version = "1.1.0-alpha.2" description = "nonebot2 mediawiki 查询插件" authors = ["KoishiMoe <68314080+KoishiMoe@users.noreply.github.com>"] license = "AGPL-3.0-or-later"