From 9bfa72610728f900169e1eabeb533ddba29a4f7d Mon Sep 17 00:00:00 2001 From: Zhalslar Date: Fri, 12 Sep 2025 15:40:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=BC=E5=AE=B9=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E5=90=8D=E5=92=8C=E7=AC=AC=E4=B8=80=E4=B8=AA=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E4=B9=8B=E9=97=B4=E6=B2=A1=E6=9C=89=E7=A9=BA=E6=A0=BC=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5=20(#2650)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 插件中@filter.command的指令在用户输入“命令+参数” 无空格隔开时无法处理,但只要稍微改动几行代码就可以兼容 --- astrbot/core/star/filter/command.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/astrbot/core/star/filter/command.py b/astrbot/core/star/filter/command.py index 9ceed54a9..9db43896c 100755 --- a/astrbot/core/star/filter/command.py +++ b/astrbot/core/star/filter/command.py @@ -7,7 +7,6 @@ from astrbot.core.config import AstrBotConfig from .custom_filter import CustomFilter from ..star_handler import StarHandlerMetadata - class GreedyStr(str): """标记指令完成其他参数接收后的所有剩余文本。""" @@ -153,10 +152,17 @@ class CommandFilter(HandlerFilter): _full = f"{parent_command_name} {candidate}" else: _full = candidate - if message_str.startswith(f"{_full} ") or message_str == _full: - message_str = message_str[len(_full) :].strip() + if message_str == _full: + # 完全等于命令名 → 没参数 + message_str = "" ok = True break + elif message_str.startswith(_full): + # 命令名后面无论是空格还是直接连参数都可以 + message_str = message_str[len(_full):].lstrip() + ok = True + break + if not ok: return False