nonebot-plugin-lavi 0.1.0__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.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,219 @@
1
+ Metadata-Version: 2.4
2
+ Name: nonebot-plugin-lavi
3
+ Version: 0.1.0
4
+ Summary: 一个面向二元问题的 NoneBot2 决策插件
5
+ Author: p0rt39
6
+ Author-email: p0rt39 <YuibataMiraa@gmail.com>
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Requires-Dist: nonebot2>=2.5.0,<3.0.0
10
+ Requires-Dist: nonebot-plugin-localstore>=0.7.0,<1.0.0
11
+ Requires-Dist: pydantic>=1.10.0,<3.0.0
12
+ Requires-Dist: nonebot-adapter-onebot>=2.4.6,<3.0.0 ; extra == 'onebot'
13
+ Requires-Python: >=3.10
14
+ Project-URL: Homepage, https://github.com/p0rt39/nonebot-plugin-lavi
15
+ Project-URL: Issues, https://github.com/p0rt39/nonebot-plugin-lavi/issues
16
+ Project-URL: Repository, https://github.com/p0rt39/nonebot-plugin-lavi.git
17
+ Provides-Extra: onebot
18
+ Description-Content-Type: text/markdown
19
+
20
+ # LaVI
21
+
22
+ **一个面向二元问题的 NoneBot2 决策插件**
23
+
24
+ [![pypi](https://img.shields.io/pypi/v/nonebot-plugin-lavi.svg)](https://pypi.python.org/pypi/nonebot-plugin-lavi)
25
+
26
+ ## 介绍
27
+
28
+ `nonebot-plugin-lavi` 是一个面向 NoneBot2 的二元决策插件。它提供:
29
+
30
+ - `/lavi` 命令:回答“是/否”,或从两个空白分隔的候选项中选一个。
31
+ - 可插拔算法:内置 `dayan`(大衍筮法)、`geomancy`(地占盾盘)、`obi-ifa`(Obi 宝螺 / Ifa 奥杜)与 `trial`(十三裁判)。
32
+
33
+ ## 安装
34
+
35
+ 推荐使用 nb-cli:
36
+
37
+ ```bash
38
+ nb plugin install nonebot-plugin-lavi
39
+ ```
40
+
41
+ 也可以使用常见 Python 包管理器:
42
+
43
+ ```bash
44
+ uv add nonebot-plugin-lavi
45
+ ```
46
+
47
+ 若**不使用** nb-cli 安装,需要自行在 NoneBot 项目的 `pyproject.toml` 中注册插件:
48
+
49
+ ```toml
50
+ [tool.nonebot]
51
+ plugins = ["nonebot_plugin_lavi"]
52
+ ```
53
+
54
+ ## 配置
55
+
56
+ 所有配置位于 `.env` 中的 `LAVI__...` 作用域。
57
+
58
+ ### 基础配置
59
+
60
+ | 配置项 | 类型 | 默认值 | 说明 |
61
+ | :--- | :--- | :--- | :--- |
62
+ | `LAVI__ALGORITHM` | `str` | `random` | 默认算法;`random` 为每次决策随机选择,也可填 `dayan`、`geomancy`、`obi-ifa` 或 `trial`。|
63
+ | `LAVI__DETAILED` | `bool` | `false` | 详细模式:在简洁回复后追加算法算子数量与演算过程 |
64
+
65
+ 配置的算法名无效时,插件会记录 WARNING 并回退到 `random`。
66
+
67
+ ### 自定义文案
68
+
69
+ 回复文案位于 `LAVI__TEXT__...` 作用域:
70
+
71
+ | 配置项 | 类型 | 默认值 | 说明 |
72
+ | :--- | :--- | :--- | :--- |
73
+ | `LAVI__TEXT__HEADER` | `str` | `🔮 决断仪式:「{decider}」` | 简洁与详细回复的首行;必须包含 `{decider}`(算法显示名)。|
74
+ | `LAVI__TEXT__RESULT` | `str` | `✨ 决断结果:「{answer}」` | 结果行;必须包含 `{answer}`。|
75
+ | `LAVI__TEXT__OPERATOR_COUNT` | `str` | `📊 算子数量:{operator_count}` | 详细模式的算子数行;必须包含 `{operator_count}`。|
76
+ | `LAVI__TEXT__STEPS_HEADER` | `str` | `📜 演算过程:` | 详细模式的步骤标题;设为空字符串可隐藏该行。|
77
+ | `LAVI__TEXT__UNKNOWN_ALGORITHM` | `str` | `⚠️ 未知算法:「{requested}」` | 未知算法错误的标题行;必须包含 `{requested}`。|
78
+ | `LAVI__TEXT__AVAILABLE_ALGORITHMS` | `str` | `可用算法:{available};random(随机)` | 未知算法错误的可用列表行;必须包含 `{available}`。|
79
+ | `LAVI__TEXT__UNAVAILABLE` | `str` | `决策算法暂时不可用,请稍后再试。` | 处理异常时的降级回复。|
80
+ | `LAVI__TEXT__AFFIRMATIVE` | `str` | `是` | 是/否模式中的肯定回复。|
81
+ | `LAVI__TEXT__NEGATIVE` | `str` | `否` | 是/否模式中的否定回复。|
82
+
83
+ 模板字段使用 Python 标准 `str.format` 语法:必填占位符必须出现,字面量花括号写成 `{{` 和 `}}`;不支持 `!r` 转换或 `:...` 格式说明符。
84
+
85
+ 若缺少必填占位符、使用不支持的占位符或花括号不配对,插件会拒绝加载。
86
+
87
+ 例如:
88
+
89
+ ```dotenv
90
+ LAVI__TEXT__HEADER="🎴 神谕:「{decider}」"
91
+ LAVI__TEXT__RESULT="🎯 结果:「{answer}」"
92
+ LAVI__TEXT__AFFIRMATIVE="行"
93
+ LAVI__TEXT__NEGATIVE="不行"
94
+ ```
95
+
96
+ 之后 `/lavi` 的默认回复会变成:
97
+
98
+ ```text
99
+ 🎴 神谕:「大衍」
100
+ 🎯 结果:「行」
101
+ ```
102
+
103
+ ## 内置算法
104
+
105
+ - `dayan`(大衍):模拟大衍筮法。五十根蓍草中取一根不用,余四十九根;每爻三变,第一变按 3:1 移除五根或九根,后两变各按 1:1 移除四根或八根,三变后余数除以四得到 6/7/8/9。爻值概率为 1/16、5/16、7/16、3/16,阴阳各占 8/16。变爻、之卦与阳爻多数都不是 50/50,因此只取本卦六爻阳爻数量的奇偶;六爻阴阳各半,64 种本卦中恰有 32 种回答“是”。
106
+ - `geomancy`(地占):以 16 个由决策上下文直接派生的爻位起四母图,按地占加法(逐行异或)推导四女、四侄、左右见证与裁判。裁判必然是偶数图;按传统简易是非读法,稳定图回答“是”,流动图回答“否”。
107
+ - `obi-ifa`(宝螺):每轮先掷四枚宝螺得到 Obi 字母。首轮 Alafia(4 枚开口)与 Etawa(3 枚开口)为肯定,Okana(1 枚)与 Oyekun(0 枚)为否定。若首轮是 Eyeife(2:2),直接转 Ifa;否则再掷一次 Obi:第二次为 Eyeife 时按首轮结果,第二次不是 Eyeife 时转 Ifa;Ifa 判定为真时按首轮结果,为假则重新开始一轮。Ifa 以八枚宝螺组成奥杜,按单爻数量的奇偶判定。
108
+ - `trial`(裁判):从 `DecisionContext` 派生 13 个 64 位算子;每个算子的高 32 位作为主算子份额,低 32 位作为选票。13 个高半按位多数选出 32 位主算子(全零时取 1),主算子再与每张选票做内积奇偶,得到 13 票;7 票及以上回答“是”。
109
+
110
+ ## 命令
111
+
112
+ | 指令 | 权限 | 说明 |
113
+ | :--- | :--- | :--- |
114
+ | `/lavi` | 无 | 按配置算法给出肯定/否定回复(默认“是/否”) |
115
+ | `/lavi 算法名` | 无 | 用指定算法给出肯定/否定回复(默认“是/否”) |
116
+ | `/lavi 候选1 候选2` | 无 | 按配置算法从两个候选中选择一个 |
117
+ | `/lavi 算法名 候选1 候选2` | 无 | 用指定算法从两个候选中选择一个 |
118
+
119
+ 参数按空白分隔后的字段数解释:
120
+
121
+ - 0 个字段(`/lavi`):按配置算法给出肯定/否定回复(默认“是/否”)。
122
+ - 1 个字段:视为算法名,未知名称会静默回退到配置算法。
123
+ - 2 个字段:始终视为两个候选。
124
+ - 3 个字段:视为“算法名 + 两个候选”;首个字段不是已知算法名时拒绝。
125
+ - 4 个及以上字段:静默丢弃,按配置算法给出肯定/否定回复(默认“是/否”)。
126
+
127
+ 在 1 或 3 字段形式中,命令参数优先于 `LAVI__ALGORITHM`。指定单次算法时,把算法 ID 放在最前,例如:
128
+
129
+ ```text
130
+ /lavi trial 红茶 咖啡 # 使用「裁判」从“红茶”和“咖啡”中选择
131
+ /lavi dayan # 使用「大衍」回答“是/否”
132
+ ```
133
+
134
+ ## 使用示例
135
+
136
+ 配置算法为 `dayan`(大衍)时,`/lavi 红茶 咖啡` 会从两个候选中选择一个:
137
+
138
+ ```text
139
+ 🔮 决断仪式:「大衍」
140
+ ✨ 决断结果:「红茶」
141
+ ```
142
+
143
+ 设置 `LAVI__DETAILED=true` 后,回复内容后会追加本次算法派生的 64 位算子数量(不含选择算法本身使用的算子)与演算过程。例如:
144
+
145
+ ```text
146
+ 🔮 决断仪式:「大衍」
147
+ ✨ 决断结果:「红茶」
148
+
149
+ 📊 算子数量:24
150
+ 📜 演算过程:
151
+ 初爻:去 5+4+8,余 32,32÷4=8(阴)
152
+ 二爻:去 5+4+4,余 36,36÷4=9(阳)
153
+ 三爻:去 5+8+4,余 32,32÷4=8(阴)
154
+ 四爻:去 5+4+8,余 32,32÷4=8(阴)
155
+ 五爻:去 9+4+4,余 32,32÷4=8(阴)
156
+ 上爻:去 5+4+8,余 32,32÷4=8(阴)
157
+ 阳爻 1 枚,奇偶:奇 → 肯定
158
+ ```
159
+
160
+ 开启详细模式后,各算法会提供:
161
+
162
+ - 大衍(`dayan`):六爻逐爻的蓍草移除数、余数与本爻阴阳。
163
+ - 地占(`geomancy`):四母、四女、四侄、左右见证与裁判的图形及稳定/流动。
164
+ - 宝螺(`obi-ifa`):每轮 Obi 字母、Ifa 奥杜、确认或重开。
165
+ - 裁判(`trial`):主算子、13 张选票与肯定票数。
166
+
167
+ ## 开发
168
+
169
+ 推荐使用 `uv`:
170
+
171
+ ```powershell
172
+ uv sync --all-groups
173
+ ```
174
+
175
+ 常用检查:
176
+
177
+ ```powershell
178
+ uv run ruff check .
179
+ uv run ruff format --check .
180
+ uvx basedpyright==1.40.0
181
+ uv run pytest
182
+ uv run poe test
183
+ prek run --all-files
184
+ ```
185
+
186
+ ### 目录结构
187
+
188
+ ```text
189
+ src/nonebot_plugin_lavi/
190
+ ├── __init__.py # 插件入口、__plugin_meta__、配置、matcher 注册
191
+ ├── config.py # LAVI__ 配置模型
192
+ ├── protocol.py # 决策上下文、Algorithm/Explanation/Decision、算子计量与位派生
193
+ ├── decision.py # 参数解析与 decide() 编排(产出 Decision)
194
+ ├── selector.py # 算法选择策略与注册表校验
195
+ ├── command.py # /lavi 处理函数
196
+ ├── render.py # 简洁与详细回复的文本渲染
197
+ └── decider_algorithms/
198
+ ├── __init__.py # 显式算法注册表
199
+ ├── dayan.py # 大衍筮法算法
200
+ ├── geomancy.py # 地占盾盘算法
201
+ ├── obi_ifa.py # Obi / Ifa 宝螺算法
202
+ └── trial.py # 十三裁判算法
203
+ tests/
204
+ ├── conftest.py # NoneBot 初始化与数据目录隔离
205
+ ├── fake.py # OneBot V11 假事件
206
+ ├── test_command.py # 命令参数分派与算法覆盖
207
+ ├── test_config.py # 文案配置默认值与校验
208
+ ├── test_decision.py # 决策核心契约
209
+ ├── test_decider_algorithms.py
210
+ ├── test_render.py # 回答与参数错误渲染
211
+ ├── test_selector.py
212
+ └── plugin_test.py # 插件加载与命令交互测试
213
+ docs/ # 描述性参考(架构、测试、发布)
214
+ AGENTS.md # 分层规则文件(根 / 包 / 测试)
215
+ ```
216
+
217
+ ## 许可证
218
+
219
+ Apache License 2.0 © [p0rt39](https://github.com/p0rt39)
@@ -0,0 +1,200 @@
1
+ # LaVI
2
+
3
+ **一个面向二元问题的 NoneBot2 决策插件**
4
+
5
+ [![pypi](https://img.shields.io/pypi/v/nonebot-plugin-lavi.svg)](https://pypi.python.org/pypi/nonebot-plugin-lavi)
6
+
7
+ ## 介绍
8
+
9
+ `nonebot-plugin-lavi` 是一个面向 NoneBot2 的二元决策插件。它提供:
10
+
11
+ - `/lavi` 命令:回答“是/否”,或从两个空白分隔的候选项中选一个。
12
+ - 可插拔算法:内置 `dayan`(大衍筮法)、`geomancy`(地占盾盘)、`obi-ifa`(Obi 宝螺 / Ifa 奥杜)与 `trial`(十三裁判)。
13
+
14
+ ## 安装
15
+
16
+ 推荐使用 nb-cli:
17
+
18
+ ```bash
19
+ nb plugin install nonebot-plugin-lavi
20
+ ```
21
+
22
+ 也可以使用常见 Python 包管理器:
23
+
24
+ ```bash
25
+ uv add nonebot-plugin-lavi
26
+ ```
27
+
28
+ 若**不使用** nb-cli 安装,需要自行在 NoneBot 项目的 `pyproject.toml` 中注册插件:
29
+
30
+ ```toml
31
+ [tool.nonebot]
32
+ plugins = ["nonebot_plugin_lavi"]
33
+ ```
34
+
35
+ ## 配置
36
+
37
+ 所有配置位于 `.env` 中的 `LAVI__...` 作用域。
38
+
39
+ ### 基础配置
40
+
41
+ | 配置项 | 类型 | 默认值 | 说明 |
42
+ | :--- | :--- | :--- | :--- |
43
+ | `LAVI__ALGORITHM` | `str` | `random` | 默认算法;`random` 为每次决策随机选择,也可填 `dayan`、`geomancy`、`obi-ifa` 或 `trial`。|
44
+ | `LAVI__DETAILED` | `bool` | `false` | 详细模式:在简洁回复后追加算法算子数量与演算过程 |
45
+
46
+ 配置的算法名无效时,插件会记录 WARNING 并回退到 `random`。
47
+
48
+ ### 自定义文案
49
+
50
+ 回复文案位于 `LAVI__TEXT__...` 作用域:
51
+
52
+ | 配置项 | 类型 | 默认值 | 说明 |
53
+ | :--- | :--- | :--- | :--- |
54
+ | `LAVI__TEXT__HEADER` | `str` | `🔮 决断仪式:「{decider}」` | 简洁与详细回复的首行;必须包含 `{decider}`(算法显示名)。|
55
+ | `LAVI__TEXT__RESULT` | `str` | `✨ 决断结果:「{answer}」` | 结果行;必须包含 `{answer}`。|
56
+ | `LAVI__TEXT__OPERATOR_COUNT` | `str` | `📊 算子数量:{operator_count}` | 详细模式的算子数行;必须包含 `{operator_count}`。|
57
+ | `LAVI__TEXT__STEPS_HEADER` | `str` | `📜 演算过程:` | 详细模式的步骤标题;设为空字符串可隐藏该行。|
58
+ | `LAVI__TEXT__UNKNOWN_ALGORITHM` | `str` | `⚠️ 未知算法:「{requested}」` | 未知算法错误的标题行;必须包含 `{requested}`。|
59
+ | `LAVI__TEXT__AVAILABLE_ALGORITHMS` | `str` | `可用算法:{available};random(随机)` | 未知算法错误的可用列表行;必须包含 `{available}`。|
60
+ | `LAVI__TEXT__UNAVAILABLE` | `str` | `决策算法暂时不可用,请稍后再试。` | 处理异常时的降级回复。|
61
+ | `LAVI__TEXT__AFFIRMATIVE` | `str` | `是` | 是/否模式中的肯定回复。|
62
+ | `LAVI__TEXT__NEGATIVE` | `str` | `否` | 是/否模式中的否定回复。|
63
+
64
+ 模板字段使用 Python 标准 `str.format` 语法:必填占位符必须出现,字面量花括号写成 `{{` 和 `}}`;不支持 `!r` 转换或 `:...` 格式说明符。
65
+
66
+ 若缺少必填占位符、使用不支持的占位符或花括号不配对,插件会拒绝加载。
67
+
68
+ 例如:
69
+
70
+ ```dotenv
71
+ LAVI__TEXT__HEADER="🎴 神谕:「{decider}」"
72
+ LAVI__TEXT__RESULT="🎯 结果:「{answer}」"
73
+ LAVI__TEXT__AFFIRMATIVE="行"
74
+ LAVI__TEXT__NEGATIVE="不行"
75
+ ```
76
+
77
+ 之后 `/lavi` 的默认回复会变成:
78
+
79
+ ```text
80
+ 🎴 神谕:「大衍」
81
+ 🎯 结果:「行」
82
+ ```
83
+
84
+ ## 内置算法
85
+
86
+ - `dayan`(大衍):模拟大衍筮法。五十根蓍草中取一根不用,余四十九根;每爻三变,第一变按 3:1 移除五根或九根,后两变各按 1:1 移除四根或八根,三变后余数除以四得到 6/7/8/9。爻值概率为 1/16、5/16、7/16、3/16,阴阳各占 8/16。变爻、之卦与阳爻多数都不是 50/50,因此只取本卦六爻阳爻数量的奇偶;六爻阴阳各半,64 种本卦中恰有 32 种回答“是”。
87
+ - `geomancy`(地占):以 16 个由决策上下文直接派生的爻位起四母图,按地占加法(逐行异或)推导四女、四侄、左右见证与裁判。裁判必然是偶数图;按传统简易是非读法,稳定图回答“是”,流动图回答“否”。
88
+ - `obi-ifa`(宝螺):每轮先掷四枚宝螺得到 Obi 字母。首轮 Alafia(4 枚开口)与 Etawa(3 枚开口)为肯定,Okana(1 枚)与 Oyekun(0 枚)为否定。若首轮是 Eyeife(2:2),直接转 Ifa;否则再掷一次 Obi:第二次为 Eyeife 时按首轮结果,第二次不是 Eyeife 时转 Ifa;Ifa 判定为真时按首轮结果,为假则重新开始一轮。Ifa 以八枚宝螺组成奥杜,按单爻数量的奇偶判定。
89
+ - `trial`(裁判):从 `DecisionContext` 派生 13 个 64 位算子;每个算子的高 32 位作为主算子份额,低 32 位作为选票。13 个高半按位多数选出 32 位主算子(全零时取 1),主算子再与每张选票做内积奇偶,得到 13 票;7 票及以上回答“是”。
90
+
91
+ ## 命令
92
+
93
+ | 指令 | 权限 | 说明 |
94
+ | :--- | :--- | :--- |
95
+ | `/lavi` | 无 | 按配置算法给出肯定/否定回复(默认“是/否”) |
96
+ | `/lavi 算法名` | 无 | 用指定算法给出肯定/否定回复(默认“是/否”) |
97
+ | `/lavi 候选1 候选2` | 无 | 按配置算法从两个候选中选择一个 |
98
+ | `/lavi 算法名 候选1 候选2` | 无 | 用指定算法从两个候选中选择一个 |
99
+
100
+ 参数按空白分隔后的字段数解释:
101
+
102
+ - 0 个字段(`/lavi`):按配置算法给出肯定/否定回复(默认“是/否”)。
103
+ - 1 个字段:视为算法名,未知名称会静默回退到配置算法。
104
+ - 2 个字段:始终视为两个候选。
105
+ - 3 个字段:视为“算法名 + 两个候选”;首个字段不是已知算法名时拒绝。
106
+ - 4 个及以上字段:静默丢弃,按配置算法给出肯定/否定回复(默认“是/否”)。
107
+
108
+ 在 1 或 3 字段形式中,命令参数优先于 `LAVI__ALGORITHM`。指定单次算法时,把算法 ID 放在最前,例如:
109
+
110
+ ```text
111
+ /lavi trial 红茶 咖啡 # 使用「裁判」从“红茶”和“咖啡”中选择
112
+ /lavi dayan # 使用「大衍」回答“是/否”
113
+ ```
114
+
115
+ ## 使用示例
116
+
117
+ 配置算法为 `dayan`(大衍)时,`/lavi 红茶 咖啡` 会从两个候选中选择一个:
118
+
119
+ ```text
120
+ 🔮 决断仪式:「大衍」
121
+ ✨ 决断结果:「红茶」
122
+ ```
123
+
124
+ 设置 `LAVI__DETAILED=true` 后,回复内容后会追加本次算法派生的 64 位算子数量(不含选择算法本身使用的算子)与演算过程。例如:
125
+
126
+ ```text
127
+ 🔮 决断仪式:「大衍」
128
+ ✨ 决断结果:「红茶」
129
+
130
+ 📊 算子数量:24
131
+ 📜 演算过程:
132
+ 初爻:去 5+4+8,余 32,32÷4=8(阴)
133
+ 二爻:去 5+4+4,余 36,36÷4=9(阳)
134
+ 三爻:去 5+8+4,余 32,32÷4=8(阴)
135
+ 四爻:去 5+4+8,余 32,32÷4=8(阴)
136
+ 五爻:去 9+4+4,余 32,32÷4=8(阴)
137
+ 上爻:去 5+4+8,余 32,32÷4=8(阴)
138
+ 阳爻 1 枚,奇偶:奇 → 肯定
139
+ ```
140
+
141
+ 开启详细模式后,各算法会提供:
142
+
143
+ - 大衍(`dayan`):六爻逐爻的蓍草移除数、余数与本爻阴阳。
144
+ - 地占(`geomancy`):四母、四女、四侄、左右见证与裁判的图形及稳定/流动。
145
+ - 宝螺(`obi-ifa`):每轮 Obi 字母、Ifa 奥杜、确认或重开。
146
+ - 裁判(`trial`):主算子、13 张选票与肯定票数。
147
+
148
+ ## 开发
149
+
150
+ 推荐使用 `uv`:
151
+
152
+ ```powershell
153
+ uv sync --all-groups
154
+ ```
155
+
156
+ 常用检查:
157
+
158
+ ```powershell
159
+ uv run ruff check .
160
+ uv run ruff format --check .
161
+ uvx basedpyright==1.40.0
162
+ uv run pytest
163
+ uv run poe test
164
+ prek run --all-files
165
+ ```
166
+
167
+ ### 目录结构
168
+
169
+ ```text
170
+ src/nonebot_plugin_lavi/
171
+ ├── __init__.py # 插件入口、__plugin_meta__、配置、matcher 注册
172
+ ├── config.py # LAVI__ 配置模型
173
+ ├── protocol.py # 决策上下文、Algorithm/Explanation/Decision、算子计量与位派生
174
+ ├── decision.py # 参数解析与 decide() 编排(产出 Decision)
175
+ ├── selector.py # 算法选择策略与注册表校验
176
+ ├── command.py # /lavi 处理函数
177
+ ├── render.py # 简洁与详细回复的文本渲染
178
+ └── decider_algorithms/
179
+ ├── __init__.py # 显式算法注册表
180
+ ├── dayan.py # 大衍筮法算法
181
+ ├── geomancy.py # 地占盾盘算法
182
+ ├── obi_ifa.py # Obi / Ifa 宝螺算法
183
+ └── trial.py # 十三裁判算法
184
+ tests/
185
+ ├── conftest.py # NoneBot 初始化与数据目录隔离
186
+ ├── fake.py # OneBot V11 假事件
187
+ ├── test_command.py # 命令参数分派与算法覆盖
188
+ ├── test_config.py # 文案配置默认值与校验
189
+ ├── test_decision.py # 决策核心契约
190
+ ├── test_decider_algorithms.py
191
+ ├── test_render.py # 回答与参数错误渲染
192
+ ├── test_selector.py
193
+ └── plugin_test.py # 插件加载与命令交互测试
194
+ docs/ # 描述性参考(架构、测试、发布)
195
+ AGENTS.md # 分层规则文件(根 / 包 / 测试)
196
+ ```
197
+
198
+ ## 许可证
199
+
200
+ Apache License 2.0 © [p0rt39](https://github.com/p0rt39)