Skip to content

Commit

Permalink
🐛 version 0.30.3
Browse files Browse the repository at this point in the history
fix escape tag
  • Loading branch information
RF-Tar-Railt committed Oct 24, 2023
1 parent 977c5e7 commit 3254297
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/nonebot_plugin_alconna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 插件",
Expand Down
7 changes: 5 additions & 2 deletions src/nonebot_plugin_alconna/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions src/nonebot_plugin_alconna/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/nonebot_plugin_alconna/uniseg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 插件",
Expand Down
10 changes: 4 additions & 6 deletions tests/test_qqguild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 _():
Expand All @@ -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!")
Expand Down

0 comments on commit 3254297

Please sign in to comment.