From 32542974a8d9730867cfb7bc9bc15bc06493d474 Mon Sep 17 00:00:00 2001 From: RF-Tar-Railt <3165388245@qq.com> Date: Tue, 24 Oct 2023 10:23:49 +0800 Subject: [PATCH] :bug: version 0.30.3 fix escape tag --- src/nonebot_plugin_alconna/__init__.py | 2 +- src/nonebot_plugin_alconna/matcher.py | 7 +++++-- src/nonebot_plugin_alconna/rule.py | 15 +++++++++++++-- src/nonebot_plugin_alconna/uniseg/__init__.py | 2 +- tests/test_qqguild.py | 10 ++++------ 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/nonebot_plugin_alconna/__init__.py b/src/nonebot_plugin_alconna/__init__.py index f69fa9e..a0ba865 100644 --- a/src/nonebot_plugin_alconna/__init__.py +++ b/src/nonebot_plugin_alconna/__init__.py @@ -89,7 +89,7 @@ from .consts import ALCONNA_EXEC_RESULT as ALCONNA_EXEC_RESULT from .extension import add_global_extension as add_global_extension -__version__ = "0.30.2" +__version__ = "0.30.3" __plugin_meta__ = PluginMetadata( name="Alconna 插件", diff --git a/src/nonebot_plugin_alconna/matcher.py b/src/nonebot_plugin_alconna/matcher.py index d320dd6..1e94e22 100644 --- a/src/nonebot_plugin_alconna/matcher.py +++ b/src/nonebot_plugin_alconna/matcher.py @@ -8,6 +8,7 @@ from nonebot.rule import Rule from nonebot.params import Depends +from nonebot.utils import escape_tag from _weakref import _remove_dead_weakref from nonebot.permission import Permission from nonebot.dependencies import Dependent @@ -197,11 +198,13 @@ async def _key_getter(event: Event, bot: Bot, matcher: AlconnaMatcher): ms = event.get_message()[-1] if ms.is_text() and not ms.data["text"].strip() and len(event.get_message()) > 1: ms = event.get_message()[-2] - log("DEBUG", lang.require("nbp-alc", "log.got_path/ms").format(path=path, ms=ms)) + log("DEBUG", escape_tag(lang.require("nbp-alc", "log.got_path/ms").format(path=path, ms=ms))) if (res := _validate(arg, ms)) is None: # type: ignore log( "TRACE", - lang.require("nbp-alc", "log.got_path/validate").format(path=path, validate=res), + escape_tag( + lang.require("nbp-alc", "log.got_path/validate").format(path=path, validate=res) + ), ) await matcher.reject(prompt, fallback=True) return diff --git a/src/nonebot_plugin_alconna/rule.py b/src/nonebot_plugin_alconna/rule.py index 6322598..cb291fa 100644 --- a/src/nonebot_plugin_alconna/rule.py +++ b/src/nonebot_plugin_alconna/rule.py @@ -4,6 +4,7 @@ from nonebot import get_driver from nonebot.typing import T_State from nonebot.matcher import matchers +from nonebot.utils import escape_tag from nonebot.params import EventMessage from nonebot.plugin.on import on_message from nonebot.internal.rule import Rule as Rule @@ -235,10 +236,20 @@ async def __call__(self, event: Event, state: T_State, bot: Bot) -> bool: may_help_text: Optional[str] = cap.get("output", None) self._session = None if not arp.matched and not may_help_text and self.skip: - log("TRACE", lang.require("nbp-alc", "log.parse").format(msg=msg, cmd=self.command.path, arp=arp)) + log( + "TRACE", + escape_tag( + lang.require("nbp-alc", "log.parse").format(msg=msg, cmd=self.command.path, arp=arp) + ), + ) return False if arp.head_matched: - log("DEBUG", lang.require("nbp-alc", "log.parse").format(msg=msg, cmd=self.command.path, arp=arp)) + log( + "DEBUG", + escape_tag( + lang.require("nbp-alc", "log.parse").format(msg=msg, cmd=self.command.path, arp=arp) + ), + ) if not may_help_text and arp.error_info: may_help_text = repr(arp.error_info) if self.auto_send and may_help_text: diff --git a/src/nonebot_plugin_alconna/uniseg/__init__.py b/src/nonebot_plugin_alconna/uniseg/__init__.py index b75aead..22c30d4 100644 --- a/src/nonebot_plugin_alconna/uniseg/__init__.py +++ b/src/nonebot_plugin_alconna/uniseg/__init__.py @@ -24,7 +24,7 @@ from .params import UniversalMessage as UniversalMessage from .params import UniversalSegment as UniversalSegment -__version__ = "0.30.2" +__version__ = "0.30.3" __plugin_meta__ = PluginMetadata( name="Universal Segment 插件", diff --git a/tests/test_qqguild.py b/tests/test_qqguild.py index 6f04d0b..2a10127 100644 --- a/tests/test_qqguild.py +++ b/tests/test_qqguild.py @@ -2,7 +2,7 @@ import pytest from nonebug import App -from nonebot import logger, get_adapter +from nonebot import get_adapter from arclet.alconna import Args, Alconna from nonebot.adapters.qq import Bot, Adapter, Message @@ -11,17 +11,15 @@ @pytest.mark.asyncio() async def test_send(app: App): - from nonebot_plugin_alconna import on_alconna + from nonebot_plugin_alconna import At, on_alconna def check(name: str): - print(">>>>>>>>>>>>> check running") - logger.warning(">>>>>>>>>>>>>>> check running") asyncio.create_task(bot.send(event, "check running")) if isinstance(name, str): return name return None - cmd = on_alconna(Alconna("test", Args["name", check])) + cmd = on_alconna(Alconna([At], "test", Args["name", check])) @cmd.handle() async def _(): @@ -30,7 +28,7 @@ async def _(): async with app.test_matcher(cmd) as ctx: adapter = get_adapter(Adapter) bot = ctx.create_bot(base=Bot, adapter=adapter, bot_info=None) - event = fake_message_event_guild(message=Message("test aaaa"), id="123") + event = fake_message_event_guild(message=Message("<@5678> test aaaa"), id="123") ctx.receive_event(bot, event) ctx.should_call_send(event, "check running") ctx.should_call_send(event, "test!")