From da5aada002e27004d8330050f48254905865aa55 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Wed, 5 Feb 2025 13:52:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E7=BB=84=E6=83=85=E5=86=B5=E4=B8=8B=E5=8F=AF=E8=83=BD=E9=80=A0?= =?UTF-8?q?=E6=88=90=E5=A4=9A=E6=8C=87=E4=BB=A4=E5=87=BA=E8=A7=A6=E5=8F=91?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/pipeline/waking_check/stage.py | 4 +++- astrbot/core/star/filter/command.py | 6 +++++- astrbot/core/star/filter/command_group.py | 15 +++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/astrbot/core/pipeline/waking_check/stage.py b/astrbot/core/pipeline/waking_check/stage.py index 89fccaff6..6d9905822 100644 --- a/astrbot/core/pipeline/waking_check/stage.py +++ b/astrbot/core/pipeline/waking_check/stage.py @@ -7,6 +7,7 @@ from astrbot.core.message.components import At from astrbot.core.star.star_handler import star_handlers_registry, EventType from astrbot.core.star.filter.command_group import CommandGroupFilter from astrbot.core.star.filter.permission import PermissionTypeFilter +from astrbot.core.star.filter.command import CommandFilter @register_stage @@ -80,6 +81,8 @@ class WakingCheckStage(Stage): child_command_handler_md = None permission_not_pass = False + + has_command_pass = False if len(handler.event_filters) == 0: # 不可能有这种情况, 也不允许有这种情况 @@ -99,7 +102,6 @@ class WakingCheckStage(Stage): break elif isinstance(filter, PermissionTypeFilter): if not filter.filter(event, self.ctx.astrbot_config): - print("permission not pass") permission_not_pass = True else: if not filter.filter(event, self.ctx.astrbot_config): diff --git a/astrbot/core/star/filter/command.py b/astrbot/core/star/filter/command.py index 0976e59f0..03466bb73 100644 --- a/astrbot/core/star/filter/command.py +++ b/astrbot/core/star/filter/command.py @@ -46,7 +46,11 @@ class CommandFilter(HandlerFilter, ParameterValidationMixin): if not event.is_wake_up(): return False - message_str = event.get_message_str().strip() + if event.get_extra("parsing_command"): + message_str = event.get_extra("parsing_command").strip() + else: + message_str = event.get_message_str().strip() + # 分割为列表(每个参数之间可能会有多个空格) ls = re.split(r"\s+", message_str) if self.command_name != ls[0]: diff --git a/astrbot/core/star/filter/command_group.py b/astrbot/core/star/filter/command_group.py index 5a8e7fae8..b3a66d22e 100644 --- a/astrbot/core/star/filter/command_group.py +++ b/astrbot/core/star/filter/command_group.py @@ -40,17 +40,24 @@ class CommandGroupFilter(HandlerFilter): if not event.is_wake_up(): return False, None - message_str = event.get_message_str().strip() + if event.get_extra("parsing_command"): + message_str = event.get_extra("parsing_command").strip() + else: + message_str = event.get_message_str().strip() + ls = re.split(r"\s+", message_str) if ls[0] != self.group_name: return False, None # 改写 message_str ls = ls[1:] - event.message_str = " ".join(ls) - event.message_str = event.message_str.strip() + # event.message_str = " ".join(ls) + # event.message_str = event.message_str.strip() + parsing_command = " ".join(ls) + parsing_command = parsing_command.strip() + event.set_extra("parsing_command", parsing_command) - if event.message_str == "": + if parsing_command == "": # 当前还是指令组 tree = self.group_name + "\n" + self.print_cmd_tree(self.sub_command_filters) raise ValueError(f"指令组 {self.group_name} 未填写完全。这个指令组下有如下指令:\n"+tree)