refactor(bf-bot): 插件重构为 handlers/services/utils 分层,资源归入 res/
- 旧平铺模块(data/data_utils/database_op/image_builder*/get_bf6_data/ gametools_bf6/bf6_data/img_utils)拆分为 handlers(绑定/查询)、 services(fetchers/processing/query)、utils(渲染/参数)分层; 新增 repository.py / config.py / paths.py - 字体/图片/模板资源迁入 res/,新增 BF2042 卡面素材(bg/object_icon 等) - browser_ext/:BF2042 扩展捕获桥(WS 直连兜底通道)源码入库 - 新增 hexi/web/src/plugins/bf_bot 前端管理页 - 新增 tests:test_bf_bot_helpers / repository / tracker_api Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
614e1d7e00
commit
a31aab00e8
752 files changed
+6241
-2506
No files matched your search
@@ -0,0 +1,6 @@
|
||||
"""Trigger 层:命令注册与消息发送(接触发 → 调 service → 出 View)。"""
|
||||
|
||||
from . import binding as _binding # noqa: F401
|
||||
from . import query as _query # noqa: F401
|
||||
|
||||
__all__ = ["binding", "query"]
|
||||
@@ -0,0 +1,39 @@
|
||||
"""绑定管理命令:/bfbind(绑定) /unbind(解绑) /update_bind(修改绑定)。"""
|
||||
|
||||
from nonebot import on_command
|
||||
from nonebot.adapters import Event, Message
|
||||
from nonebot.params import CommandArg
|
||||
from nonebot.rule import to_me
|
||||
from nonebot_plugin_alconna import UniMessage
|
||||
|
||||
from ..services import binding as binding_service
|
||||
|
||||
bind_cmd = on_command("bfbind", rule=to_me(), aliases={"绑定"}, block=True)
|
||||
unbind_cmd = on_command("unbind", rule=to_me(), aliases={"解绑"}, block=True)
|
||||
update_bind_cmd = on_command(
|
||||
"update_bind", rule=to_me(), aliases={"修改绑定"}, block=True
|
||||
)
|
||||
|
||||
|
||||
async def _reply(event: Event, text: str) -> None:
|
||||
await UniMessage.at(user_id=event.get_user_id()).text(text).send()
|
||||
|
||||
|
||||
@bind_cmd.handle()
|
||||
async def handle_bind(event: Event, msg: Message = CommandArg()):
|
||||
text = await binding_service.bind(event.get_user_id(), msg.extract_plain_text())
|
||||
await _reply(event, text)
|
||||
|
||||
|
||||
@unbind_cmd.handle()
|
||||
async def handle_unbind(event: Event):
|
||||
text = await binding_service.unbind(event.get_user_id())
|
||||
await _reply(event, text)
|
||||
|
||||
|
||||
@update_bind_cmd.handle()
|
||||
async def handle_update_bind(event: Event, msg: Message = CommandArg()):
|
||||
text = await binding_service.update_bind(
|
||||
event.get_user_id(), msg.extract_plain_text()
|
||||
)
|
||||
await _reply(event, text)
|
||||
@@ -0,0 +1,54 @@
|
||||
"""`/bft` 及全部别名:命令注册 + 结果发送。"""
|
||||
|
||||
from nonebot import on_command
|
||||
from nonebot.adapters import Event, Message
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import CommandArg
|
||||
from nonebot.rule import to_me
|
||||
from nonebot_plugin_alconna import UniMessage
|
||||
|
||||
from hexi.core.cooldown import cooldown
|
||||
|
||||
from ..services.query import run_query
|
||||
|
||||
# 群冷却 10s(全群共享,私聊退化为按用户);显式 name 保证热重载后 CD 不重置
|
||||
query = cooldown(
|
||||
10,
|
||||
scope="group",
|
||||
name="bf_query",
|
||||
hint="查询太频繁了,{secs} 秒后再试",
|
||||
)(
|
||||
on_command(
|
||||
"bft",
|
||||
rule=to_me(),
|
||||
aliases={"bf3", "bf4", "bfv", "bf1", "bf2042", "bf6"},
|
||||
block=True,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@query.handle()
|
||||
async def handle_query(matcher: Matcher, event: Event, msg: Message = CommandArg()):
|
||||
# 实际输入的游戏别名(去掉 COMMAND_START 后的首段)决定走哪个游戏分支
|
||||
prefix = matcher.state.get("_prefix") or {}
|
||||
cmd = (prefix.get("command") or ["bft"])[0]
|
||||
input_text = msg.extract_plain_text().strip()
|
||||
user_id = event.get_user_id()
|
||||
logger.info(f"BF查询:cmd={cmd!r}, input={input_text!r}")
|
||||
|
||||
async def notify(text: str) -> None:
|
||||
await UniMessage.text(text).send()
|
||||
|
||||
reply = await run_query(
|
||||
cmd=cmd, input_text=input_text, qq_id=user_id, notify=notify
|
||||
)
|
||||
if reply.image is not None:
|
||||
await (
|
||||
UniMessage.image(raw=reply.image)
|
||||
.at(user_id=user_id)
|
||||
.text(reply.text)
|
||||
.send()
|
||||
)
|
||||
else:
|
||||
await UniMessage.at(user_id=user_id).text(reply.text).send()
|
||||
Reference in new issue
Block a user