nonebot-plugin-yijing 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nonebot_plugin_yijing-0.1.1/LICENSE +21 -0
- nonebot_plugin_yijing-0.1.1/PKG-INFO +294 -0
- nonebot_plugin_yijing-0.1.1/README.md +252 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/__init__.py +38 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/commands/__init__.py +3 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/commands/main.py +498 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/config.py +41 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/core/caster.py +103 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/core/data.py +243 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/core/hexagram.py +46 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/core/interpret.py +82 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/README.en.md +73 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/README.md +73 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/casting_rules.json +38 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/guaci.json +450 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/hexagrams.json +1218 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/interpret_rules.json +20 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/lines.json +2690 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/relations.json +1154 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/reserved_tables.json +10 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/schemas/casting_rules.schema.json +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/schemas/chapter_text.schema.json +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/schemas/guaci.schema.json +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/schemas/hexagrams.schema.json +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/schemas/interpret_rules.schema.json +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/schemas/lines.schema.json +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/schemas/manifest.json +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/schemas/relations.schema.json +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/schemas/sources.schema.json +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/schemas/special_texts.schema.json +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/schemas/trigrams.schema.json +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/schemas/tuan.schema.json +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/schemas/wenyan.schema.json +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/schemas/xiang.schema.json +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/schemas/yaoci.schema.json +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/shuogua.json +8 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/sources.json +24 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/special_texts.json +26 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/trigrams.json +114 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/tuan.json +450 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/wenyan.json +20 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/xiang.json +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/xici_shang.json +8 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/xici_xia.json +8 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/xugua.json +8 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/yaoci.json +3074 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/data/zagua.json +8 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/migrations/20260708_01_initial_yijing_tables.py +143 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/migrations/20260708_02_add_group_setting_windows.py +51 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/migrations/8f2b7c4a1d00_init_yijing.py +92 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/migrations/__init__.py +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/models.py +82 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/permissions.py +16 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/render/__init__.py +0 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/render/html.py +33 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/render/message.py +18 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/services/__init__.py +0 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/services/llm.py +142 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/services/payload.py +144 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/services/repository.py +200 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/templates/card.html +158 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/templates/help.html +2 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/templates/history.html +2 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/templates/notice.html +2 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/templates/settings.html +2 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing/utils.py +104 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing.egg-info/PKG-INFO +294 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing.egg-info/SOURCES.txt +83 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing.egg-info/dependency_links.txt +1 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing.egg-info/requires.txt +20 -0
- nonebot_plugin_yijing-0.1.1/nonebot_plugin_yijing.egg-info/top_level.txt +1 -0
- nonebot_plugin_yijing-0.1.1/pyproject.toml +76 -0
- nonebot_plugin_yijing-0.1.1/setup.cfg +4 -0
- nonebot_plugin_yijing-0.1.1/tests/test_casting.py +63 -0
- nonebot_plugin_yijing-0.1.1/tests/test_data_files.py +28 -0
- nonebot_plugin_yijing-0.1.1/tests/test_data_integrity.py +18 -0
- nonebot_plugin_yijing-0.1.1/tests/test_data_load.py +41 -0
- nonebot_plugin_yijing-0.1.1/tests/test_data_schema.py +98 -0
- nonebot_plugin_yijing-0.1.1/tests/test_hexagrams.py +33 -0
- nonebot_plugin_yijing-0.1.1/tests/test_lines.py +23 -0
- nonebot_plugin_yijing-0.1.1/tests/test_llm_schema.py +150 -0
- nonebot_plugin_yijing-0.1.1/tests/test_migrations.py +64 -0
- nonebot_plugin_yijing-0.1.1/tests/test_models.py +79 -0
- nonebot_plugin_yijing-0.1.1/tests/test_payload.py +97 -0
- nonebot_plugin_yijing-0.1.1/tests/test_resolve.py +39 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 YG W
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nonebot-plugin-yijing
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: 群内自助进行基于《周易》的起卦、查卦与解卦的 NoneBot2 插件
|
|
5
|
+
Author: YG W
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/newcovid/nonebot-plugin-yijing
|
|
8
|
+
Project-URL: Documentation, https://github.com/newcovid/nonebot-plugin-yijing#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/newcovid/nonebot-plugin-yijing
|
|
10
|
+
Project-URL: Issues, https://github.com/newcovid/nonebot-plugin-yijing/issues
|
|
11
|
+
Keywords: nonebot,nonebot2,yijing,iching,zhouyi,qqbot
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Framework :: AsyncIO
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: nonebot2>=2.5.0
|
|
23
|
+
Requires-Dist: nonebot-adapter-onebot>=2.3.0
|
|
24
|
+
Requires-Dist: nonebot-plugin-alconna>=0.50.0
|
|
25
|
+
Requires-Dist: nonebot-plugin-htmlrender>=0.7.1
|
|
26
|
+
Requires-Dist: nonebot-plugin-orm[sqlite]>=0.7.0
|
|
27
|
+
Requires-Dist: nonebot-plugin-localstore>=0.7.0
|
|
28
|
+
Requires-Dist: nonebot-plugin-access-control>=1.2.4
|
|
29
|
+
Requires-Dist: nonebot-plugin-access-control-api>=1.1.0
|
|
30
|
+
Requires-Dist: playwright>=1.60.0
|
|
31
|
+
Requires-Dist: aiohttp>=3.8.0
|
|
32
|
+
Requires-Dist: pydantic>=1.10.0
|
|
33
|
+
Requires-Dist: SQLAlchemy>=2.0.0
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: build>=1.2.0; extra == "dev"
|
|
36
|
+
Requires-Dist: nonebot2[fastapi]>=2.5.0; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
38
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
39
|
+
Requires-Dist: ruff>=0.8.0; extra == "dev"
|
|
40
|
+
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
|
|
43
|
+
# nonebot-plugin-yijing
|
|
44
|
+
|
|
45
|
+
[English](README.en.md)
|
|
46
|
+
|
|
47
|
+
基于《周易》的 NoneBot2 群聊起卦、查卦、解卦与图片化输出插件。
|
|
48
|
+
|
|
49
|
+
> 当前版本是可运行的 Alpha 工程:命令、ORM、权限、HTML 长图渲染、资料库结构与种子数据已经接通;经传全文仍在持续校勘补录。
|
|
50
|
+
|
|
51
|
+
## 介绍
|
|
52
|
+
|
|
53
|
+
`nonebot-plugin-yijing` 面向 OneBot V11 群聊场景,提供群内自助起卦、查询、历史记录与解读输出。插件将交互结果统一渲染为图片,便于在 QQ 群等聊天环境中展示。
|
|
54
|
+
|
|
55
|
+
插件支持本地规则解读,并可选接入 OpenAI 兼容 LLM,用于问题预处理、三不占判断、近期历史对照与综合解读。LLM 失败时会自动降级到本地逻辑,不阻塞核心起卦流程。
|
|
56
|
+
|
|
57
|
+
## 功能
|
|
58
|
+
|
|
59
|
+
- 使用 `nonebot-plugin-alconna` 解析命令。
|
|
60
|
+
- 使用 `nonebot-plugin-orm[sqlite]` + SQLite 存储历史、配置、限额与冷却。
|
|
61
|
+
- 使用 `nonebot-plugin-htmlrender` 将帮助、起卦、查卦、历史等输出渲染为图片。
|
|
62
|
+
- 使用 `nonebot-plugin-access-control` 与 `nonebot-plugin-access-control-api` 管理插件级和功能级权限。
|
|
63
|
+
- 支持三枚铜钱法、大衍筮法概率模拟、手动输入与随机一卦。
|
|
64
|
+
- 起卦记录包含时间信息,可用于冷却、日限额与短期相似问题判断。
|
|
65
|
+
- 资料库预留完整经传、关系、来源、起卦规则、解读规则与后续术数扩展字段。
|
|
66
|
+
|
|
67
|
+
## 安装
|
|
68
|
+
|
|
69
|
+
### 使用 nb-cli
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
nb plugin install nonebot-plugin-yijing
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 使用包管理器
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install nonebot-plugin-yijing
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
开发目录安装:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install -e .
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
从 GitHub 指定提交安装,适合 Alpha 服务器验证:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pip install "nonebot-plugin-yijing @ git+ssh://git@github.com/newcovid/nonebot-plugin-yijing.git@<commit-sha>"
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 在 NoneBot 项目中加载
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
nonebot.load_plugin("nonebot_plugin_yijing")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
或在 `pyproject.toml` 中配置:
|
|
100
|
+
|
|
101
|
+
```toml
|
|
102
|
+
[tool.nonebot]
|
|
103
|
+
plugins = ["nonebot_plugin_yijing"]
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## 依赖
|
|
107
|
+
|
|
108
|
+
基础依赖会随插件安装。若需要在现有项目中显式补齐依赖,可执行:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
pip install "nonebot-plugin-orm[sqlite]" nonebot-plugin-alconna nonebot-plugin-htmlrender
|
|
112
|
+
pip install nonebot-plugin-access-control nonebot-plugin-access-control-api
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
本插件当前保留 `nonebot-adapter-onebot` 作为硬依赖,因为发布目标主要是 OneBot V11 群聊环境。
|
|
116
|
+
|
|
117
|
+
## ORM 初始化
|
|
118
|
+
|
|
119
|
+
首次使用或升级后执行:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
nb orm upgrade
|
|
123
|
+
nb orm check
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
不建议在常规配置中默认关闭 ORM 启动检查。只有在本地临时排查迁移问题时,才可短暂加入:
|
|
127
|
+
|
|
128
|
+
```env
|
|
129
|
+
ALEMBIC_STARTUP_CHECK=false
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
排查结束后应移除该配置,并重新执行 `nb orm upgrade` 与 `nb orm check`。
|
|
133
|
+
|
|
134
|
+
## 配置
|
|
135
|
+
|
|
136
|
+
### 基础配置
|
|
137
|
+
|
|
138
|
+
```env
|
|
139
|
+
SQLALCHEMY_DATABASE_URL=sqlite+aiosqlite:///./data/yijing.sqlite3
|
|
140
|
+
|
|
141
|
+
ACCESS_CONTROL_AUTO_PATCH_ENABLED=true
|
|
142
|
+
ACCESS_CONTROL_REPLY_ON_PERMISSION_DENIED_ENABLED=true
|
|
143
|
+
ACCESS_CONTROL_REPLY_ON_RATE_LIMITED_ENABLED=true
|
|
144
|
+
|
|
145
|
+
YIJING_DEFAULT_METHOD=coin
|
|
146
|
+
YIJING_POSITIVE_FACE=正
|
|
147
|
+
YIJING_NEGATIVE_FACE=反
|
|
148
|
+
YIJING_POSITIVE_VALUE=3
|
|
149
|
+
YIJING_NEGATIVE_VALUE=2
|
|
150
|
+
YIJING_GROUP_DEFAULT_ENABLED=true
|
|
151
|
+
YIJING_COOLDOWN_SECONDS=60
|
|
152
|
+
YIJING_DAILY_LIMIT_PER_USER=10
|
|
153
|
+
YIJING_DUPLICATE_WINDOW_MINUTES=30
|
|
154
|
+
YIJING_STORE_QUESTION=true
|
|
155
|
+
|
|
156
|
+
YIJING_LLM_ENABLED=false
|
|
157
|
+
# YIJING_LLM_BASE_URL=https://api.openai.com/v1
|
|
158
|
+
# YIJING_LLM_API_KEY=sk-xxx
|
|
159
|
+
# YIJING_LLM_MODEL=gpt-4o-mini
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### htmlrender / Playwright
|
|
163
|
+
|
|
164
|
+
本插件以 `nonebot-plugin-htmlrender>=0.7.1` 为基线。推荐本地开发配置:
|
|
165
|
+
|
|
166
|
+
```env
|
|
167
|
+
RENDER_BACKEND=playwright
|
|
168
|
+
RENDER_STARTUP_MODE=probe
|
|
169
|
+
RENDER_PLAYWRIGHT={"engine":"chromium","skip_browser_install":false,"close_on_exit":true,"launch_args":"--no-sandbox --disable-dev-shm-usage --disable-gpu"}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
生产 Docker 环境如果在镜像构建阶段把 Playwright Chromium 安装到 `/ms-playwright`,推荐:
|
|
173
|
+
|
|
174
|
+
```env
|
|
175
|
+
RENDER_BACKEND=playwright
|
|
176
|
+
RENDER_STARTUP_MODE=probe
|
|
177
|
+
RENDER_STORAGE_PATH=/ms-playwright
|
|
178
|
+
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"}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
这种部署方式要求 Dockerfile 或镜像构建脚本确实把 Chromium 安装到了 `/ms-playwright`。如果没有预装浏览器,不要设置 `skip_browser_install=true`。
|
|
182
|
+
|
|
183
|
+
## 使用
|
|
184
|
+
|
|
185
|
+
### 命令
|
|
186
|
+
|
|
187
|
+
| 命令 | 说明 |
|
|
188
|
+
| --- | --- |
|
|
189
|
+
| `易经帮助` | 查看帮助长图 |
|
|
190
|
+
| `起卦 问题` | 默认三枚铜钱法起卦并解卦 |
|
|
191
|
+
| `起卦 问题 铜钱` | 精确指定铜钱法 |
|
|
192
|
+
| `起卦 问题 大衍` | 使用大衍筮法概率模拟 |
|
|
193
|
+
| `起卦 问题 手动` | 进入手动起卦引导 |
|
|
194
|
+
| `解卦 卦象` | 查询/解释指定卦象 |
|
|
195
|
+
| `易经历史` | 查看自己的历史记录 |
|
|
196
|
+
| `易经记录 ID` | 查看指定记录 |
|
|
197
|
+
| `随机一卦` | 随机生成一个观察主题 |
|
|
198
|
+
| `易经设置` | 查看或修改本群配置 |
|
|
199
|
+
|
|
200
|
+
### 手动铜钱输入
|
|
201
|
+
|
|
202
|
+
铜钱法必须自下而上输入 6 组,每组 3 个正/反:
|
|
203
|
+
|
|
204
|
+
```text
|
|
205
|
+
正反正 反反正 正正反 正反反 反正正 反反反
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### 手动大衍输入
|
|
209
|
+
|
|
210
|
+
大衍法可以自下而上输入 6 个爻值:
|
|
211
|
+
|
|
212
|
+
```text
|
|
213
|
+
7 8 9 6 7 8
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
其中:
|
|
217
|
+
|
|
218
|
+
- `6`:老阴,动爻,阴变阳。
|
|
219
|
+
- `7`:少阳,静爻。
|
|
220
|
+
- `8`:少阴,静爻。
|
|
221
|
+
- `9`:老阳,动爻,阳变阴。
|
|
222
|
+
|
|
223
|
+
## 权限控制
|
|
224
|
+
|
|
225
|
+
本插件通过 `nonebot-plugin-access-control-api` 注册以下服务:
|
|
226
|
+
|
|
227
|
+
```text
|
|
228
|
+
nonebot_plugin_yijing
|
|
229
|
+
nonebot_plugin_yijing.cast
|
|
230
|
+
nonebot_plugin_yijing.query
|
|
231
|
+
nonebot_plugin_yijing.history
|
|
232
|
+
nonebot_plugin_yijing.settings
|
|
233
|
+
nonebot_plugin_yijing.random
|
|
234
|
+
nonebot_plugin_yijing.manual
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
示例:禁用某群的起卦功能,但保留查卦:
|
|
238
|
+
|
|
239
|
+
```text
|
|
240
|
+
/ac permission deny --sbj qq:g123456789 --srv nonebot_plugin_yijing.cast
|
|
241
|
+
/ac permission allow --sbj qq:g123456789 --srv nonebot_plugin_yijing.query
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## 资料库
|
|
245
|
+
|
|
246
|
+
资料库位于 `nonebot_plugin_yijing/data/`,结构说明见 [`nonebot_plugin_yijing/data/README.md`](nonebot_plugin_yijing/data/README.md)。
|
|
247
|
+
|
|
248
|
+
当前内置完整项:八卦、六十四卦、六爻骨架、卦辞、卦关系、起卦规则、解读规则。
|
|
249
|
+
|
|
250
|
+
当前种子经文:乾、坤、需的爻辞/象传较完整;其余卦的爻辞、彖传、文言、系辞等字段先以结构化占位保留,等待后续校勘补录。
|
|
251
|
+
|
|
252
|
+
## LLM 预处理、解读与隐私
|
|
253
|
+
|
|
254
|
+
启用 LLM 后,`起卦 问题` 会在真正起卦前执行预处理:
|
|
255
|
+
|
|
256
|
+
- 判断问题是否明确。
|
|
257
|
+
- 判断是否违反“不诚不占、不义不占、不疑不占”。
|
|
258
|
+
- 对照参数化历史记录,识别短期重复或相似问题。
|
|
259
|
+
- 标注医疗、法律、投资、人身安全等敏感领域。
|
|
260
|
+
|
|
261
|
+
LLM 接口为 OpenAI 兼容 `/chat/completions`,失败会自动降级到本地规则,不阻塞起卦核心流程。
|
|
262
|
+
|
|
263
|
+
隐私注意事项:
|
|
264
|
+
|
|
265
|
+
- `YIJING_LLM_ENABLED=false` 时,LLM 不会被调用。
|
|
266
|
+
- 开启 LLM 后,用户问题、卦象资料、预处理字段,以及按配置选取的近期历史记录,可能会发送给你配置的第三方模型服务商。
|
|
267
|
+
- `YIJING_STORE_QUESTION=true` 会在数据库中保存原始问题文本,便于历史回看和相似问题判断。
|
|
268
|
+
- 若希望降低存储敏感内容的风险,可设置 `YIJING_STORE_QUESTION=false`。此时历史记录会保留卦象和结构化结果,但原始问题文本不会保存。
|
|
269
|
+
- 本插件只提供本地降级逻辑,不代理或改变第三方模型服务商的数据处理规则。请按实际接入的模型服务商补充群公告或隐私说明。
|
|
270
|
+
|
|
271
|
+
## 开发
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
python -m pip install -e ".[dev]"
|
|
275
|
+
ruff check .
|
|
276
|
+
python -m compileall nonebot_plugin_yijing
|
|
277
|
+
pytest -q
|
|
278
|
+
python -m build --sdist --wheel .
|
|
279
|
+
twine check dist/*
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
## 更多文档
|
|
283
|
+
|
|
284
|
+
- [`docs/server-smoke-test.md`](docs/server-smoke-test.md):服务器升级、包安装、真实群聊命令验收清单。
|
|
285
|
+
- [`docs/data-collation.md`](docs/data-collation.md):经传资料库补录、来源、状态与校勘流程。
|
|
286
|
+
- [`docs/release.md`](docs/release.md):构建、验包、发布、服务器验证与 PyPI 发布流程。
|
|
287
|
+
|
|
288
|
+
## 许可证
|
|
289
|
+
|
|
290
|
+
本项目使用 MIT License。详见 [`LICENSE`](LICENSE)。
|
|
291
|
+
|
|
292
|
+
## 免责声明
|
|
293
|
+
|
|
294
|
+
本插件用于传统文化学习、文本解释与群聊娱乐,不提供确定性预测,不构成医疗、法律、投资、安全或其他专业建议。
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# nonebot-plugin-yijing
|
|
2
|
+
|
|
3
|
+
[English](README.en.md)
|
|
4
|
+
|
|
5
|
+
基于《周易》的 NoneBot2 群聊起卦、查卦、解卦与图片化输出插件。
|
|
6
|
+
|
|
7
|
+
> 当前版本是可运行的 Alpha 工程:命令、ORM、权限、HTML 长图渲染、资料库结构与种子数据已经接通;经传全文仍在持续校勘补录。
|
|
8
|
+
|
|
9
|
+
## 介绍
|
|
10
|
+
|
|
11
|
+
`nonebot-plugin-yijing` 面向 OneBot V11 群聊场景,提供群内自助起卦、查询、历史记录与解读输出。插件将交互结果统一渲染为图片,便于在 QQ 群等聊天环境中展示。
|
|
12
|
+
|
|
13
|
+
插件支持本地规则解读,并可选接入 OpenAI 兼容 LLM,用于问题预处理、三不占判断、近期历史对照与综合解读。LLM 失败时会自动降级到本地逻辑,不阻塞核心起卦流程。
|
|
14
|
+
|
|
15
|
+
## 功能
|
|
16
|
+
|
|
17
|
+
- 使用 `nonebot-plugin-alconna` 解析命令。
|
|
18
|
+
- 使用 `nonebot-plugin-orm[sqlite]` + SQLite 存储历史、配置、限额与冷却。
|
|
19
|
+
- 使用 `nonebot-plugin-htmlrender` 将帮助、起卦、查卦、历史等输出渲染为图片。
|
|
20
|
+
- 使用 `nonebot-plugin-access-control` 与 `nonebot-plugin-access-control-api` 管理插件级和功能级权限。
|
|
21
|
+
- 支持三枚铜钱法、大衍筮法概率模拟、手动输入与随机一卦。
|
|
22
|
+
- 起卦记录包含时间信息,可用于冷却、日限额与短期相似问题判断。
|
|
23
|
+
- 资料库预留完整经传、关系、来源、起卦规则、解读规则与后续术数扩展字段。
|
|
24
|
+
|
|
25
|
+
## 安装
|
|
26
|
+
|
|
27
|
+
### 使用 nb-cli
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
nb plugin install nonebot-plugin-yijing
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 使用包管理器
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install nonebot-plugin-yijing
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
开发目录安装:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install -e .
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
从 GitHub 指定提交安装,适合 Alpha 服务器验证:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install "nonebot-plugin-yijing @ git+ssh://git@github.com/newcovid/nonebot-plugin-yijing.git@<commit-sha>"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 在 NoneBot 项目中加载
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
nonebot.load_plugin("nonebot_plugin_yijing")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
或在 `pyproject.toml` 中配置:
|
|
58
|
+
|
|
59
|
+
```toml
|
|
60
|
+
[tool.nonebot]
|
|
61
|
+
plugins = ["nonebot_plugin_yijing"]
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 依赖
|
|
65
|
+
|
|
66
|
+
基础依赖会随插件安装。若需要在现有项目中显式补齐依赖,可执行:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install "nonebot-plugin-orm[sqlite]" nonebot-plugin-alconna nonebot-plugin-htmlrender
|
|
70
|
+
pip install nonebot-plugin-access-control nonebot-plugin-access-control-api
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
本插件当前保留 `nonebot-adapter-onebot` 作为硬依赖,因为发布目标主要是 OneBot V11 群聊环境。
|
|
74
|
+
|
|
75
|
+
## ORM 初始化
|
|
76
|
+
|
|
77
|
+
首次使用或升级后执行:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
nb orm upgrade
|
|
81
|
+
nb orm check
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
不建议在常规配置中默认关闭 ORM 启动检查。只有在本地临时排查迁移问题时,才可短暂加入:
|
|
85
|
+
|
|
86
|
+
```env
|
|
87
|
+
ALEMBIC_STARTUP_CHECK=false
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
排查结束后应移除该配置,并重新执行 `nb orm upgrade` 与 `nb orm check`。
|
|
91
|
+
|
|
92
|
+
## 配置
|
|
93
|
+
|
|
94
|
+
### 基础配置
|
|
95
|
+
|
|
96
|
+
```env
|
|
97
|
+
SQLALCHEMY_DATABASE_URL=sqlite+aiosqlite:///./data/yijing.sqlite3
|
|
98
|
+
|
|
99
|
+
ACCESS_CONTROL_AUTO_PATCH_ENABLED=true
|
|
100
|
+
ACCESS_CONTROL_REPLY_ON_PERMISSION_DENIED_ENABLED=true
|
|
101
|
+
ACCESS_CONTROL_REPLY_ON_RATE_LIMITED_ENABLED=true
|
|
102
|
+
|
|
103
|
+
YIJING_DEFAULT_METHOD=coin
|
|
104
|
+
YIJING_POSITIVE_FACE=正
|
|
105
|
+
YIJING_NEGATIVE_FACE=反
|
|
106
|
+
YIJING_POSITIVE_VALUE=3
|
|
107
|
+
YIJING_NEGATIVE_VALUE=2
|
|
108
|
+
YIJING_GROUP_DEFAULT_ENABLED=true
|
|
109
|
+
YIJING_COOLDOWN_SECONDS=60
|
|
110
|
+
YIJING_DAILY_LIMIT_PER_USER=10
|
|
111
|
+
YIJING_DUPLICATE_WINDOW_MINUTES=30
|
|
112
|
+
YIJING_STORE_QUESTION=true
|
|
113
|
+
|
|
114
|
+
YIJING_LLM_ENABLED=false
|
|
115
|
+
# YIJING_LLM_BASE_URL=https://api.openai.com/v1
|
|
116
|
+
# YIJING_LLM_API_KEY=sk-xxx
|
|
117
|
+
# YIJING_LLM_MODEL=gpt-4o-mini
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### htmlrender / Playwright
|
|
121
|
+
|
|
122
|
+
本插件以 `nonebot-plugin-htmlrender>=0.7.1` 为基线。推荐本地开发配置:
|
|
123
|
+
|
|
124
|
+
```env
|
|
125
|
+
RENDER_BACKEND=playwright
|
|
126
|
+
RENDER_STARTUP_MODE=probe
|
|
127
|
+
RENDER_PLAYWRIGHT={"engine":"chromium","skip_browser_install":false,"close_on_exit":true,"launch_args":"--no-sandbox --disable-dev-shm-usage --disable-gpu"}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
生产 Docker 环境如果在镜像构建阶段把 Playwright Chromium 安装到 `/ms-playwright`,推荐:
|
|
131
|
+
|
|
132
|
+
```env
|
|
133
|
+
RENDER_BACKEND=playwright
|
|
134
|
+
RENDER_STARTUP_MODE=probe
|
|
135
|
+
RENDER_STORAGE_PATH=/ms-playwright
|
|
136
|
+
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"}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
这种部署方式要求 Dockerfile 或镜像构建脚本确实把 Chromium 安装到了 `/ms-playwright`。如果没有预装浏览器,不要设置 `skip_browser_install=true`。
|
|
140
|
+
|
|
141
|
+
## 使用
|
|
142
|
+
|
|
143
|
+
### 命令
|
|
144
|
+
|
|
145
|
+
| 命令 | 说明 |
|
|
146
|
+
| --- | --- |
|
|
147
|
+
| `易经帮助` | 查看帮助长图 |
|
|
148
|
+
| `起卦 问题` | 默认三枚铜钱法起卦并解卦 |
|
|
149
|
+
| `起卦 问题 铜钱` | 精确指定铜钱法 |
|
|
150
|
+
| `起卦 问题 大衍` | 使用大衍筮法概率模拟 |
|
|
151
|
+
| `起卦 问题 手动` | 进入手动起卦引导 |
|
|
152
|
+
| `解卦 卦象` | 查询/解释指定卦象 |
|
|
153
|
+
| `易经历史` | 查看自己的历史记录 |
|
|
154
|
+
| `易经记录 ID` | 查看指定记录 |
|
|
155
|
+
| `随机一卦` | 随机生成一个观察主题 |
|
|
156
|
+
| `易经设置` | 查看或修改本群配置 |
|
|
157
|
+
|
|
158
|
+
### 手动铜钱输入
|
|
159
|
+
|
|
160
|
+
铜钱法必须自下而上输入 6 组,每组 3 个正/反:
|
|
161
|
+
|
|
162
|
+
```text
|
|
163
|
+
正反正 反反正 正正反 正反反 反正正 反反反
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### 手动大衍输入
|
|
167
|
+
|
|
168
|
+
大衍法可以自下而上输入 6 个爻值:
|
|
169
|
+
|
|
170
|
+
```text
|
|
171
|
+
7 8 9 6 7 8
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
其中:
|
|
175
|
+
|
|
176
|
+
- `6`:老阴,动爻,阴变阳。
|
|
177
|
+
- `7`:少阳,静爻。
|
|
178
|
+
- `8`:少阴,静爻。
|
|
179
|
+
- `9`:老阳,动爻,阳变阴。
|
|
180
|
+
|
|
181
|
+
## 权限控制
|
|
182
|
+
|
|
183
|
+
本插件通过 `nonebot-plugin-access-control-api` 注册以下服务:
|
|
184
|
+
|
|
185
|
+
```text
|
|
186
|
+
nonebot_plugin_yijing
|
|
187
|
+
nonebot_plugin_yijing.cast
|
|
188
|
+
nonebot_plugin_yijing.query
|
|
189
|
+
nonebot_plugin_yijing.history
|
|
190
|
+
nonebot_plugin_yijing.settings
|
|
191
|
+
nonebot_plugin_yijing.random
|
|
192
|
+
nonebot_plugin_yijing.manual
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
示例:禁用某群的起卦功能,但保留查卦:
|
|
196
|
+
|
|
197
|
+
```text
|
|
198
|
+
/ac permission deny --sbj qq:g123456789 --srv nonebot_plugin_yijing.cast
|
|
199
|
+
/ac permission allow --sbj qq:g123456789 --srv nonebot_plugin_yijing.query
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## 资料库
|
|
203
|
+
|
|
204
|
+
资料库位于 `nonebot_plugin_yijing/data/`,结构说明见 [`nonebot_plugin_yijing/data/README.md`](nonebot_plugin_yijing/data/README.md)。
|
|
205
|
+
|
|
206
|
+
当前内置完整项:八卦、六十四卦、六爻骨架、卦辞、卦关系、起卦规则、解读规则。
|
|
207
|
+
|
|
208
|
+
当前种子经文:乾、坤、需的爻辞/象传较完整;其余卦的爻辞、彖传、文言、系辞等字段先以结构化占位保留,等待后续校勘补录。
|
|
209
|
+
|
|
210
|
+
## LLM 预处理、解读与隐私
|
|
211
|
+
|
|
212
|
+
启用 LLM 后,`起卦 问题` 会在真正起卦前执行预处理:
|
|
213
|
+
|
|
214
|
+
- 判断问题是否明确。
|
|
215
|
+
- 判断是否违反“不诚不占、不义不占、不疑不占”。
|
|
216
|
+
- 对照参数化历史记录,识别短期重复或相似问题。
|
|
217
|
+
- 标注医疗、法律、投资、人身安全等敏感领域。
|
|
218
|
+
|
|
219
|
+
LLM 接口为 OpenAI 兼容 `/chat/completions`,失败会自动降级到本地规则,不阻塞起卦核心流程。
|
|
220
|
+
|
|
221
|
+
隐私注意事项:
|
|
222
|
+
|
|
223
|
+
- `YIJING_LLM_ENABLED=false` 时,LLM 不会被调用。
|
|
224
|
+
- 开启 LLM 后,用户问题、卦象资料、预处理字段,以及按配置选取的近期历史记录,可能会发送给你配置的第三方模型服务商。
|
|
225
|
+
- `YIJING_STORE_QUESTION=true` 会在数据库中保存原始问题文本,便于历史回看和相似问题判断。
|
|
226
|
+
- 若希望降低存储敏感内容的风险,可设置 `YIJING_STORE_QUESTION=false`。此时历史记录会保留卦象和结构化结果,但原始问题文本不会保存。
|
|
227
|
+
- 本插件只提供本地降级逻辑,不代理或改变第三方模型服务商的数据处理规则。请按实际接入的模型服务商补充群公告或隐私说明。
|
|
228
|
+
|
|
229
|
+
## 开发
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
python -m pip install -e ".[dev]"
|
|
233
|
+
ruff check .
|
|
234
|
+
python -m compileall nonebot_plugin_yijing
|
|
235
|
+
pytest -q
|
|
236
|
+
python -m build --sdist --wheel .
|
|
237
|
+
twine check dist/*
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## 更多文档
|
|
241
|
+
|
|
242
|
+
- [`docs/server-smoke-test.md`](docs/server-smoke-test.md):服务器升级、包安装、真实群聊命令验收清单。
|
|
243
|
+
- [`docs/data-collation.md`](docs/data-collation.md):经传资料库补录、来源、状态与校勘流程。
|
|
244
|
+
- [`docs/release.md`](docs/release.md):构建、验包、发布、服务器验证与 PyPI 发布流程。
|
|
245
|
+
|
|
246
|
+
## 许可证
|
|
247
|
+
|
|
248
|
+
本项目使用 MIT License。详见 [`LICENSE`](LICENSE)。
|
|
249
|
+
|
|
250
|
+
## 免责声明
|
|
251
|
+
|
|
252
|
+
本插件用于传统文化学习、文本解释与群聊娱乐,不提供确定性预测,不构成医疗、法律、投资、安全或其他专业建议。
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from nonebot import require
|
|
4
|
+
from nonebot.plugin import PluginMetadata
|
|
5
|
+
|
|
6
|
+
from .config import YijingConfig
|
|
7
|
+
|
|
8
|
+
require("nonebot_plugin_alconna")
|
|
9
|
+
require("nonebot_plugin_htmlrender")
|
|
10
|
+
require("nonebot_plugin_orm")
|
|
11
|
+
require("nonebot_plugin_localstore")
|
|
12
|
+
|
|
13
|
+
# 权限控制插件是强依赖;API 适配用于将本插件拆成细粒度服务。
|
|
14
|
+
require("nonebot_plugin_access_control")
|
|
15
|
+
require("nonebot_plugin_access_control_api")
|
|
16
|
+
|
|
17
|
+
__plugin_meta__ = PluginMetadata(
|
|
18
|
+
name="易经起卦解卦",
|
|
19
|
+
description="群内自助进行基于《周易》的起卦、查卦、解卦、历史记录与图片化输出。",
|
|
20
|
+
usage="""
|
|
21
|
+
易经帮助
|
|
22
|
+
起卦 <问题>
|
|
23
|
+
起卦 <问题> 铜钱
|
|
24
|
+
起卦 <问题> 大衍
|
|
25
|
+
起卦 <问题> 手动
|
|
26
|
+
解卦 <卦名/卦象>
|
|
27
|
+
易经历史
|
|
28
|
+
易经记录 <ID>
|
|
29
|
+
随机一卦
|
|
30
|
+
易经设置
|
|
31
|
+
""".strip(),
|
|
32
|
+
type="application",
|
|
33
|
+
homepage="https://github.com/newcovid/nonebot-plugin-yijing",
|
|
34
|
+
config=YijingConfig,
|
|
35
|
+
supported_adapters={"~onebot.v11"},
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
from . import commands as _commands # noqa: E402,F401
|