From 3b149c520b5d585c8176c35e7835477b6b0266d6 Mon Sep 17 00:00:00 2001 From: HakimYu Date: Tue, 24 Jun 2025 16:30:23 +0800 Subject: [PATCH 1/7] =?UTF-8?q?fix(AiocqhttpAdapter):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?at=5Finfo.get("nick",=20"")=E7=9A=84=E9=94=99=E8=AF=AF=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E5=9C=A8message=5Fstr=E4=B8=AD=E9=92=88=E5=AF=B9At?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=B7=BB=E5=8A=A0QQ=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py index df8a00ae1..079371548 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -307,7 +307,7 @@ class AiocqhttpAdapter(Platform): user_id=int(m["data"]["qq"]), ) if at_info: - nickname = at_info.get("nick", "") + nickname = at_info.get("nickname", "") is_at_self = str(m["data"]["qq"]) in {abm.self_id, "all"} abm.message.append( @@ -322,7 +322,7 @@ class AiocqhttpAdapter(Platform): first_at_self_processed = True else: # 非第一个@机器人或@其他用户,添加到message_str - message_str += f" @{nickname} " + message_str += f" @{nickname}({m['data']['qq']}) " else: abm.message.append(At(qq=str(m["data"]["qq"]), name="")) except ActionFailed as e: From 0760cabbbe9391024e811bd64f48a2bcc77848b2 Mon Sep 17 00:00:00 2001 From: HakimYu Date: Tue, 24 Jun 2025 17:20:30 +0800 Subject: [PATCH 2/7] =?UTF-8?q?feat(AiocqhttpAdapter):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dreply=E7=B1=BB=E5=9E=8B=E7=9A=84=20Event.from=5Fpayloa?= =?UTF-8?q?d=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py index 079371548..a103b2ea6 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -183,6 +183,7 @@ class AiocqhttpAdapter(Platform): @param get_reply: 是否获取回复消息。这个参数是为了防止多个回复嵌套。 """ abm = AstrBotMessage() + logger.info(f"event: {event}") abm.self_id = str(event.self_id) abm.sender = MessageMember( str(event.sender["user_id"]), event.sender["nickname"] @@ -273,6 +274,8 @@ class AiocqhttpAdapter(Platform): action="get_msg", message_id=int(m["data"]["id"]), ) + # 添加必要的 post_type 字段,防止 Event.from_payload 报错 + reply_event_data["post_type"] = "message" abm_reply = await self._convert_handle_message_event( Event.from_payload(reply_event_data), get_reply=False ) From 2f81b2e381eb6715046172d31f0abdb3d7372c27 Mon Sep 17 00:00:00 2001 From: QiChenSn <2102733232@qq.com> Date: Fri, 27 Jun 2025 02:32:10 +0800 Subject: [PATCH 3/7] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8Dcommandfilter?= =?UTF-8?q?=E5=AF=B9=E5=B8=83=E5=B0=94=E7=B1=BB=E5=9E=8B=E7=9A=84=E8=A7=A3?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/star/filter/command.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/astrbot/core/star/filter/command.py b/astrbot/core/star/filter/command.py index 7d3cabbfa..9bddcb263 100755 --- a/astrbot/core/star/filter/command.py +++ b/astrbot/core/star/filter/command.py @@ -110,6 +110,17 @@ class CommandFilter(HandlerFilter): elif isinstance(param_type_or_default_val, str): # 如果 param_type_or_default_val 是字符串,直接赋值 result[param_name] = params[i] + elif isinstance(param_type_or_default_val, bool): + # 处理布尔类型 + lower_param = params[i].lower() + if lower_param in ['true', 'yes', '1']: + result[param_name] = True + elif lower_param in ['false', 'no', '0']: + result[param_name] = False + else: + raise ValueError( + f"参数 {param_name} 必须是布尔值(true/false, yes/no, 1/0)。" + ) elif isinstance(param_type_or_default_val, int): result[param_name] = int(params[i]) elif isinstance(param_type_or_default_val, float): From 244fb1fed6a019c8183d30c7dcad5a3da9b75be3 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Fri, 27 Jun 2025 14:38:31 +0800 Subject: [PATCH 4/7] chore: remove useless logger --- .../platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py index a103b2ea6..eca99543a 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -168,9 +168,7 @@ class AiocqhttpAdapter(Platform): if "sub_type" in event: if event["sub_type"] == "poke" and "target_id" in event: - abm.message.append( - Poke(qq=str(event["target_id"]), type="poke") - ) # noqa: F405 + abm.message.append(Poke(qq=str(event["target_id"]), type="poke")) # noqa: F405 return abm @@ -183,7 +181,6 @@ class AiocqhttpAdapter(Platform): @param get_reply: 是否获取回复消息。这个参数是为了防止多个回复嵌套。 """ abm = AstrBotMessage() - logger.info(f"event: {event}") abm.self_id = str(event.self_id) abm.sender = MessageMember( str(event.sender["user_id"]), event.sender["nickname"] From 2ca95a988e4635fd58d64623bff68e023d2806c6 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sat, 28 Jun 2025 15:05:57 +0800 Subject: [PATCH 5/7] fix: lint warnings --- astrbot/core/star/filter/command.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/astrbot/core/star/filter/command.py b/astrbot/core/star/filter/command.py index 9bddcb263..52f530da6 100755 --- a/astrbot/core/star/filter/command.py +++ b/astrbot/core/star/filter/command.py @@ -7,10 +7,13 @@ from astrbot.core.config import AstrBotConfig from .custom_filter import CustomFilter from ..star_handler import StarHandlerMetadata + class GreedyStr(str): """标记指令完成其他参数接收后的所有剩余文本。""" + pass + # 标准指令受到 wake_prefix 的制约。 class CommandFilter(HandlerFilter): """标准指令过滤器""" @@ -18,8 +21,8 @@ class CommandFilter(HandlerFilter): def __init__( self, command_name: str, - alias: set = None, - handler_md: StarHandlerMetadata = None, + alias: set | None = None, + handler_md: StarHandlerMetadata | None = None, parent_command_names: List[str] = [""], ): self.command_name = command_name @@ -113,9 +116,9 @@ class CommandFilter(HandlerFilter): elif isinstance(param_type_or_default_val, bool): # 处理布尔类型 lower_param = params[i].lower() - if lower_param in ['true', 'yes', '1']: + if lower_param in ["true", "yes", "1"]: result[param_name] = True - elif lower_param in ['false', 'no', '0']: + elif lower_param in ["false", "no", "0"]: result[param_name] = False else: raise ValueError( From 770dec9ed677b9885c527036d9ef085f4250e242 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sat, 28 Jun 2025 15:08:19 +0800 Subject: [PATCH 6/7] fix: handle boolean parameter parsing correctly in CommandFilter --- astrbot/core/star/filter/command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astrbot/core/star/filter/command.py b/astrbot/core/star/filter/command.py index 52f530da6..9ceed54a9 100755 --- a/astrbot/core/star/filter/command.py +++ b/astrbot/core/star/filter/command.py @@ -115,7 +115,7 @@ class CommandFilter(HandlerFilter): result[param_name] = params[i] elif isinstance(param_type_or_default_val, bool): # 处理布尔类型 - lower_param = params[i].lower() + lower_param = str(params[i]).lower() if lower_param in ["true", "yes", "1"]: result[param_name] = True elif lower_param in ["false", "no", "0"]: From 073cdf6d51bce7e2028c78673d0e793a5c289c27 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sat, 28 Jun 2025 21:51:10 +0800 Subject: [PATCH 7/7] perf: also consider nick --- .../platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py index eca99543a..02e655af7 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -307,7 +307,7 @@ class AiocqhttpAdapter(Platform): user_id=int(m["data"]["qq"]), ) if at_info: - nickname = at_info.get("nickname", "") + nickname = at_info.get("nick", "") or at_info.get("nickname", "") is_at_self = str(m["data"]["qq"]) in {abm.self_id, "all"} abm.message.append(