Skip to content

Commit

Permalink
fix: 修正部分提示信息
Browse files Browse the repository at this point in the history
  • Loading branch information
KoishiMoe committed Feb 18, 2023
1 parent 914ff2b commit 97a053a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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等敏感信息
* 攻击者可能会利用浏览器漏洞来入侵服务器
2 changes: 1 addition & 1 deletion nonebot_plugin_mediawiki/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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推送'
20 changes: 12 additions & 8 deletions nonebot_plugin_mediawiki/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "AGPL-3.0-or-later"
Expand Down

0 comments on commit 97a053a

Please sign in to comment.