diff --git a/src/nonebot_plugin_alconna/__init__.py b/src/nonebot_plugin_alconna/__init__.py index 887e9a3..2bcf89c 100644 --- a/src/nonebot_plugin_alconna/__init__.py +++ b/src/nonebot_plugin_alconna/__init__.py @@ -96,7 +96,7 @@ from .consts import ALCONNA_EXEC_RESULT as ALCONNA_EXEC_RESULT from .extension import add_global_extension as add_global_extension -__version__ = "0.31.4" +__version__ = "0.31.5" __plugin_meta__ = PluginMetadata( name="Alconna 插件", diff --git a/src/nonebot_plugin_alconna/matcher.py b/src/nonebot_plugin_alconna/matcher.py index b863163..038aff2 100644 --- a/src/nonebot_plugin_alconna/matcher.py +++ b/src/nonebot_plugin_alconna/matcher.py @@ -139,11 +139,11 @@ def _decorator(func: T_Handler) -> T_Handler: if TYPE_CHECKING: @classmethod - def set_path_arg(cls_or_self, path: str, content: Any) -> None: + def set_path_arg(cls_or_self, path: str, content: Any) -> None: # type: ignore ... @classmethod - def get_path_arg(self, path: str, default: Any) -> Any: + def get_path_arg(cls_or_self, path: str, default: Any) -> Any: # type: ignore ... else: @@ -376,11 +376,17 @@ def convert(cls, message: _M) -> Message | UniMessage | str: event = current_event.get() state = current_matcher.get().state if isinstance(message, MessageTemplate): - return message.format(**state, **state[ALCONNA_RESULT].result.all_matched_args) + return message.format(**state[ALCONNA_RESULT].result.all_matched_args, **state) if isinstance(message, UniMessageTemplate): - return message.format( - **state, **state[ALCONNA_RESULT].result.all_matched_args, **{"$event": event, "$bot": bot} - ) + extra = {"$event": event, "$bot": bot} + extra["$target"] = UniMessage.get_target(event, bot) + try: + msg_id = UniMessage.get_message_id(event, bot) + except Exception: + pass + else: + extra["$message_id"] = msg_id + return message.format(**state[ALCONNA_RESULT].result.all_matched_args, **state, **extra) if isinstance(message, Segment): return UniMessage(message) if isinstance(message, MessageSegment): diff --git a/src/nonebot_plugin_alconna/uniseg/__init__.py b/src/nonebot_plugin_alconna/uniseg/__init__.py index ae8e56a..ac7ef4b 100644 --- a/src/nonebot_plugin_alconna/uniseg/__init__.py +++ b/src/nonebot_plugin_alconna/uniseg/__init__.py @@ -32,7 +32,7 @@ from .params import UniversalMessage as UniversalMessage from .params import UniversalSegment as UniversalSegment -__version__ = "0.31.4" +__version__ = "0.31.5" __plugin_meta__ = PluginMetadata( name="Universal Segment 插件", diff --git a/src/nonebot_plugin_alconna/uniseg/template.py b/src/nonebot_plugin_alconna/uniseg/template.py index b5f94ee..fb15889 100644 --- a/src/nonebot_plugin_alconna/uniseg/template.py +++ b/src/nonebot_plugin_alconna/uniseg/template.py @@ -174,7 +174,7 @@ def _vformat( def format_field(self, value: Any, format_spec: str) -> Any: formatter: Optional[FormatSpecFunc] = self.format_specs.get(format_spec) if formatter is None and format_spec in _MAPPING: - formatter = _MAPPING[format_spec] + formatter = _MAPPING[format_spec] # type: ignore return super().format_field(value, format_spec) if formatter is None else formatter(value) def _add(self, a: Any, b: Any) -> Any: diff --git a/tests/test_uniseg.py b/tests/test_uniseg.py index c5e0a84..fba77e3 100644 --- a/tests/test_uniseg.py +++ b/tests/test_uniseg.py @@ -46,14 +46,14 @@ async def test_unimsg_template(app: App): @matcher.handle() async def handle(): - await matcher.finish(UniMessage.template("{:At(user, $event.get_user_id())}")) + await matcher.finish(UniMessage.template("{:Reply($message_id)}{:At(user, $event.get_user_id())}")) async with app.test_matcher(matcher) as ctx: adapter = get_adapter(Adapter) bot = ctx.create_bot(base=Bot, adapter=adapter) event = fake_group_message_event_v11(message=Message("test_unimsg_template"), user_id=123) ctx.receive_event(bot, event) - ctx.should_call_send(event, Message(MessageSegment.at(123))) + ctx.should_call_send(event, MessageSegment.reply(1) + MessageSegment.at(123)) ctx.should_finished(matcher)