群内自助进行基于《周易》的起卦、查卦与解卦的 NoneBot2 插件
Project description
nonebot-plugin-yijing
基于《周易》的 NoneBot2 群聊起卦、查卦、解卦与图片化输出插件。
当前版本是可运行的 Alpha 工程:命令、ORM、权限、HTML 长图渲染、资料库结构与种子数据已经接通;经传全文仍在持续校勘补录。
介绍
nonebot-plugin-yijing 面向 OneBot V11 群聊场景,提供群内自助起卦、查询、历史记录与解读输出。插件将交互结果统一渲染为图片,便于在 QQ 群等聊天环境中展示。
插件支持本地规则解读,并可选接入 OpenAI 兼容 LLM,用于问题预处理、三不占判断、近期历史对照与综合解读。LLM 失败时会自动降级到本地逻辑,不阻塞核心起卦流程。
功能
- 使用
nonebot-plugin-alconna解析命令。 - 使用
nonebot-plugin-orm[sqlite]+ SQLite 存储历史、配置、限额与冷却。 - 使用
nonebot-plugin-htmlrender将帮助、起卦、查卦、历史等输出渲染为图片。 - 使用
nonebot-plugin-access-control与nonebot-plugin-access-control-api管理插件级和功能级权限。 - 支持三枚铜钱法、大衍筮法概率模拟、手动输入与随机一卦。
- 起卦记录包含时间信息,可用于冷却、日限额与短期相似问题判断。
- 资料库预留完整经传、关系、来源、起卦规则、解读规则与后续术数扩展字段。
安装
使用 nb-cli
nb plugin install nonebot-plugin-yijing
使用包管理器
pip install nonebot-plugin-yijing
开发目录安装:
pip install -e .
从 GitHub 指定提交安装,适合 Alpha 服务器验证:
pip install "nonebot-plugin-yijing @ git+ssh://git@github.com/newcovid/nonebot-plugin-yijing.git@<commit-sha>"
在 NoneBot 项目中加载
nonebot.load_plugin("nonebot_plugin_yijing")
或在 pyproject.toml 中配置:
[tool.nonebot]
plugins = ["nonebot_plugin_yijing"]
依赖
基础依赖会随插件安装。若需要在现有项目中显式补齐依赖,可执行:
pip install "nonebot-plugin-orm[sqlite]" nonebot-plugin-alconna nonebot-plugin-htmlrender
pip install nonebot-plugin-access-control nonebot-plugin-access-control-api
本插件当前保留 nonebot-adapter-onebot 作为硬依赖,因为发布目标主要是 OneBot V11 群聊环境。
ORM 初始化
首次使用或升级后执行:
nb orm upgrade
nb orm check
不建议在常规配置中默认关闭 ORM 启动检查。只有在本地临时排查迁移问题时,才可短暂加入:
ALEMBIC_STARTUP_CHECK=false
排查结束后应移除该配置,并重新执行 nb orm upgrade 与 nb orm check。
配置
基础配置
SQLALCHEMY_DATABASE_URL=sqlite+aiosqlite:///./data/yijing.sqlite3
ACCESS_CONTROL_AUTO_PATCH_ENABLED=true
ACCESS_CONTROL_REPLY_ON_PERMISSION_DENIED_ENABLED=true
ACCESS_CONTROL_REPLY_ON_RATE_LIMITED_ENABLED=true
YIJING_DEFAULT_METHOD=coin
YIJING_POSITIVE_FACE=正
YIJING_NEGATIVE_FACE=反
YIJING_POSITIVE_VALUE=3
YIJING_NEGATIVE_VALUE=2
YIJING_GROUP_DEFAULT_ENABLED=true
YIJING_COOLDOWN_SECONDS=60
YIJING_DAILY_LIMIT_PER_USER=10
YIJING_DUPLICATE_WINDOW_MINUTES=30
YIJING_STORE_QUESTION=true
YIJING_LLM_ENABLED=false
# YIJING_LLM_BASE_URL=https://api.openai.com/v1
# YIJING_LLM_API_KEY=sk-xxx
# YIJING_LLM_MODEL=gpt-4o-mini
htmlrender / Playwright
本插件以 nonebot-plugin-htmlrender>=0.7.1 为基线。推荐本地开发配置:
RENDER_BACKEND=playwright
RENDER_STARTUP_MODE=probe
RENDER_PLAYWRIGHT={"engine":"chromium","skip_browser_install":false,"close_on_exit":true,"launch_args":"--no-sandbox --disable-dev-shm-usage --disable-gpu"}
生产 Docker 环境如果在镜像构建阶段把 Playwright Chromium 安装到 /ms-playwright,推荐:
RENDER_BACKEND=playwright
RENDER_STARTUP_MODE=probe
RENDER_STORAGE_PATH=/ms-playwright
RENDER_PLAYWRIGHT={"engine":"chromium","skip_browser_install":true,"close_on_exit":true,"cleanup_legacy_cache":true,"launch_args":"--no-sandbox --disable-dev-shm-usage --disable-gpu"}
这种部署方式要求 Dockerfile 或镜像构建脚本确实把 Chromium 安装到了 /ms-playwright。如果没有预装浏览器,不要设置 skip_browser_install=true。
使用
命令
| 命令 | 说明 |
|---|---|
易经帮助 |
查看帮助长图 |
起卦 问题 |
默认三枚铜钱法起卦并解卦 |
起卦 问题 铜钱 |
精确指定铜钱法 |
起卦 问题 大衍 |
使用大衍筮法概率模拟 |
起卦 问题 手动 |
进入手动起卦引导 |
解卦 卦象 |
查询/解释指定卦象 |
易经历史 |
查看自己的历史记录 |
易经记录 ID |
查看指定记录 |
随机一卦 |
随机生成一个观察主题 |
易经设置 |
查看或修改本群配置 |
手动铜钱输入
铜钱法必须自下而上输入 6 组,每组 3 个正/反:
正反正 反反正 正正反 正反反 反正正 反反反
手动大衍输入
大衍法可以自下而上输入 6 个爻值:
7 8 9 6 7 8
其中:
6:老阴,动爻,阴变阳。7:少阳,静爻。8:少阴,静爻。9:老阳,动爻,阳变阴。
权限控制
本插件通过 nonebot-plugin-access-control-api 注册以下服务:
nonebot_plugin_yijing
nonebot_plugin_yijing.cast
nonebot_plugin_yijing.query
nonebot_plugin_yijing.history
nonebot_plugin_yijing.settings
nonebot_plugin_yijing.random
nonebot_plugin_yijing.manual
示例:禁用某群的起卦功能,但保留查卦:
/ac permission deny --sbj qq:g123456789 --srv nonebot_plugin_yijing.cast
/ac permission allow --sbj qq:g123456789 --srv nonebot_plugin_yijing.query
资料库
资料库位于 nonebot_plugin_yijing/data/,结构说明见 nonebot_plugin_yijing/data/README.md。
当前内置完整项:八卦、六十四卦、六爻骨架、卦辞、卦关系、起卦规则、解读规则。
当前种子经文:乾、坤、需的爻辞/象传较完整;其余卦的爻辞、彖传、文言、系辞等字段先以结构化占位保留,等待后续校勘补录。
LLM 预处理、解读与隐私
启用 LLM 后,起卦 问题 会在真正起卦前执行预处理:
- 判断问题是否明确。
- 判断是否违反“不诚不占、不义不占、不疑不占”。
- 对照参数化历史记录,识别短期重复或相似问题。
- 标注医疗、法律、投资、人身安全等敏感领域。
LLM 接口为 OpenAI 兼容 /chat/completions,失败会自动降级到本地规则,不阻塞起卦核心流程。
隐私注意事项:
YIJING_LLM_ENABLED=false时,LLM 不会被调用。- 开启 LLM 后,用户问题、卦象资料、预处理字段,以及按配置选取的近期历史记录,可能会发送给你配置的第三方模型服务商。
YIJING_STORE_QUESTION=true会在数据库中保存原始问题文本,便于历史回看和相似问题判断。- 若希望降低存储敏感内容的风险,可设置
YIJING_STORE_QUESTION=false。此时历史记录会保留卦象和结构化结果,但原始问题文本不会保存。 - 本插件只提供本地降级逻辑,不代理或改变第三方模型服务商的数据处理规则。请按实际接入的模型服务商补充群公告或隐私说明。
开发
python -m pip install -e ".[dev]"
ruff check .
python -m compileall nonebot_plugin_yijing
pytest -q
python -m build --sdist --wheel .
twine check dist/*
更多文档
docs/server-smoke-test.md:服务器升级、包安装、真实群聊命令验收清单。docs/data-collation.md:经传资料库补录、来源、状态与校勘流程。docs/release.md:构建、验包、发布、服务器验证与 PyPI 发布流程。
许可证
本项目使用 MIT License。详见 LICENSE。
免责声明
本插件用于传统文化学习、文本解释与群聊娱乐,不提供确定性预测,不构成医疗、法律、投资、安全或其他专业建议。
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
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_yijing-0.1.2.tar.gz.
File metadata
- Download URL: nonebot_plugin_yijing-0.1.2.tar.gz
- Upload date:
- Size: 60.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb093b03b932d7ae134cfe7a2014a98183b07b8d4addc1b6888979c42141db9e
|
|
| MD5 |
9170e0cfc4d53017103d95b7c6a71f32
|
|
| BLAKE2b-256 |
e0f02b2f37aad6d93e897134999325f5adfd0c8ed69daac386ba5c909e22fc29
|
Provenance
The following attestation bundles were made for nonebot_plugin_yijing-0.1.2.tar.gz:
Publisher:
publish.yml on newcovid/nonebot-plugin-yijing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nonebot_plugin_yijing-0.1.2.tar.gz -
Subject digest:
fb093b03b932d7ae134cfe7a2014a98183b07b8d4addc1b6888979c42141db9e - Sigstore transparency entry: 2125937725
- Sigstore integration time:
-
Permalink:
newcovid/nonebot-plugin-yijing@abfc339cf8a7966be91914d541ba5d01bc9b8864 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/newcovid
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@abfc339cf8a7966be91914d541ba5d01bc9b8864 -
Trigger Event:
push
-
Statement type:
File details
Details for the file nonebot_plugin_yijing-0.1.2-py3-none-any.whl.
File metadata
- Download URL: nonebot_plugin_yijing-0.1.2-py3-none-any.whl
- Upload date:
- Size: 69.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56f184e5405825833a78b259c5e8c166d698227ff7638751159c892803683aa8
|
|
| MD5 |
dcb2791a1bfd8d98d3f0575e0836b522
|
|
| BLAKE2b-256 |
c4eae71e992676acc8f3dff68692a7e638f7b46163f5b268c4c24db0a40d44a7
|
Provenance
The following attestation bundles were made for nonebot_plugin_yijing-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on newcovid/nonebot-plugin-yijing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nonebot_plugin_yijing-0.1.2-py3-none-any.whl -
Subject digest:
56f184e5405825833a78b259c5e8c166d698227ff7638751159c892803683aa8 - Sigstore transparency entry: 2125938139
- Sigstore integration time:
-
Permalink:
newcovid/nonebot-plugin-yijing@abfc339cf8a7966be91914d541ba5d01bc9b8864 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/newcovid
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@abfc339cf8a7966be91914d541ba5d01bc9b8864 -
Trigger Event:
push
-
Statement type: