Files
HeXi/plugin_template/nonebot_plugin_template/handlers/entry.py
T

30 lines
915 B
Python
Raw Normal View History

"""触发器(Trigger)层:接触发 → 鉴权 → 调 service → 出 View。"""
from __future__ import annotations
from nonebot import on_command
from nonebot.adapters import Message
from nonebot.rule import to_me
from nonebot.params import CommandArg
from nonebot_plugin_alconna import UniMessage
from hexi.web_config import get_effective_value
from ..services.main import do_something
_PLUGIN_ID = __package__.rsplit(".", 1)[0]
cmd = on_command("模板指令", aliases={"模板"}, rule=to_me(), priority=10, block=True)
@cmd.handle()
async def handle(arg: Message = CommandArg()):
if not get_effective_value(_PLUGIN_ID, "enable", True):
await cmd.finish("模板插件已停用")
return
text = arg.extract_plain_text().strip()
if not text:
await cmd.finish("请提供要记录的内容")
result = await do_something(text)
await UniMessage.text(result).send()