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
7 changed files with 355 additions and 0 deletions
Showing only changes of commit 69b5908445 - Show all commits

View File

@ -1,7 +1,10 @@
import re
import nonebot
from nonebot.adapters import Event
from nonebot_plugin_alconna import UniMessage, UniMsg
from konabot.common.nb import match_keyword
from konabot.common.permsys import register_default_allow_permission, require_permission
from konabot.plugins.trpg_roll.core import RollError, roll_expression
@ -11,18 +14,15 @@ register_default_allow_permission(PERMISSION_KEY)
matcher = nonebot.on_message(
rule=require_permission(PERMISSION_KEY),
rule=match_keyword.match_keyword(re.compile(r"^roll(?:\s+.+)?$", re.I))
& require_permission(PERMISSION_KEY),
)
@matcher.handle()
async def _(event: Event, msg: UniMsg):
text = msg.extract_plain_text().strip()
lowered = text.lower()
if lowered == "roll" or lowered.startswith("roll "):
expr = text[4:].strip()
else:
return
expr = text[4:].strip()
if not expr:
await UniMessage.text("用法roll 3d6 / roll d20+5 / roll 2d8+1d4+3 / roll 4dF").send(event)