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>
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
import random
|
||||
import re
|
||||
"""掷骰子 / 结婚判定"""
|
||||
|
||||
from nonebot import on_regex, on_startswith, require
|
||||
from nonebot.adapters.onebot.v11 import MessageEvent
|
||||
from nonebot import require
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot.typing import T_State
|
||||
|
||||
require("nonebot_plugin_alconna")
|
||||
from nonebot_plugin_alconna import UniMessage
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name="掷骰子",
|
||||
@@ -16,69 +12,4 @@ __plugin_meta__ = PluginMetadata(
|
||||
type="application",
|
||||
)
|
||||
|
||||
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")
|
||||
|
||||
|
||||
async def do_dice(
|
||||
ev: MessageEvent,
|
||||
num: int,
|
||||
min_: int,
|
||||
max_: int,
|
||||
opr: int,
|
||||
offset: int,
|
||||
tip: str = "的掷骰结果是:",
|
||||
) -> None:
|
||||
if num == 0:
|
||||
await UniMessage.text("咦?我骰子呢?").send()
|
||||
return
|
||||
min_, max_ = min(min_, max_), max(min_, max_)
|
||||
rolls = [random.randint(min_, max_) for _ in range(num)]
|
||||
total = sum(rolls)
|
||||
rolls_str = "+".join(map(str, rolls))
|
||||
if len(rolls_str) > 100:
|
||||
rolls_str = str(total)
|
||||
res = total + opr * offset
|
||||
sign = " +-"[opr]
|
||||
msg = [
|
||||
f"{tip}\n",
|
||||
str(num) if num > 1 else "",
|
||||
"D",
|
||||
f"{min_}~" if min_ != 1 else "",
|
||||
str(max_),
|
||||
f"{sign}{offset}" if offset else "",
|
||||
f"={rolls_str}",
|
||||
f"{sign}{offset}" if offset else "",
|
||||
f"={res}" if offset or num > 1 else "",
|
||||
]
|
||||
await UniMessage.text("".join(msg)).send(at_sender=True)
|
||||
|
||||
|
||||
@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 do_dice(ev, num, min_, max_, opr, offset)
|
||||
|
||||
|
||||
@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 do_dice(ev, 1, 3, 6, 1, 0, tip)
|
||||
from .handlers import dice, marriage # noqa: E402,F401
|
||||
|
||||
Reference in New Issue
Block a user