From 589855c39314b6129048864f28652e022cfda7f1 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Tue, 15 Apr 2025 21:55:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E5=BC=80=E5=85=B3?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=BF=BD=E7=95=A5=E8=87=AA=E8=BA=AB=E5=8F=91?= =?UTF-8?q?=E9=80=81=E7=9A=84=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 某些平台如 gewechat 会将自身账号在其他 APP 端发送的消息也当做消息事件下发导致给自己发消息时唤醒机器人 fixes: #890 --- astrbot/core/config/default.py | 6 ++++++ astrbot/core/pipeline/waking_check/stage.py | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index f42da1871..6d48a3c9f 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -38,6 +38,7 @@ DEFAULT_CONFIG = { "no_permission_reply": True, "empty_mention_waiting": True, "friend_message_needs_wake_prefix": False, + "ignore_bot_self_message": False, }, "provider": [], "provider_settings": { @@ -287,6 +288,11 @@ CONFIG_METADATA_2 = { "type": "bool", "hint": "启用后,私聊消息需要唤醒前缀才会被处理,同群聊一样。", }, + "ignore_bot_self_message": { + "description": "是否忽略机器人自身的消息", + "type": "bool", + "hint": "某些平台如 gewechat 会将自身账号在其他 APP 端发送的消息也当做消息事件下发导致给自己发消息时唤醒机器人", + }, "segmented_reply": { "description": "分段回复", "type": "object", diff --git a/astrbot/core/pipeline/waking_check/stage.py b/astrbot/core/pipeline/waking_check/stage.py index cfc905693..7162b77ab 100644 --- a/astrbot/core/pipeline/waking_check/stage.py +++ b/astrbot/core/pipeline/waking_check/stage.py @@ -35,10 +35,21 @@ class WakingCheckStage(Stage): self.friend_message_needs_wake_prefix = self.ctx.astrbot_config[ "platform_settings" ].get("friend_message_needs_wake_prefix", False) + # 是否忽略机器人自己发送的消息 + self.ignore_bot_self_message = self.ctx.astrbot_config["platform_settings"].get( + "ignore_bot_self_message", False + ) async def process( self, event: AstrMessageEvent ) -> Union[None, AsyncGenerator[None, None]]: + if ( + self.ignore_bot_self_message + and event.get_self_id() == event.get_sender_id() + ): + # 忽略机器人自己发送的消息 + event.stop_event() + return # 设置 sender 身份 event.message_str = event.message_str.strip() for admin_id in self.ctx.astrbot_config["admins_id"]: