feat: add TRPG roll command #59

Merged
Passthem merged 2 commits from pi-agent/konabot:feat/trpg-roll into master 2026-03-14 02:19:16 +08:00
Contributor

PR Type

Enhancement, Tests, Documentation


Description

  • 新增 TRPG 掷骰插件,支持常见骰子表达式

  • 权限系统增加默认放行权限注册机制

  • 补充掷骰逻辑与权限功能的单元测试

  • 更新用户文档及权限系统开发文档


Diagram Walkthrough

flowchart LR
  User["用户"] -->|发送 roll 指令| Matcher["消息匹配器"]
  Matcher -->|验证权限| PermSys["权限系统"]
  Matcher -->|解析表达式| RollCore["掷骰核心"]
  RollCore -->|返回结果| User
  Plugin["插件"] -->|注册默认权限| PermSys

File Walkthrough

Relevant files
Enhancement
3 files
__init__.py
新增 TRPG 掷骰插件入口与消息匹配                                                                           
+35/-0   
core.py
实现骰子表达式解析与安全限制                                                                                     
+143/-0 
__init__.py
增加默认允许权限注册函数                                                                                         
+9/-0     
Tests
2 files
test_trpg_roll.py
添加掷骰核心逻辑单元测试                                                                                         
+66/-0   
test_permsys_default_allow.py
添加权限默认放行功能测试                                                                                         
+40/-0   
Documentation
2 files
permsys.md
更新权限系统开发文档说明                                                                                         
+9/-0     
roll.txt
新增用户端掷骰指令使用文档                                                                                       
+53/-0   

### **PR Type** Enhancement, Tests, Documentation ___ ### **Description** - 新增 TRPG 掷骰插件,支持常见骰子表达式 - 权限系统增加默认放行权限注册机制 - 补充掷骰逻辑与权限功能的单元测试 - 更新用户文档及权限系统开发文档 ___ ### Diagram Walkthrough ```mermaid flowchart LR User["用户"] -->|发送 roll 指令| Matcher["消息匹配器"] Matcher -->|验证权限| PermSys["权限系统"] Matcher -->|解析表达式| RollCore["掷骰核心"] RollCore -->|返回结果| User Plugin["插件"] -->|注册默认权限| PermSys ``` <details> <summary><h3> File Walkthrough</h3></summary> <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><details><summary>3 files</summary><table> <tr> <td><strong>__init__.py</strong><dd><code>新增 TRPG 掷骰插件入口与消息匹配</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feat/trpg-roll/konabot/plugins/trpg_roll/__init__.py">+35/-0</a>&nbsp; &nbsp; </td> </tr> <tr> <td><strong>core.py</strong><dd><code>实现骰子表达式解析与安全限制</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feat/trpg-roll/konabot/plugins/trpg_roll/core.py">+143/-0</a>&nbsp; </td> </tr> <tr> <td><strong>__init__.py</strong><dd><code>增加默认允许权限注册函数</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feat/trpg-roll/konabot/common/permsys/__init__.py">+9/-0</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></details></td></tr><tr><td><strong>Tests</strong></td><td><details><summary>2 files</summary><table> <tr> <td><strong>test_trpg_roll.py</strong><dd><code>添加掷骰核心逻辑单元测试</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feat/trpg-roll/tests/test_trpg_roll.py">+66/-0</a>&nbsp; &nbsp; </td> </tr> <tr> <td><strong>test_permsys_default_allow.py</strong><dd><code>添加权限默认放行功能测试</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feat/trpg-roll/tests/test_permsys_default_allow.py">+40/-0</a>&nbsp; &nbsp; </td> </tr> </table></details></td></tr><tr><td><strong>Documentation</strong></td><td><details><summary>2 files</summary><table> <tr> <td><strong>permsys.md</strong><dd><code>更新权限系统开发文档说明</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feat/trpg-roll/docs/permsys.md">+9/-0</a>&nbsp; &nbsp; &nbsp; </td> </tr> <tr> <td><strong>roll.txt</strong><dd><code>新增用户端掷骰指令使用文档</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feat/trpg-roll/konabot/docs/user/roll.txt">+53/-0</a>&nbsp; &nbsp; </td> </tr> </table></details></td></tr></tr></tbody></table> </details> ___
pi-agent added 1 commit 2026-03-14 01:59:20 +08:00
Passthem requested review from Passthem 2026-03-14 01:59:41 +08:00
Collaborator

PR Reviewer Guide 🔍

(Review updated until commit 5e0e39bfc3)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵
🧪 PR contains tests
🔒 No security concerns identified
 Recommended focus areas for review

测试全局状态

测试用例直接调用 register_default_allow_permission 修改了全局状态 _default_allow_permissions。需确认测试框架是否会在不同用例间重置该全局集合,避免测试污染或顺序依赖问题。

register_default_allow_permission("test.default.allow")
权限注册时机

插件在模块导入阶段即调用 register_default_allow_permission 注册权限。需确保插件加载时机早于权限系统启动任务消费默认权限列表的时机,否则默认权限可能未生效。

register_default_allow_permission(PERMISSION_KEY)
## PR Reviewer Guide 🔍 #### (Review updated until commit https://gitea.service.jazzwhom.top/mttu-developers/konabot/commit/5e0e39bfc3344a4eb1aaf1c81e1398f246237b20) Here are some key observations to aid the review process: <table> <tr><td>⏱️&nbsp;<strong>Estimated effort to review</strong>: 2 🔵🔵⚪⚪⚪</td></tr> <tr><td>🧪&nbsp;<strong>PR contains tests</strong></td></tr> <tr><td>🔒&nbsp;<strong>No security concerns identified</strong></td></tr> <tr><td>⚡&nbsp;<strong>Recommended focus areas for review</strong><br><br> <details><summary><a href='https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feat/trpg-roll/tests/test_permsys_default_allow.py#L24-L24'><strong>测试全局状态</strong></a> 测试用例直接调用 register_default_allow_permission 修改了全局状态 _default_allow_permissions。需确认测试框架是否会在不同用例间重置该全局集合,避免测试污染或顺序依赖问题。 </summary> ```python register_default_allow_permission("test.default.allow") ``` </details> <details><summary><a href='https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feat/trpg-roll/konabot/plugins/trpg_roll/__init__.py#L13-L13'><strong>权限注册时机</strong></a> 插件在模块导入阶段即调用 register_default_allow_permission 注册权限。需确保插件加载时机早于权限系统启动任务消费默认权限列表的时机,否则默认权限可能未生效。 </summary> ```python register_default_allow_permission(PERMISSION_KEY) ``` </details> </td></tr> </table>
pi-agent force-pushed feat/trpg-roll from 6b93268325 to a542ed1fd9 2026-03-14 02:02:48 +08:00 Compare
Collaborator

Persistent review updated to latest commit 5e0e39bfc3

**[Persistent review](https://gitea.service.jazzwhom.top/mttu-developers/konabot/pulls/59#issuecomment-328)** updated to latest commit https://gitea.service.jazzwhom.top/mttu-developers/konabot/commit/5e0e39bfc3344a4eb1aaf1c81e1398f246237b20
Passthem requested changes 2026-03-14 02:11:55 +08:00
Dismissed
@ -0,0 +10,4 @@
register_default_allow_permission(PERMISSION_KEY)
matcher = nonebot.on_message(
Owner

我觉得这里确实需要更加收缩的范围,就是直接 on_message 匹配所有,效率有点低。不要学 oracle 那个 plugin 的写法,看看其他的插件怎么匹配前缀的

我觉得这里确实需要更加收缩的范围,就是直接 on_message 匹配所有,效率有点低。不要学 oracle 那个 plugin 的写法,看看其他的插件怎么匹配前缀的
Passthem marked this conversation as resolved
Collaborator

Failed to generate code suggestions for PR

Failed to generate code suggestions for PR
Collaborator

Failed to generate code suggestions for PR

Failed to generate code suggestions for PR
pi-agent added 1 commit 2026-03-14 02:17:21 +08:00
Author
Contributor

已根据评审意见收缩匹配范围:不再直接对所有消息做 on_message + handler 内判断,现在改为参照仓库内其他插件的写法,使用前缀规则先做过滤,再进入 handler。

当前规则等价于仅匹配 roll / roll 这类消息,并继续保留权限检查。

已重新验证:

  • cd /workspace/konabot && PYTHONPATH=/workspace/konabot poetry run pytest -q tests/test_trpg_roll.py tests/test_permsys.py tests/test_permsys_default_allow.py
  • cd /workspace/konabot && PYTHONPATH=/workspace/konabot poetry run python scripts/test_plugin_load.py
已根据评审意见收缩匹配范围:不再直接对所有消息做 on_message + handler 内判断,现在改为参照仓库内其他插件的写法,使用前缀规则先做过滤,再进入 handler。 当前规则等价于仅匹配 roll / roll <expr> 这类消息,并继续保留权限检查。 已重新验证: - cd /workspace/konabot && PYTHONPATH=/workspace/konabot poetry run pytest -q tests/test_trpg_roll.py tests/test_permsys.py tests/test_permsys_default_allow.py - cd /workspace/konabot && PYTHONPATH=/workspace/konabot poetry run python scripts/test_plugin_load.py
Passthem approved these changes 2026-03-14 02:18:51 +08:00
Passthem merged commit ff60642c62 into master 2026-03-14 02:19:16 +08:00
Collaborator

Persistent review updated to latest commit 5e0e39bfc3

**[Persistent review](https://gitea.service.jazzwhom.top/mttu-developers/konabot/pulls/59#issuecomment-328)** updated to latest commit https://gitea.service.jazzwhom.top/mttu-developers/konabot/commit/5e0e39bfc3344a4eb1aaf1c81e1398f246237b20
Collaborator

Failed to generate code suggestions for PR

Failed to generate code suggestions for PR
Sign in to join this conversation.
No description provided.