Files
HeXi/hexi/plugins/nonebot_plugin_dice/handlers/roll.py
T
sansenhoshiandClaude 9371a28e35 refactor: restructure plugins per MTSS standard, consolidate assets to res/
Per docs/plugin-audit-report.md (plugins normalized to
Trigger(handlers) → Service(services) → Model(repository/models) + utils):

- Split monolithic __init__.py into handlers/services/utils across
  dailywife, deer_pipe, dice, galgame_card, helldivers_tools,
  huoziyinshua, learning_chat, makeaquote, mc_server_status,
  ncm_saying, picfinder_take, picstatus, random_jm_code, regif,
  steam_info, video_analysis, group_tools
- Move static assets under res/: deer_pipe font/img, makeaquote font,
  helldivers img/templates, huoziyinshua HuoZiYinShua
- Add config.py + register_config_items to ncm_saying, random_jm_code,
  group_tools; learning_chat unified config bridge
- Remove deprecated: voice_trans plugin, bf_bot/test.py, dead code in
  dailywife/deer_pipe, empty dirs, debug scripts under helldivers temp
- Disable brash_general_supercredits_tools (stub comment only)
- bot.py: optional stdout/stderr redirect to log file for Web log viewer,
  force ANSI colorize on non-TTY sinks
- Move runtime data (jm_code.json) out of plugin dir into hexi/data
- Docs: plugin-audit-report.md; README reflects removed plugins

Co-Authored-By: Claude <noreply@anthropic.com>
2026-09-03 00:44:38 +08:00

50 lines
1.5 KiB
Python

"""掷骰子 —— 触发器(Trigger)层。"""
from __future__ import annotations
import re
from nonebot import on_regex, on_startswith, require
from nonebot.adapters.onebot.v11 import MessageEvent
from nonebot.typing import T_State
from nonebot_plugin_alconna import UniMessage
from ..services.dice import build_dice_message
require("nonebot_plugin_alconna")
dice = on_regex(
re.compile(
r"^\.r\s*(?:(?P<num>\d{0,2})d(?:(?P<min>\d{1,4})~)?(?P<max>\d{0,4})(?:(?P<opr>[+-])(?P<offset>\d{0,5}))?)?\b",
re.I,
)
)
marriage = on_startswith(".qj")
@dice.handle()
async def dice_handle(ev: MessageEvent, state: T_State):
num, min_, max_, opr, offset = 1, 1, 100, 1, 0
matched = state.get("_matched_dict") or {}
if s := matched.get("num"):
num = int(s)
if s := matched.get("min"):
min_ = int(s)
if s := matched.get("max"):
max_ = int(s)
if s := matched.get("opr"):
opr = -1 if s == "-" else 1
if s := matched.get("offset"):
offset = int(s)
await UniMessage.text(build_dice_message(num, min_, max_, opr, offset)).send(
at_sender=True
)
@marriage.handle()
async def marriage_handle(ev: MessageEvent):
text = ev.message.extract_plain_text().strip()
wife = text[len(".qj") :].strip()
tip = f"与{wife}的ケッコンカッコカリ结果是:" if wife else "的ケッコンカッコカリ结果是:"
await UniMessage.text(build_dice_message(1, 3, 6, 1, 0, tip)).send(at_sender=True)