Skip to main content

pErithacus 是一个基于 NoneBot2 框架的聊天插件,可以根据用户设定的关键词自动回复相关内容。该插件提供了完整的词条管理功能,让用户能够轻松创建、编辑和管理自定义回复内容

Project description

logo

✨ pErithacus ✨

LICENSE pypi python uv
ruff

简介

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nonebot_plugin_perithacus-1.1.3.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nonebot_plugin_perithacus-1.1.3-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

Details for the file nonebot_plugin_perithacus-1.1.3.tar.gz.

File metadata

File hashes

Hashes for nonebot_plugin_perithacus-1.1.3.tar.gz
Algorithm Hash digest
SHA256 c344e818060e3fb6ae0c59479e65149a0d4a5a2c5cfd1fd572b22a412572fb47
MD5 c842fb45fbf5af3fba7a1b9fbd99491d
BLAKE2b-256 36078484403cc3323f7d7754c83abd0e36a578b7679215dc95c740068acb546a

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonebot_plugin_perithacus-1.1.3.tar.gz:

Publisher: python-publish.yml on SnowMoonSS/nonebot-plugin-pErithacus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nonebot_plugin_perithacus-1.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for nonebot_plugin_perithacus-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b34c8fffe57b5e1f77fadb942b9f8c19480758d36015081f687a9fc439c68346
MD5 a5ac923d12fed8f41f6e3cbed3106023
BLAKE2b-256 f549513b34e3dc3ddb1663b67565c35dd126094358ff72e81d87e4544d423927

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonebot_plugin_perithacus-1.1.3-py3-none-any.whl:

Publisher: python-publish.yml on SnowMoonSS/nonebot-plugin-pErithacus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page