pErithacus 是一个基于 NoneBot2 框架的聊天插件,可以根据用户设定的关键词自动回复相关内容。该插件提供了完整的词条管理功能,让用户能够轻松创建、编辑和管理自定义回复内容
Project description
简介
pErithacus 是一个基于 NoneBot2 框架的聊天插件,可以根据用户设定的关键词自动回复相关内容。该插件提供了完整的词条管理功能,让用户能够轻松创建、编辑和管理自定义回复内容。 pErithacus,名称来自灰鹦鹉(Psittacus erithacus),具有极强的语言模仿能力
功能特性
- 📝 词条管理:添加、删除、修改、查看词条
- 🔍 多种匹配模式:支持精准匹配、模糊匹配和正则表达式匹配
- ⏰ 定时触发:支持使用 cron 表达式设置定时自动触发回复
- 🎲 随机回复:可设置多个回复内容并随机选择
- 🌐 作用域管理:支持按群组或私聊会话分别管理不同的词条
- 🔗 别名词条:可以为词条设置别名,增加使用的灵活性
安装方法
使用 nb-cli 安装(尚未实现)
在 nonebot2 项目的根目录下打开命令行, 输入以下指令即可安装nb plugin install nonebot-plugin-pErithacus --upgrade
使用 pypi 源安装
nb plugin install nonebot-plugin-pErithacus --upgrade -i "https://pypi.org/simple"
使用清华源安装
nb plugin install nonebot-plugin-pErithacus --upgrade -i "https://pypi.tuna.tsinghua.edu.cn/simple"
使用包管理器安装
在 nonebot2 项目的插件目录下, 打开命令行, 根据你使用的包管理器, 输入相应的安装命令pip
pip install nonebot-plugin-pErithacus
uv
uv add nonebot-plugin-pErithacus
安装仓库 master 分支
uv add git+https://github.com/SnowMoonSS/nonebot-plugin-pErithacus@master
pdm
pdm add nonebot-plugin-pErithacus
安装仓库 master 分支
pdm add git+https://github.com/SnowMoonSS/nonebot-plugin-pErithacus@master
poetry
poetry add nonebot-plugin-pErithacus
安装仓库 master 分支
poetry add git+https://github.com/SnowMoonSS/nonebot-plugin-pErithacus@master
打开 nonebot2 项目根目录下的 pyproject.toml 文件, 在 [tool.nonebot] 部分追加写入
plugins = ["nonebot_plugin_perithacus"]
使用 nbr 安装(使用 uv 管理依赖可用)
nbr 是一个基于 uv 的 nb-cli,可以方便地管理 nonebot2
nbr plugin install nonebot-plugin-pErithacus
使用 pypi 源安装
nbr plugin install nonebot-plugin-pErithacus -i "https://pypi.org/simple"
使用清华源安装
nbr plugin install nonebot-plugin-pErithacus -i "https://pypi.tuna.tsinghua.edu.cn/simple"
🎉 使用
第一次启动
第一次启动时可能收到如下提示:
nonebot_plugin_orm.exception.AutogenerateDiffsDetected: 检测到新的升级操作:
......
......
在控制台输入 nb orm revision 生成升级脚本,之后输入 nb orm upgrade 升级数据库。
基本命令
pe <子命令> [选项...] [参数...]
发送 pe --help 查看详细的命令帮助信息。详情可查看command.py
add | 添加
添加新的词条到系统中。
语法:
pe add <关键词> <回复内容> [选项...]
参数:
关键词: 要匹配的关键词回复内容: 当匹配成功时回复的内容
选项:
-m,--match: 匹配方式(精准/模糊),默认为"精准"。-r,--random: 是否随机回复,默认为True。为否时回复为最后添加的内容。-c,--cron: 定时触发的cron表达式,默认为空。详见CRON 表达式-s,--scope: 作用域。该参数配合<关键词>进行词条查询,默认为当前会话所在作用域。指定作用域时,将会根据指定作用域对应的词条,并向其添加作用域。详见作用域。-R,--reg: 正则匹配的正则表达式,默认为空。当存在正则表达式时,将不会进行模糊匹配。-a,--alias: 为词条添加别名,默认为空。一次只能添加一个别名。
说明: 插件会先从数据库中查找已有词条。排除已删除的,根据已有的匹配方式、正则表达式在当前会话所在作用域或指定的作用域中匹配。 如果匹配到多条词条,将只会为最近修改过的词条进行操作。
del | 删除
删除指定的词条。
语法:
pe del <关键词> [选项]
参数:
关键词: 要删除的词条关键词
选项:
-s,--scope: 作用域,默认为当前会话所在的作用域。详见作用域
说明: 从作用域中删除指定的词条。未指定作用域时,删除当前会话所在的作用域。 若删除后不存在作用域,将在数据库中标记为已删除状态。
list
列出所有词条或指定词条的详细内容。
语法:
pe list [页码] [选项...]
参数:
页码(可选): 列出指定页的词条。默认为1。
选项:
-s,--scope: 列出指定作用域的词条。默认为当前会话所在作用域。详见作用域-a,--all: 列出所有词条。默认为False。
search | 搜索
根据关键词搜索相关的词条。
语法:
pe search <关键词> [页码] [选项...]
参数:
关键词: 搜索关键词页码(可选): 列出指定页的词条。默认为1。
选项:
-s,--scope: 列出指定作用域的词条。默认为当前会话所在作用域。详见作用域-a,--all: 列出所有词条。默认为False。
check | 查看
查看指定词条的配置信息。
语法:
pe check <词条ID> [选项]
参数:
词条ID: 要查看的词条ID
选项:
-f,--force: 强制查看已被标记为删除的词条
detail | 详情
查看指定词条的详细内容。
语法:
pe detail <词条ID> [页码] [选项...]
参数:
词条ID: 要查看的词条ID页码(可选): 列出指定页的词条。默认为1。
选项:
-f,--force: 强制查看已被标记为删除的词条
edit | 修改
修改已有词条的配置。
语法:
pe edit <关键词> [选项...]
参数:
关键词: 要修改的词条关键词
选项:
-r,--random: 修改当前的回复模式(True/False)。-m,--match: 修改当前的匹配方式(精准/模糊)。-c,--cron: 替换当前的cron表达式。详见CRON 表达式-s,--scope: 作用域。该参数配合<关键词>进行词条查询,默认为当前会话所在作用域。指定作用域时,将会根据指定作用域对应的词条,并向其添加作用域。详见作用域-R,--regex: 修改正则匹配的正则表达式。当存在正则表达式时,将不会进行模糊匹配。-a,--alias: 为词条添加别名。一次只能添加一个别名。-d,--delete: 删除指定ID的回复内容-rep,--replace: 替换指定ID的回复内容<内容ID>: 要替换的回复内容ID<内容>: 替换为的内容
说明:
插件会先从数据库中查找已有词条。排除已删除的,根据已有的匹配方式、正则表达式在当前会话所在作用域或指定的作用域中匹配。
如果匹配到多条词条,将只会为最近修改过的词条进行操作。
要对作用域进行缩减,使用del命令
匹配方式
精准匹配
消息内容必须与关键词完全一致才会触发回复。
模糊匹配
消息内容包含关键词即可触发回复。
正则匹配
消息内容符合指定的正则表达式才会触发回复。当存在正则表达式时,将不会进行模糊匹配。
CRON 表达式
定时任务使用标准的 cron 表达式格式,以#进行分割:
分 时 日 月 周
例如:0#0#8#*#*#* 表示每天上午8点触发
可根据crontab guru编写cron表达式。添加定时消息时记得用#替换掉空格。
作用域
作用域用于控制词条的有效范围:
- 以
g开头表示群组作用域,如g123456 - 以
u开头表示私聊作用域,如u123456 - 多个作用域使用
,进行分割,如g123456,u123456
示例
添加一条简单的问候语:
pe add hello 你好!
添加每日定时提醒,每天早上9点发送消息:
pe add 晨报 新的一天开始了! -c 0#9#*#*#*
添加带模糊匹配的词条:
pe add 笑话 这是一个有趣的笑话 -m 模糊
查看当前作用域的所有未删除词条:
pe list
查看词库所有未删除的词条:
pe list -a
搜索相关词条:
pe search 笑话
数据存储
数据存储在 nonebot-plugin-localstore 定义的 data 目录下。
在不同的操作系统中,数据存储路径不同:
- macOS: ~/Library/Application Support/nonebot2
- Unix: ~/.local/share/nonebot2 or in $XDG_DATA_HOME, if defined
- Win XP (not roaming): C:\Documents and Settings<username>\Application Data\nonebot2
- Win 7 (not roaming): C:\Users<username>\AppData\Local\nonebot2
可在.env文件中添加LOCALSTORE_USE_CWD = True使其保存在当前工作目录下
已知的问题
- 没有删除别名的方法
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nonebot_plugin_perithacus-1.1.5.tar.gz.
File metadata
- Download URL: nonebot_plugin_perithacus-1.1.5.tar.gz
- Upload date:
- Size: 21.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
595bb0854f29ebf634793f95275dd8007bff6d7022c93ba4ae64eafb05a595bf
|
|
| MD5 |
e6bc9cdd922674ac3dc5b3c844231824
|
|
| BLAKE2b-256 |
6e53fffe00f21e4503a06511c09c0055459fe14027278358c0218b4a429b6bae
|
Provenance
The following attestation bundles were made for nonebot_plugin_perithacus-1.1.5.tar.gz:
Publisher:
python-publish.yml on SnowMoonSS/nonebot-plugin-pErithacus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nonebot_plugin_perithacus-1.1.5.tar.gz -
Subject digest:
595bb0854f29ebf634793f95275dd8007bff6d7022c93ba4ae64eafb05a595bf - Sigstore transparency entry: 760285949
- Sigstore integration time:
-
Permalink:
SnowMoonSS/nonebot-plugin-pErithacus@fc5dd5b70d3d0f80e09887b397220d591b34c87e -
Branch / Tag:
refs/tags/v1.1.5 - Owner: https://github.com/SnowMoonSS
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@fc5dd5b70d3d0f80e09887b397220d591b34c87e -
Trigger Event:
release
-
Statement type:
File details
Details for the file nonebot_plugin_perithacus-1.1.5-py3-none-any.whl.
File metadata
- Download URL: nonebot_plugin_perithacus-1.1.5-py3-none-any.whl
- Upload date:
- Size: 31.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7efcd6a925d5e409688cf7625c0159863feb5990c5693a429db683c598bf92b9
|
|
| MD5 |
5da3d950cced6db6148e0862f5b350f9
|
|
| BLAKE2b-256 |
96e7bf01b37dfdf64c6e70a948d4eaaefc03d8c9871107b203aa8fa738d5a8c0
|
Provenance
The following attestation bundles were made for nonebot_plugin_perithacus-1.1.5-py3-none-any.whl:
Publisher:
python-publish.yml on SnowMoonSS/nonebot-plugin-pErithacus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nonebot_plugin_perithacus-1.1.5-py3-none-any.whl -
Subject digest:
7efcd6a925d5e409688cf7625c0159863feb5990c5693a429db683c598bf92b9 - Sigstore transparency entry: 760285950
- Sigstore integration time:
-
Permalink:
SnowMoonSS/nonebot-plugin-pErithacus@fc5dd5b70d3d0f80e09887b397220d591b34c87e -
Branch / Tag:
refs/tags/v1.1.5 - Owner: https://github.com/SnowMoonSS
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@fc5dd5b70d3d0f80e09887b397220d591b34c87e -
Trigger Event:
release
-
Statement type: